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 |
||
20 | class GroupBy implements QueryModifier |
||
21 | { |
||
22 | /** |
||
23 | * @deprecated This property will be marked as private in 2.0. |
||
24 | * |
||
25 | * @var Field|Alias |
||
26 | */ |
||
27 | protected $field; |
||
28 | |||
29 | /** |
||
30 | * @deprecated This property will be marked as private in 2.0. |
||
31 | * |
||
32 | * @var string|null |
||
33 | */ |
||
34 | protected $dqlAlias; |
||
35 | |||
36 | /** |
||
37 | * @param Field|Alias|string $field |
||
38 | * @param string|null $dqlAlias |
||
39 | */ |
||
40 | View Code Duplication | public function __construct($field, $dqlAlias = null) |
|
49 | |||
50 | /** |
||
51 | * @param QueryBuilder $qb |
||
52 | * @param string $dqlAlias |
||
53 | */ |
||
54 | public function modify(QueryBuilder $qb, $dqlAlias) |
||
62 | } |
||
63 |
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.