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 | View Code Duplication | class DefaultController |
|
|
|||
17 | { |
||
18 | /** @var ServiceManager */ |
||
19 | private $serviceManager; |
||
20 | |||
21 | /** |
||
22 | * DefaultController constructor. |
||
23 | * @param ServiceManager $serviceManager Parsing the requested date |
||
24 | */ |
||
25 | public function __construct( |
||
30 | |||
31 | /** |
||
32 | * @return JsonResponse |
||
33 | */ |
||
34 | public function indexAction() |
||
41 | |||
42 | /** |
||
43 | * @return Response |
||
44 | */ |
||
45 | public function optionsAction() |
||
52 | |||
53 | /** |
||
54 | * @return Response |
||
55 | */ |
||
56 | public function proxyAction() |
||
60 | |||
61 | /** |
||
62 | * @return JsonResponse |
||
63 | */ |
||
64 | public function schemaAction() |
||
70 | } |
||
71 |
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.