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 |
||
5 | class XmlFormat extends Format |
||
6 | { |
||
7 | private $xpath; |
||
8 | |||
9 | protected $name = 'XML File'; |
||
10 | protected $id = 'xml'; |
||
11 | |||
12 | 2 | protected $rowNodeName; |
|
13 | protected $rootNodeName; |
||
14 | 2 | protected $encoding; |
|
15 | 2 | protected $version; |
|
16 | |||
17 | 1 | View Code Duplication | public function __construct($xpath = null, $rowNodeName='node', $rootNodeName = 'root', $encoding = null, $version = '1.0') |
25 | |||
26 | public function getXpath() |
||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | public function getRowNodeName() |
||
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getRootNodeName() |
||
46 | |||
47 | /** |
||
48 | * @return null |
||
49 | */ |
||
50 | public function getEncoding() |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getVersion() |
||
62 | } |
||
63 |
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.