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 |
||
22 | class ClassMetadata extends BaseClassMetadata |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | public $defaultGroup; |
||
28 | |||
29 | /** |
||
30 | * @return string |
||
31 | */ |
||
32 | public function getClassName() |
||
36 | |||
37 | /** |
||
38 | * @param string $property |
||
39 | * |
||
40 | * @return PropertyMetadata|null |
||
41 | */ |
||
42 | protected function getPropertyMetadata($property) |
||
46 | |||
47 | /** |
||
48 | * @param string $property |
||
49 | * @param Assert $constraint |
||
50 | * @param string $group |
||
51 | */ |
||
52 | View Code Duplication | public function addPropertyConstraint($property, Assert $constraint, $group = null) |
|
64 | |||
65 | /** |
||
66 | * @param string $property |
||
67 | * @param array $constraints |
||
68 | * @param string $group |
||
69 | */ |
||
70 | public function addPropertyConstraints($property, array $constraints, $group = null) |
||
76 | |||
77 | /** |
||
78 | * @return PropertyMetadata[] |
||
79 | */ |
||
80 | public function getPropertiesMetadata() |
||
84 | |||
85 | /** |
||
86 | * @param string $method |
||
87 | * |
||
88 | * @return MethodMetadata|null |
||
89 | */ |
||
90 | protected function getMethodMetadata($method) |
||
94 | |||
95 | /** |
||
96 | * @param string $method |
||
97 | * @param Assert $constraint |
||
98 | * @param string $group |
||
99 | */ |
||
100 | View Code Duplication | public function addMethodConstraint($method, Assert $constraint, $group = null) |
|
112 | |||
113 | /** |
||
114 | * @param string $method |
||
115 | * @param array $constraints |
||
116 | * @param string $group |
||
117 | */ |
||
118 | public function addMethodConstraints($method, array $constraints, $group = null) |
||
124 | |||
125 | /** |
||
126 | * @return MethodMetadata[] |
||
127 | */ |
||
128 | public function getMethodsMetadata() |
||
132 | |||
133 | /** |
||
134 | * Merges the constraints of the given metadata into this object. |
||
135 | * |
||
136 | * @param ClassMetadata $source |
||
137 | */ |
||
138 | public function mergeConstraints(ClassMetadata $source) |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function serialize() |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function unserialize($str) |
||
183 | } |
||
184 |
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.