| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4.0961 |
| 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 | 147 | $plural = preg_replace('/ys$/', 'ies', $plural); |
|
| 27 | 147 | if ($plural === null) { |
|
| 28 | throw new Exception('Error while making plural'); |
||
| 29 | } |
||
| 30 | |||
| 31 | 147 | $plural = preg_replace('/ss$/', 'ses', $plural); |
|
| 32 | 147 | if ($plural === null) { |
|
| 33 | throw new Exception('Error while making plural'); |
||
| 34 | } |
||
| 35 | |||
| 36 | 147 | return $plural; |
|
| 37 | } |
||
| 39 |