for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Doctrine\Inflector;
use Doctrine\Inflector\Rules\Ruleset;
use function array_keys;
use function implode;
use function preg_match;
use function preg_replace;
use function strtolower;
use function substr;
class RulesetInflector
{
/** @var Ruleset */
private $ruleset;
public function __construct(Ruleset $ruleset)
$this->ruleset = $ruleset;
}
/**
* @param mixed[] $rules
*/
public function addRules(array $rules) : void
$this->ruleset->addRules($rules);
public function inflect(string $word) : string
$irregular = $this->ruleset->getIrregular();
$irregularRegex = '(?:' . implode('|', array_keys($irregular)) . ')';
if (preg_match('/(.*)\\b(' . $irregularRegex . ')$/i', $word, $regs)) {
return $regs[1] . $word[0] . substr($irregular[strtolower($regs[2])], 1);
$uninflectedRegex = '(?:' . implode('|', $this->ruleset->getUninflected()) . ')';
if (preg_match('/^(' . $uninflectedRegex . ')$/i', $word, $regs)) {
return $word;
foreach ($this->ruleset->getRules() as $rule => $replacement) {
if (preg_match($rule, $word)) {
return preg_replace($rule, $replacement, $word);