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 |
||
25 | class StaticValidator extends StaticValidatorValidatorZend |
||
26 | { |
||
27 | /** |
||
28 | * ReportingCloud Validator classes |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | static protected $invokableClasses = [ |
||
33 | DateTime::class, |
||
34 | DocumentExtension::class, |
||
35 | FileExists::class, |
||
36 | FileExtension::class, |
||
37 | FileHasExtension::class, |
||
38 | ImageFormat::class, |
||
39 | Page::class, |
||
40 | ReturnFormat::class, |
||
41 | TemplateExtension::class, |
||
42 | TemplateFormat::class, |
||
43 | TemplateName::class, |
||
44 | Timestamp::class, |
||
45 | TypeArray::class, |
||
46 | TypeBoolean::class, |
||
47 | TypeInteger::class, |
||
48 | TypeString::class, |
||
49 | ZoomFactor::class, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Get plugin manager for loading validator classes, adding ReportingCloud Validator classes |
||
54 | * |
||
55 | * @return \Zend\Validator\ValidatorPluginManager |
||
56 | */ |
||
57 | 152 | View Code Duplication | public static function getPluginManager() |
71 | |||
72 | /** |
||
73 | * Statically call a Validator and throw exception on failure |
||
74 | * |
||
75 | * @param mixed $value Value |
||
76 | * @param string $className Class name |
||
77 | * @param array $options Options |
||
78 | * |
||
79 | * @return bool |
||
80 | * |
||
81 | * @throws InvalidArgumentException |
||
82 | */ |
||
83 | 153 | public static function execute($value, $className, array $options = []) |
|
108 | |||
109 | } |
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.