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 |
||
7 | View Code Duplication | class PropertyGroupingWriter extends PropertyWriter |
|
|
|||
8 | { |
||
9 | /** |
||
10 | * @param IReflectionProperty[] $properties |
||
11 | * @return string |
||
12 | */ |
||
13 | public function writeElements(array $properties) |
||
39 | |||
40 | /** |
||
41 | * @param \TokenReflection\IReflectionProperty $property |
||
42 | * @return string |
||
43 | */ |
||
44 | private function isDeprecated(IReflectionProperty $property) |
||
53 | |||
54 | /** |
||
55 | * @param \TokenReflection\IReflectionProperty $property |
||
56 | * @return string |
||
57 | */ |
||
58 | private function isTodo(IReflectionProperty $property) |
||
67 | |||
68 | private function writeDeprecated() |
||
72 | |||
73 | private function writeTodo() |
||
77 | |||
78 | private function writeSeparator() |
||
82 | } |
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.