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 ContentId extends Criterion |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * Creates a new ContentId criterion. |
||
25 | * |
||
26 | * @param int|int[] $value One or more content Id that must be matched. |
||
27 | * |
||
28 | * @throws \InvalidArgumentException if a non numeric id is given |
||
29 | * @throws \InvalidArgumentException if the value type doesn't match the operator |
||
30 | */ |
||
31 | public function __construct($value) |
||
35 | |||
36 | public function getSpecifications() |
||
45 | |||
46 | /** |
||
47 | * @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead. |
||
48 | */ |
||
49 | public static function createFromQueryBuilder($target, $operator, $value) |
||
55 | } |
||
56 |
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.