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 | View Code Duplication | trait AnnotationValueTrait |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * Parse annotation value. |
||
17 | * |
||
18 | * @param array $valueOrValues Class collection |
||
19 | * |
||
20 | * @return array Parsed annotation key=>value collection |
||
21 | * |
||
22 | * @throws \InvalidArgumentException Thrown when neither string nor string[] is passed |
||
23 | */ |
||
24 | 16 | public function parseAnnotationValue(array $valueOrValues) : array |
|
36 | |||
37 | /** |
||
38 | * Check if we received an array with keys. |
||
39 | * |
||
40 | * @param array $valueOrValues |
||
41 | * |
||
42 | * @return bool True if value key exists |
||
43 | */ |
||
44 | 16 | protected function checkValuePresence(array $valueOrValues) |
|
48 | } |
||
49 |
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.