| Total Complexity | 6 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Irregular |
||
| 14 | { |
||
| 15 | /** @var string[] */ |
||
| 16 | private $irregular; |
||
| 17 | |||
| 18 | /** @var string|null */ |
||
| 19 | private $regex; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string[] $irregular |
||
| 23 | */ |
||
| 24 | 526 | public function __construct(array $irregular = []) |
|
| 27 | 526 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return string[] |
||
| 31 | */ |
||
| 32 | 526 | public function getIrregular() : array |
|
| 33 | { |
||
| 34 | 526 | return $this->irregular; |
|
| 35 | } |
||
| 36 | |||
| 37 | 510 | public function inflect(string $word) : ?string |
|
| 38 | { |
||
| 39 | 510 | if (preg_match('/(.*)\\b(' . $this->getRegex() . ')$/i', $word, $regs)) { |
|
| 40 | 93 | return $regs[1] . $word[0] . substr($this->irregular[strtolower($regs[2])], 1); |
|
| 41 | } |
||
| 42 | |||
| 43 | 420 | return null; |
|
| 44 | } |
||
| 45 | |||
| 46 | 510 | private function getRegex() : string |
|
| 53 | } |
||
| 54 | } |
||
| 55 |