| Conditions | 12 |
| Paths | 9 |
| Total Lines | 26 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 36 | public function pluralize($word, $count) { |
||
| 37 | if ($count == 1) |
||
| 38 | return $word; |
||
| 39 | |||
| 40 | $word = lower($word); |
||
| 41 | if (in_array($word, self::$without_paired_form)) |
||
| 42 | return $word; |
||
| 43 | else if (isset(self::$exceptions[$word])) |
||
| 44 | return self::$exceptions[$word]; |
||
| 45 | |||
| 46 | if (in_array(slice($word, -1), array('s', 'x')) || in_array(slice($word, -2), array('sh', 'ch'))) { |
||
| 47 | return $word.'es'; |
||
| 48 | } else if (slice($word, -1) == 'o') { |
||
| 49 | return $word.'es'; |
||
| 50 | } else if (slice($word, -1) == 'y' && in_array(slice($word, -2, -1), self::$consonants)) { |
||
| 51 | return slice($word, 0, -1).'ies'; |
||
| 52 | } else if (slice($word, -2) == 'fe' || slice($word, -1) == 'f') { |
||
| 53 | if (slice($word, -1) == 'f') { |
||
| 54 | return slice($word, 0, -1).'ves'; |
||
| 55 | } else { |
||
| 56 | return slice($word, 0, -2).'ves'; |
||
| 57 | } |
||
| 58 | } else { |
||
| 59 | return $word.'s'; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 |