Skip to content

Commit

Permalink
Coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarep committed Apr 17, 2022
1 parent cdfb60d commit f8d6df5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
31 changes: 17 additions & 14 deletions lib/Doctrine/Inflector/GenericLanguageInflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Doctrine\Inflector;

use Doctrine\Inflector\Rules\Ruleset;
use Doctrine\Inflector\Rules\Word;
use Doctrine\Inflector\Rules\Patterns;
use Doctrine\Inflector\Rules\Ruleset;
use Doctrine\Inflector\Rules\Substitution;
use Doctrine\Inflector\Rules\Substitutions;
use Doctrine\Inflector\Rules\Transformations;
use Doctrine\Inflector\Rules\Word;

use function array_unshift;
use function is_array;

abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
{
Expand Down Expand Up @@ -65,27 +66,29 @@ final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false
return $this;
}

final public function withIrregulars(array $irregulars, bool $reset = false): LanguageInflectorFactory
final public function withIrregulars(?array $irregulars, bool $reset = false): LanguageInflectorFactory
{
if ($reset) {
$this->pluralRulesets = [];
$this->singularRulesets = [];
}

$newIrregulars = array();
foreach ($irregulars as $irregular) {
$newIrregulars[] = new Substitution(new Word($irregular[0]), new Word($irregular[1]));
}
if (is_array($irregulars)) {
$newIrregulars = [];
foreach ($irregulars as $irregular) {
$newIrregulars[] = new Substitution(new Word($irregular[0]), new Word($irregular[1]));
}

$transf = new Transformations();
$patterns = new Patterns();
$substs = new Substitutions(...$newIrregulars);
$transf = new Transformations();
$patterns = new Patterns();
$substs = new Substitutions(...$newIrregulars);

$plural = new Ruleset($transf, $patterns, $substs);
$singular = new Ruleset($transf, $patterns, $substs->getFlippedSubstitutions());
$plural = new Ruleset($transf, $patterns, $substs);
$singular = new Ruleset($transf, $patterns, $substs->getFlippedSubstitutions());

array_unshift($this->pluralRulesets, $plural);
array_unshift($this->singularRulesets, $singular);
array_unshift($this->pluralRulesets, $plural);
array_unshift($this->singularRulesets, $singular);
}

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/Inflector/LanguageInflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): sel
/**
* Applies custom rules for irregular words
*
* @param mixed[][] $irregulars Array of arrays of strings in the format [['singular', 'plural'], ...]
* @param bool $reset If true, will unset default inflections for all new rules
*
* @return $this
*/
public function withIrregulars(array $irregulars, bool $reset = false): self;
public function withIrregulars(?array $irregulars, bool $reset = false): self;

/**
* Builds the inflector instance with all applicable rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testIrregulars(string $word, string $expected): void
self::assertSame($expected, $this->inflector->pluralize($word));
self::assertSame($word, $this->inflector->singularize($expected));
}

/**
* @dataProvider dataRegulars
*/
Expand Down Expand Up @@ -57,12 +58,12 @@ public function dataIrregulars(): array
// In the format array('word', 'expected')
return [
['foobar', 'barfoo'],
['test', 'testz']
['test', 'testz'],
];
}

protected function setUp(): void
{
{
$this->inflector = InflectorFactory::create()->withIrregulars($this->dataIrregulars())->build();
}
}

0 comments on commit f8d6df5

Please sign in to comment.