for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Doctrine\Inflector\Rules;
use function array_keys;
use function implode;
use function preg_match;
use function strtolower;
use function substr;
class Irregular
{
/** @var string[] */
private $irregular;
/** @var string|null */
private $regex;
/**
* @param string[] $irregular
*/
public function __construct(array $irregular = [])
$this->irregular = $irregular;
}
* @return string[]
public function getIrregular() : array
return $this->irregular;
public function inflect(string $word) : ?string
if (preg_match('/(.*)\\b(' . $this->getRegex() . ')$/i', $word, $regs)) {
return $regs[1] . $word[0] . substr($this->irregular[strtolower($regs[2])], 1);
return null;
private function getRegex() : string
if ($this->regex === null) {
$this->regex = '(?:' . implode('|', array_keys($this->irregular)) . ')';
return $this->regex;