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 PathAttribute implements RestAnnotationInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $parameterName; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $pathPartName; |
||
26 | |||
27 | /** |
||
28 | * @var string|null |
||
29 | */ |
||
30 | private $resolverType; |
||
31 | |||
32 | /** |
||
33 | * @var bool|null |
||
34 | */ |
||
35 | private $resolutionMandatory; |
||
36 | |||
37 | 96 | 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 $pathPartName |
||
57 | * @return $this |
||
58 | */ |
||
59 | 96 | private function setPathPartName(string $pathPartName): self |
|
64 | |||
65 | /** |
||
66 | * @param string|null $resolverType |
||
67 | * @return $this |
||
68 | */ |
||
69 | 96 | private function setResolverType($resolverType): self |
|
74 | |||
75 | /** |
||
76 | * @param bool|null $resolutionMandatory |
||
77 | * @return $this |
||
78 | */ |
||
79 | 96 | private function setResolutionMandatory($resolutionMandatory): self |
|
84 | |||
85 | 96 | public function isSeveralSupported(): bool |
|
89 | |||
90 | 96 | public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod) |
|
100 | |||
101 | 96 | private function resolvePathAttributeResolverType(ReflectionMethodWrapper $reflectionMethod): string |
|
117 | |||
118 | 96 | View Code Duplication | private function resolveIfResolutionIsMandatory(ReflectionMethodWrapper $reflectionMethod): bool |
128 | } |
||
129 |
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.