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 |
||
26 | class WhoAmIController extends RestController |
||
27 | { |
||
28 | /** |
||
29 | * @param Response $response Response |
||
30 | * @param RestUtilsInterface $restUtils Rest utils |
||
31 | * @param Router $router Router |
||
32 | * @param ValidatorInterface $validator Validator |
||
33 | * @param EngineInterface $templating Templating |
||
34 | * @param FormFactory $formFactory form factory |
||
35 | * @param DocumentType $formType generic form |
||
36 | * @param ContainerInterface $container Container |
||
37 | * @param SchemaUtils $schemaUtils schema utils |
||
38 | */ |
||
39 | View Code Duplication | public function __construct( |
|
62 | |||
63 | /** |
||
64 | * Currently authenticated user information. |
||
65 | * If security is not enabled then header will be Not Allowed. |
||
66 | * If User not found using correct header Anonymous user |
||
67 | * Serialised Object transformer |
||
68 | * |
||
69 | * @return Response $response Response with result or error |
||
70 | */ |
||
71 | public function whoAmIAction() |
||
94 | |||
95 | /** |
||
96 | * Returns schema |
||
97 | * |
||
98 | * @return Response $response Response with result or error |
||
99 | */ |
||
100 | View Code Duplication | public function whoAmiSchemaAction() |
|
113 | } |
||
114 |
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.