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 |
||
21 | View Code Duplication | class Datatable110Version extends DatatableVersion |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * Datatable110Version constructor. |
||
25 | * |
||
26 | * @param RequestStack $requestStack The current request |
||
27 | */ |
||
28 | public function __construct(RequestStack $requestStack) |
||
32 | |||
33 | /** |
||
34 | * Is responsible to take the generated data and prepare a response for it. |
||
35 | * @param ResponseData $data The processed data. |
||
36 | * @param QueryConfiguration $queryConfiguration the query configuration for the current request. |
||
37 | * @param ColumnConfiguration[] $columnConfigurations the column configurations for the current data table. |
||
38 | * @return JsonResponse the response that should be returned to the client. |
||
39 | */ |
||
40 | public function createResponse( |
||
54 | |||
55 | /** |
||
56 | * @return string The name of the view that this version should use fot the table. |
||
57 | */ |
||
58 | public function tableView() |
||
62 | |||
63 | /** |
||
64 | * @return string The name of the view that this version should use for the script. |
||
65 | */ |
||
66 | public function scriptView() |
||
70 | } |
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.