Conditions | 3 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3.004 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | 148 | public static function make(string $name): string |
|
19 | { |
||
20 | // Words ending in a y preceded by a vowel form their plurals by adding -s: |
||
21 | 148 | if (preg_match('/[aeiou]y$/', $name)) { |
|
22 | 1 | return $name . 's'; |
|
23 | } |
||
24 | |||
25 | 147 | $plural = $name . 's'; |
|
26 | |||
27 | 147 | $replacements = [ |
|
28 | 147 | '/ys$/' => 'ies', |
|
29 | 147 | '/ss$/' => 'ses', |
|
30 | 147 | '/xs$/' => 'xes', |
|
31 | 147 | ]; |
|
32 | |||
33 | 147 | $plural = preg_replace(array_keys($replacements), $replacements, $plural); |
|
34 | 147 | if ($plural === null) { |
|
35 | throw new Exception('Error while making plural'); |
||
36 | } |
||
37 | |||
38 | 147 | return $plural; |
|
39 | } |
||
41 |