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 |
||
13 | abstract class DatatableVersion extends Version |
||
14 | { |
||
15 | /** |
||
16 | * @var QueryParser |
||
17 | */ |
||
18 | protected $queryParser; |
||
19 | |||
20 | /** |
||
21 | * DatatableVersion constructor. |
||
22 | * @param RequestStack $requestStack |
||
23 | * @param QueryParser $queryParser |
||
24 | */ |
||
25 | public function __construct(RequestStack $requestStack, QueryParser $queryParser) |
||
30 | |||
31 | /** |
||
32 | * Method to determine if this parser can handle the query parameters. If so then the parser should return true |
||
33 | * and be able to return a DTQueryConfiguration |
||
34 | * |
||
35 | * @return bool true if the parser is able to parse the query parameters and to return a DTQueryConfiguration |
||
36 | */ |
||
37 | View Code Duplication | public function canParseRequest() |
|
45 | |||
46 | /** |
||
47 | * Method that should parse the request and return a DTQueryConfiguration |
||
48 | * |
||
49 | * @param ColumnConfiguration[] $columnConfiguration The configuration of the columns |
||
50 | * @return QueryConfiguration the configuration the provider can use to prepare the data |
||
51 | */ |
||
52 | View Code Duplication | public function parseRequest(array $columnConfiguration) |
|
60 | } |
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.