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 Data |
||
14 | { |
||
15 | /** |
||
16 | * @return string |
||
17 | */ |
||
18 | public function getName() |
||
22 | |||
23 | /** |
||
24 | * @return string |
||
25 | */ |
||
26 | public function getType() |
||
30 | |||
31 | /** |
||
32 | * @param string $Name |
||
33 | */ |
||
34 | public function setName($Name) |
||
38 | |||
39 | /** |
||
40 | * @param string $Type |
||
41 | */ |
||
42 | public function setType($Type) |
||
46 | /** |
||
47 | * @var string Name |
||
48 | */ |
||
49 | protected $Name = 'N\A'; |
||
50 | /** @var string Type */ |
||
51 | protected $Type = 'N\A'; |
||
52 | |||
53 | /** |
||
54 | * Data constructor. |
||
55 | * @param \SimpleXMLElement $xmlData Xml data from file |
||
56 | */ |
||
57 | View Code Duplication | public function __construct(\SimpleXMLElement $xmlData) |
|
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.