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 declare(strict_types = 1); |
||
16 | abstract class Path implements Element |
||
17 | { |
||
18 | use VisiteeMixin; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $path; |
||
24 | |||
25 | /** |
||
26 | * @var Operation[] |
||
27 | */ |
||
28 | protected $operations; |
||
29 | |||
30 | /** |
||
31 | * @var Parameter[] |
||
32 | */ |
||
33 | protected $pathParameters = []; |
||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | public function getPath(): string |
||
42 | |||
43 | /** |
||
44 | * @return Operation[] |
||
45 | */ |
||
46 | public function getOperations(): array |
||
50 | |||
51 | /** |
||
52 | * @param string $method |
||
53 | * |
||
54 | * @return Operation |
||
55 | */ |
||
56 | public function getOperation(string $method): Operation |
||
69 | |||
70 | /** |
||
71 | * @return Parameter[] |
||
72 | */ |
||
73 | public function getPathParameters(): array |
||
77 | |||
78 | /** |
||
79 | * @param string $method |
||
80 | * @param \stdClass $operationDefinition |
||
81 | * |
||
82 | * @return Operation |
||
83 | */ |
||
84 | abstract protected function createOperation(string $method, \stdClass $operationDefinition): Operation; |
||
85 | } |
||
86 |
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.