Skip to content

Commit 9791640

Browse files
committed
Coding standards
1 parent cdfb60d commit 9791640

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

lib/Doctrine/Inflector/GenericLanguageInflectorFactory.php

+18-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace Doctrine\Inflector;
66

7-
use Doctrine\Inflector\Rules\Ruleset;
8-
use Doctrine\Inflector\Rules\Word;
97
use Doctrine\Inflector\Rules\Patterns;
8+
use Doctrine\Inflector\Rules\Ruleset;
109
use Doctrine\Inflector\Rules\Substitution;
1110
use Doctrine\Inflector\Rules\Substitutions;
1211
use Doctrine\Inflector\Rules\Transformations;
12+
use Doctrine\Inflector\Rules\Word;
1313

1414
use function array_unshift;
15+
use function is_array;
1516

1617
abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
1718
{
@@ -65,27 +66,29 @@ final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false
6566
return $this;
6667
}
6768

68-
final public function withIrregulars(array $irregulars, bool $reset = false): LanguageInflectorFactory
69+
final public function withIrregulars(?array $irregulars, bool $reset = false): LanguageInflectorFactory
6970
{
7071
if ($reset) {
71-
$this->pluralRulesets = [];
72+
$this->pluralRulesets = [];
7273
$this->singularRulesets = [];
7374
}
7475

75-
$newIrregulars = array();
76-
foreach ($irregulars as $irregular) {
77-
$newIrregulars[] = new Substitution(new Word($irregular[0]), new Word($irregular[1]));
78-
}
76+
if (is_array($irregulars)) {
77+
$newIrregulars = [];
78+
foreach ($irregulars as $irregular) {
79+
$newIrregulars[] = new Substitution(new Word($irregular[0]), new Word($irregular[1]));
80+
}
7981

80-
$transf = new Transformations();
81-
$patterns = new Patterns();
82-
$substs = new Substitutions(...$newIrregulars);
82+
$transf = new Transformations();
83+
$patterns = new Patterns();
84+
$substs = new Substitutions(...$newIrregulars);
8385

84-
$plural = new Ruleset($transf, $patterns, $substs);
85-
$singular = new Ruleset($transf, $patterns, $substs->getFlippedSubstitutions());
86+
$plural = new Ruleset($transf, $patterns, $substs);
87+
$singular = new Ruleset($transf, $patterns, $substs->getFlippedSubstitutions());
8688

87-
array_unshift($this->pluralRulesets, $plural);
88-
array_unshift($this->singularRulesets, $singular);
89+
array_unshift($this->pluralRulesets, $plural);
90+
array_unshift($this->singularRulesets, $singular);
91+
}
8992

9093
return $this;
9194
}

lib/Doctrine/Inflector/LanguageInflectorFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): sel
2929
/**
3030
* Applies custom rules for irregular words
3131
*
32-
* @param bool $reset If true, will unset default inflections for all new rules
32+
* @param mixed[][] $irregulars Array of arrays of strings in the format [['singular', 'plural'], ...]
33+
* @param bool $reset If true, will unset default inflections for all new rules
3334
*
3435
* @return $this
3536
*/
36-
public function withIrregulars(array $irregulars, bool $reset = false): self;
37+
public function withIrregulars(?array $irregulars, bool $reset = false): self;
3738

3839
/**
3940
* Builds the inflector instance with all applicable rules

tests/Doctrine/Tests/Inflector/InflectorWithIrregularsTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testIrregulars(string $word, string $expected): void
2121
self::assertSame($expected, $this->inflector->pluralize($word));
2222
self::assertSame($word, $this->inflector->singularize($expected));
2323
}
24+
2425
/**
2526
* @dataProvider dataRegulars
2627
*/
@@ -57,12 +58,12 @@ public function dataIrregulars(): array
5758
// In the format array('word', 'expected')
5859
return [
5960
['foobar', 'barfoo'],
60-
['test', 'testz']
61+
['test', 'testz'],
6162
];
6263
}
6364

6465
protected function setUp(): void
65-
{
66+
{
6667
$this->inflector = InflectorFactory::create()->withIrregulars($this->dataIrregulars())->build();
6768
}
6869
}

0 commit comments

Comments
 (0)