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 |
||
13 | class KnpSnappyAutodetectBundle extends Bundle |
||
14 | { |
||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | 9 | public function build(ContainerBuilder $container) |
|
30 | |||
31 | /** |
||
32 | * Gets wkhtmltoimage binary based on operating system and architecture. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | 9 | View Code Duplication | private function getImageBinary() |
55 | |||
56 | /** |
||
57 | * Gets wkhtmltopdf binary based on operating system and architecture. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 9 | View Code Duplication | private function getPdfBinary() |
80 | |||
81 | /** |
||
82 | * Detects common operating systems. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 9 | private function detectOs() |
|
98 | |||
99 | /** |
||
100 | * Detects common architecture types. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 9 | private function detectArchitecture() |
|
113 | } |
||
114 |
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.