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 |
||
15 | class Query implements RestAnnotationInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $parameterName; |
||
21 | |||
22 | /** |
||
23 | * @var string|null |
||
24 | */ |
||
25 | private $denormalizationType; |
||
26 | |||
27 | /** |
||
28 | * @var string|null |
||
29 | */ |
||
30 | private $denormalizationGroup; |
||
31 | |||
32 | /** |
||
33 | * @var Validation|null |
||
34 | */ |
||
35 | private $validation; |
||
36 | |||
37 | 96 | View Code Duplication | public function __construct(array $options) |
44 | |||
45 | /** |
||
46 | * @param string $parameterName |
||
47 | * @return $this |
||
48 | */ |
||
49 | 96 | private function setParameterName(string $parameterName): self |
|
54 | |||
55 | /** |
||
56 | * @param string|null $denormalizationType |
||
57 | * @return $this |
||
58 | */ |
||
59 | 96 | private function setDenormalizationType($denormalizationType): self |
|
64 | |||
65 | /** |
||
66 | * @param string|null $denormalizationGroup |
||
67 | * @return $this |
||
68 | */ |
||
69 | 96 | public function setDenormalizationGroup($denormalizationGroup): self |
|
74 | |||
75 | /** |
||
76 | * @param Validation|null $validation |
||
77 | * @return $this |
||
78 | */ |
||
79 | 96 | private function setValidation($validation): self |
|
84 | |||
85 | 96 | public function isSeveralSupported(): bool |
|
89 | |||
90 | 96 | public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod) |
|
102 | |||
103 | 96 | View Code Duplication | private function resolveDenormalizationType(ReflectionMethodWrapper $reflectionMethod): string |
121 | |||
122 | 96 | private function setValidationOptions(ReflectionMethodWrapper $reflectionMethod, QueryResolverOptions $options) |
|
138 | } |
||
139 |
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.