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 |
||
17 | class XmlResponseHandler extends Handler |
||
18 | { |
||
19 | /** |
||
20 | * @var bool |
||
21 | */ |
||
22 | private $returnFrames = false; |
||
23 | |||
24 | /** |
||
25 | * @param bool|null $returnFrames |
||
26 | * @return bool|static |
||
27 | */ |
||
28 | 1 | View Code Duplication | public function addTraceToOutput($returnFrames = null) |
37 | |||
38 | /** |
||
39 | * @return int |
||
40 | */ |
||
41 | 1 | public function handle() |
|
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | 1 | public function contentType() |
|
62 | |||
63 | /** |
||
64 | * @param SimpleXMLElement $node Node to append data to, will be modified in place |
||
65 | * @param array|\Traversable $data |
||
66 | * @return SimpleXMLElement The modified node, for chaining |
||
67 | */ |
||
68 | 1 | private static function addDataToNode(\SimpleXMLElement $node, $data) |
|
92 | |||
93 | /** |
||
94 | * The main function for converting to an XML document. |
||
95 | * |
||
96 | * @param array|\Traversable $data |
||
97 | * @return string XML |
||
98 | */ |
||
99 | 1 | private static function toXml($data) |
|
107 | } |
||
108 |
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.