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 Robot extends Data |
||
14 | { |
||
15 | /** |
||
16 | * @return string |
||
17 | */ |
||
18 | public function getHomepage() |
||
22 | |||
23 | /** |
||
24 | * @return boolean |
||
25 | */ |
||
26 | public function isSearchEngine() |
||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | public function getOwner() |
||
38 | |||
39 | /** |
||
40 | * @param string $Homepage |
||
41 | */ |
||
42 | public function setHomepage($Homepage) |
||
46 | |||
47 | /** |
||
48 | * @param string $Owner |
||
49 | */ |
||
50 | public function setOwner($Owner) |
||
54 | |||
55 | /** |
||
56 | * @param boolean $isSearchEngine |
||
57 | */ |
||
58 | public function setSearchEngine($isSearchEngine) |
||
62 | /** @var string Crawler homepage */ |
||
63 | private $Homepage; |
||
64 | |||
65 | /** @var boolean Search Engine */ |
||
66 | private $SearchEngine; |
||
67 | |||
68 | /** @var string Crawler Owner */ |
||
69 | private $Owner; |
||
70 | |||
71 | View Code Duplication | public function __construct(\SimpleXMLElement $xmlData) |
|
91 | } |
||
92 |
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.