|
4 | 4 |
|
5 | 5 | namespace Doctrine\Inflector;
|
6 | 6 |
|
7 |
| -use Doctrine\Inflector\Rules\Ruleset; |
8 |
| -use Doctrine\Inflector\Rules\Word; |
9 | 7 | use Doctrine\Inflector\Rules\Patterns;
|
| 8 | +use Doctrine\Inflector\Rules\Ruleset; |
10 | 9 | use Doctrine\Inflector\Rules\Substitution;
|
11 | 10 | use Doctrine\Inflector\Rules\Substitutions;
|
12 | 11 | use Doctrine\Inflector\Rules\Transformations;
|
| 12 | +use Doctrine\Inflector\Rules\Word; |
13 | 13 |
|
14 | 14 | use function array_unshift;
|
| 15 | +use function is_array; |
15 | 16 |
|
16 | 17 | abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
|
17 | 18 | {
|
@@ -65,27 +66,29 @@ final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false
|
65 | 66 | return $this;
|
66 | 67 | }
|
67 | 68 |
|
68 |
| - final public function withIrregulars(array $irregulars, bool $reset = false): LanguageInflectorFactory |
| 69 | + final public function withIrregulars(?array $irregulars, bool $reset = false): LanguageInflectorFactory |
69 | 70 | {
|
70 | 71 | if ($reset) {
|
71 |
| - $this->pluralRulesets = []; |
| 72 | + $this->pluralRulesets = []; |
72 | 73 | $this->singularRulesets = [];
|
73 | 74 | }
|
74 | 75 |
|
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 | + } |
79 | 81 |
|
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); |
83 | 85 |
|
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()); |
86 | 88 |
|
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 | + } |
89 | 92 |
|
90 | 93 | return $this;
|
91 | 94 | }
|
|
0 commit comments