| Conditions | 5 |
| Paths | 5 |
| Total Lines | 22 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | 510 | public function inflect(string $word) : string |
|
| 34 | { |
||
| 35 | 510 | $irregular = $this->ruleset->getIrregular(); |
|
| 36 | 510 | $irregularRegex = '(?:' . implode('|', array_keys($irregular)) . ')'; |
|
| 37 | |||
| 38 | 510 | if (preg_match('/(.*)\\b(' . $irregularRegex . ')$/i', $word, $regs)) { |
|
| 39 | 93 | return $regs[1] . $word[0] . substr($irregular[strtolower($regs[2])], 1); |
|
| 40 | } |
||
| 41 | |||
| 42 | 420 | $uninflectedRegex = '(?:' . implode('|', $this->ruleset->getUninflected()) . ')'; |
|
| 43 | |||
| 44 | 420 | if (preg_match('/^(' . $uninflectedRegex . ')$/i', $word, $regs)) { |
|
| 45 | 244 | return $word; |
|
| 46 | } |
||
| 47 | |||
| 48 | 179 | foreach ($this->ruleset->getRules() as $rule => $replacement) { |
|
| 49 | 179 | if (preg_match($rule, $word)) { |
|
| 50 | 179 | return preg_replace($rule, $replacement, $word); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | 2 | return $word; |
|
| 55 | } |
||
| 57 |