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 |
||
12 | View Code Duplication | class Decode implements Processor |
|
|
|||
13 | { |
||
14 | use Processor\Implementation; |
||
15 | |||
16 | /** |
||
17 | * Apply processing to a single node |
||
18 | * |
||
19 | * @param Node $node |
||
20 | */ |
||
21 | public function applyToNode(Node $node) |
||
41 | |||
42 | |||
43 | /** |
||
44 | * Base64 decode |
||
45 | * |
||
46 | * @param string $input |
||
47 | */ |
||
48 | public function base64($input) |
||
52 | |||
53 | /** |
||
54 | * Base58 decode |
||
55 | * |
||
56 | * @param string $input |
||
57 | */ |
||
58 | public function base58($input) |
||
63 | |||
64 | /** |
||
65 | * Url decode |
||
66 | * |
||
67 | * @param string $input |
||
68 | */ |
||
69 | public function url($input) |
||
73 | } |
||
74 |
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.