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 |
||
11 | class Sum implements Processor |
||
12 | { |
||
13 | use Processor\Implementation; |
||
14 | |||
15 | /** |
||
16 | * Apply processing to a single node |
||
17 | * |
||
18 | * @param Node $node |
||
19 | */ |
||
20 | 4 | View Code Duplication | public function applyToNode(Node $node) |
34 | |||
35 | /** |
||
36 | * Resolve processing nodes in the instruction |
||
37 | * |
||
38 | * @param array $list |
||
39 | * @return array |
||
40 | */ |
||
41 | 4 | View Code Duplication | public function resolve($list) |
61 | |||
62 | /** |
||
63 | * Calculate sum |
||
64 | * |
||
65 | * @param array $list |
||
66 | * |
||
67 | * @return number |
||
68 | */ |
||
69 | 4 | protected function execute(array $list) |
|
75 | } |
||
76 | |||
77 |
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.