Total Complexity | 9 |
Total Lines | 49 |
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 | 532 | public function __construct(Rule ...$rules) |
|
26 | } |
||
27 | 532 | } |
|
28 | |||
29 | /** |
||
30 | * @return Rule[] |
||
31 | */ |
||
32 | 530 | public function getFlippedRules() : iterable |
|
36 | } |
||
37 | 530 | } |
|
38 | |||
39 | /** |
||
40 | * @return Rule[] |
||
41 | */ |
||
42 | 530 | public function getRules() : iterable |
|
45 | 530 | } |
|
46 | |||
47 | 514 | public function inflect(string $word) : ?string |
|
48 | { |
||
49 | 514 | if (preg_match('/(.*)\\b(' . $this->getRegex() . ')$/i', $word, $regs)) { |
|
50 | 94 | return $regs[1] . $word[0] . substr($this->rules[strtolower($regs[2])]->getTo(), 1); |
|
51 | } |
||
52 | |||
53 | 423 | return null; |
|
54 | } |
||
55 | |||
56 | 514 | private function getRegex() : string |
|
63 | } |
||
64 | } |
||
65 |