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 |
||
22 | class FileAccessibilityAndValidationCheck implements EnvironmentCheck |
||
|
|||
23 | { |
||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | const CHECK_SINGLE = 1; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | const CHECK_ALL = 2; |
||
33 | |||
34 | /** |
||
35 | * Absolute path to a file or folder, compatible with glob(). |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $path; |
||
40 | |||
41 | /** |
||
42 | * Constant, check for a single file to match age criteria, or all of them. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $fileTypeValidateFunc; |
||
47 | |||
48 | /** |
||
49 | * Constant, check for a single file to match age criteria, or all of them. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $checkType; |
||
54 | |||
55 | /** |
||
56 | * @param string $path |
||
57 | * @param string $fileTypeValidateFunc |
||
58 | * @param null|int $checkType |
||
59 | */ |
||
60 | public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null) |
||
66 | |||
67 | /** |
||
68 | * @inheritdoc |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public function check() |
||
148 | |||
149 | /** |
||
150 | * @param string $file |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | private function jsonValidate($file) |
||
163 | |||
164 | /** |
||
165 | * @param string $file |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | protected function noVidation($file) |
||
173 | |||
174 | /** |
||
175 | * Gets a list of absolute file paths. |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | protected function getFiles() |
||
183 | } |
||
184 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.