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 |
||
17 | class DeleteContract extends Contract |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Column filter. |
||
22 | * |
||
23 | * @var ColumnFilter |
||
24 | */ |
||
25 | private $filter; |
||
26 | |||
27 | /** |
||
28 | * Sets the input values. |
||
29 | * |
||
30 | * @param string $rootSchemaName The name of the root schema object. |
||
31 | */ |
||
32 | 7 | public function __construct($rootSchemaName) |
|
40 | |||
41 | /** |
||
42 | * Adding query filter to contract. |
||
43 | * |
||
44 | * @param ColumnFilter $columnFilter Column filter. |
||
45 | * |
||
46 | * @return self |
||
47 | */ |
||
48 | 2 | public function addFilter(ColumnFilter $columnFilter) |
|
53 | |||
54 | /** |
||
55 | * Returns data as an associative array. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | 2 | public function toArray() |
|
71 | |||
72 | /** |
||
73 | * Validates contract data, throws an exception in case of an error. |
||
74 | * |
||
75 | * @throws ValidateException |
||
76 | */ |
||
77 | 2 | View Code Duplication | public function validate() |
84 | } |
||
85 |
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.