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 string $name |
||
15 | * @return null|string |
||
16 | */ |
||
17 | 5 | public static function detectGender($name) |
|
28 | |||
29 | /** |
||
30 | * @param string $name |
||
31 | * @param null $gender |
||
32 | * @return bool |
||
33 | */ |
||
34 | 2 | public static function isMutable($name, $gender = null) |
|
44 | |||
45 | /** |
||
46 | * @param string $name |
||
47 | * @param string $case |
||
48 | * @param string|null $gender |
||
49 | * @return string |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | 9 | public static function getCase($name, $case, $gender = null) |
|
58 | |||
59 | /** |
||
60 | * @param string $name |
||
61 | * @param string|null $gender |
||
62 | * @return string[] |
||
63 | * @phpstan-return array<string, string> |
||
64 | */ |
||
65 | 21 | public static function getCases($name, $gender = null) |
|
94 | } |
||
95 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.