Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class MiddleNamesInflection extends \morphos\NamesInflection implements Cases |
||
| 10 | { |
||
| 11 | use RussianLanguage, CasesHelper; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param $name |
||
| 15 | * @return null|string |
||
| 16 | */ |
||
| 17 | 5 | public static function detectGender($name) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @param $name |
||
| 31 | * @param null $gender |
||
| 32 | * @return bool |
||
| 33 | */ |
||
| 34 | 2 | public static function isMutable($name, $gender = null) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @param $name |
||
| 47 | * @param $case |
||
| 48 | * @param null $gender |
||
| 49 | * @return mixed |
||
| 50 | * @throws \Exception |
||
| 51 | */ |
||
| 52 | 9 | public static function getCase($name, $case, $gender = null) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @param $name |
||
| 61 | * @param null $gender |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | 21 | public static function getCases($name, $gender = null) |
|
| 93 | } |
||
| 94 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.