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 |
||
19 | class InnerHitValue |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $rawData; |
||
25 | |||
26 | /** |
||
27 | * @var Manager |
||
28 | */ |
||
29 | private $manager; |
||
30 | |||
31 | /** |
||
32 | * @param array $rawData |
||
33 | * @param Manager $manager |
||
34 | */ |
||
35 | public function __construct($rawData, Manager $manager) |
||
40 | |||
41 | /** |
||
42 | * Returns array of specific inner hit objects |
||
43 | * |
||
44 | * @param string $name |
||
45 | * |
||
46 | * @return object[] |
||
47 | */ |
||
48 | public function getValue($name) |
||
83 | |||
84 | /** |
||
85 | * Returns the count of inner hits for a specific hit |
||
86 | * |
||
87 | * @param string $name |
||
88 | * |
||
89 | * @return integer |
||
90 | */ |
||
91 | View Code Duplication | public function getCount($name) |
|
99 | |||
100 | /** |
||
101 | * Returns inner hits for a specified inner hit |
||
102 | * |
||
103 | * @param string $name |
||
104 | * |
||
105 | * @return InnerHitValue[]|null |
||
106 | */ |
||
107 | public function getInnerHits($name) |
||
121 | } |
||
122 |
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.