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 |
||
35 | View Code Duplication | class Check extends Column implements CheckInterface |
|
|
|||
36 | { |
||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $cols; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $items; |
||
46 | |||
47 | /** |
||
48 | * Input constructor. |
||
49 | * |
||
50 | * @param string $columnName |
||
51 | * @param $configuration |
||
52 | */ |
||
53 | public function __construct($columnName, $configuration) |
||
59 | |||
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | public function getCols() |
||
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getItems() |
||
76 | |||
77 | /** |
||
78 | * @param array $items |
||
79 | * @return CheckInterface |
||
80 | */ |
||
81 | public function setItems(array $items) |
||
87 | } |
||
88 |
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.