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 ReflectionMutator implements MutatorInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var \ReflectionProperty[] |
||
21 | */ |
||
22 | private $properties = []; |
||
23 | |||
24 | /** |
||
25 | * @var \ReflectionMethod[] |
||
26 | */ |
||
27 | private $methods = []; |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | 328 | public function setValue($object, $property, $value) |
|
40 | |||
41 | /** |
||
42 | * @param object $object |
||
43 | * @param string $property |
||
44 | * @param mixed $value |
||
45 | */ |
||
46 | 16 | View Code Duplication | private function setMethodValue($object, $property, $value) |
75 | |||
76 | /** |
||
77 | * @param object $object |
||
78 | * @param string $property |
||
79 | * |
||
80 | * @return \ReflectionProperty |
||
81 | */ |
||
82 | 312 | View Code Duplication | private function getReflectionProperty($object, $property) |
93 | |||
94 | /** |
||
95 | * @param object $object |
||
96 | * @param string $method |
||
97 | * |
||
98 | * @return \ReflectionMethod |
||
99 | */ |
||
100 | 16 | View Code Duplication | private function getReflectionMethod($object, $method) |
111 | |||
112 | /** |
||
113 | * @param object $object |
||
114 | * @param string $key |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 328 | private function getCacheKey($object, $key) |
|
122 | } |
||
123 |
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.