| Conditions | 6 |
| Paths | 5 |
| Total Lines | 24 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 9.1595 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | function singular($word) |
||
| 10 | { |
||
| 11 | 1 | if (substr($word, -1) !== 's') { |
|
| 12 | return $word; |
||
| 13 | } |
||
| 14 | |||
| 15 | 1 | if (in_array(substr($word, -2), ['us', 'ss'])) { |
|
| 16 | // Not a pluralized word |
||
| 17 | return $word; |
||
| 18 | } |
||
| 19 | |||
| 20 | 1 | if (preg_match('/[ssz]es$/', $word) || preg_match('/[^aeioudgkprt]hes$/', $word)) { |
|
| 21 | // Remove "es" |
||
| 22 | return substr($word, 0, -2); |
||
| 23 | } |
||
| 24 | |||
| 25 | 1 | if (preg_match('/[^aeiou]ies$/', $word)) { |
|
| 26 | // Replace "ies" with "y" |
||
| 27 | return substr($word, 0, -3) . 'y'; |
||
| 28 | } |
||
| 29 | |||
| 30 | // Remove "s" |
||
| 31 | 1 | return substr($word, 0, -1); |
|
| 32 | } |
||
| 33 |