| Total Complexity | 9 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class Irregular |
||
| 15 | { |
||
| 16 | /** @var Rule[] */ |
||
| 17 | private $rules; |
||
| 18 | |||
| 19 | /** @var string|null */ |
||
| 20 | private $regex; |
||
| 21 | |||
| 22 | 527 | public function __construct(Rule ...$rules) |
|
| 23 | { |
||
| 24 | 527 | foreach ($rules as $rule) { |
|
| 25 | 527 | $this->rules[$rule->getFrom()] = $rule; |
|
| 26 | } |
||
| 27 | 527 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return Rule[] |
||
| 31 | */ |
||
| 32 | 527 | public function getFlippedRules() : array |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return Rule[] |
||
| 45 | */ |
||
| 46 | 527 | public function getRules() : array |
|
| 49 | } |
||
| 50 | |||
| 51 | 511 | public function inflect(string $word) : ?string |
|
| 52 | { |
||
| 53 | 511 | if (preg_match('/(.*)\\b(' . $this->getRegex() . ')$/i', $word, $regs)) { |
|
| 54 | 92 | return $regs[1] . $word[0] . substr($this->rules[strtolower($regs[2])]->getTo(), 1); |
|
| 55 | } |
||
| 56 | |||
| 57 | 421 | return null; |
|
| 58 | } |
||
| 59 | |||
| 60 | 511 | private function getRegex() : string |
|
| 67 | } |
||
| 68 | } |
||
| 69 |