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 |
||
16 | class EntityParamConverter implements ParamConverterInterface |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var EntityTypeManagerInterface |
||
21 | */ |
||
22 | private $entityTypeManager; |
||
23 | |||
24 | /** |
||
25 | * @param EntityTypeManagerInterface $entityTypeManager |
||
26 | */ |
||
27 | 13 | public function __construct(EntityTypeManagerInterface $entityTypeManager) |
|
31 | |||
32 | /** |
||
33 | * @param Request $request |
||
34 | * @param ParamConverter $configuration |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | 5 | View Code Duplication | public function apply(Request $request, ParamConverter $configuration) |
57 | |||
58 | /** |
||
59 | * @param string $value |
||
60 | * @param ParamConverter $configuration |
||
61 | * |
||
62 | * @return EntityInterface|null |
||
63 | */ |
||
64 | 4 | protected function getNode($value, ParamConverter $configuration) |
|
71 | |||
72 | /** |
||
73 | * @param ParamConverter $configuration |
||
74 | * @param EntityInterface $node |
||
75 | */ |
||
76 | 4 | protected function assertValidNode( |
|
94 | |||
95 | /** |
||
96 | * @param ParamConverter $configuration |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 7 | public function supports(ParamConverter $configuration) |
|
114 | } |
||
115 |
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.