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 |
||
18 | class Validator extends BaseValidator |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Config class instance |
||
23 | * @var \gplcart\core\Config $config |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | /** |
||
28 | * Constructor |
||
29 | * @param Config $config |
||
30 | */ |
||
31 | public function __construct(Config $config) |
||
37 | |||
38 | /** |
||
39 | * Validates an array of submitted data while creating a skeleton |
||
40 | * @param array $submitted |
||
41 | * @param array $options |
||
42 | * @return boolean|array |
||
43 | */ |
||
44 | public function skeleton(array &$submitted, array $options = array()) |
||
56 | |||
57 | /** |
||
58 | * Validates module author name |
||
59 | * @return boolean |
||
60 | */ |
||
61 | View Code Duplication | protected function validateModuleAuthorSkeleton() |
|
74 | |||
75 | /** |
||
76 | * Validates a module ID |
||
77 | */ |
||
78 | protected function validateModuleIdSkeleton() |
||
98 | |||
99 | /** |
||
100 | * Validates a module version |
||
101 | */ |
||
102 | View Code Duplication | protected function validateModuleVersionSkeleton() |
|
115 | |||
116 | /** |
||
117 | * Validates a module core compatibility |
||
118 | */ |
||
119 | protected function validateModuleCoreSkeleton() |
||
140 | |||
141 | } |
||
142 |
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.