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 Module |
||
19 | { |
||
20 | /** @var YF\Modules\Base\Model\Module[] Module model cache. */ |
||
21 | protected static $cache; |
||
22 | |||
23 | /** @var string Module name. */ |
||
24 | protected $moduleName; |
||
25 | |||
26 | /** @var array Fields. */ |
||
27 | protected $fields = []; |
||
28 | |||
29 | /** @var array Fields. */ |
||
30 | protected $fieldsForm; |
||
31 | |||
32 | /** @var array Data from API fields. */ |
||
33 | protected $apiFields; |
||
34 | |||
35 | /** @var array Fields models. */ |
||
36 | protected $fieldsModels; |
||
37 | |||
38 | protected $defaultView = 'ListView'; |
||
39 | |||
40 | /** |
||
41 | * Get module model instance. |
||
42 | * |
||
43 | * @param string $moduleName |
||
44 | * |
||
45 | * @return self |
||
|
|||
46 | */ |
||
47 | public static function getInstance(string $moduleName): self |
||
55 | |||
56 | /** |
||
57 | * Constructor function. |
||
58 | * |
||
59 | * @param string $moduleName |
||
60 | */ |
||
61 | public function __construct(string $moduleName) |
||
65 | |||
66 | /** |
||
67 | * Function to check permission for a Module/Action. |
||
68 | * |
||
69 | * @param string $module |
||
70 | * @param string $action |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | public static function isPermittedByModule(string $module, string $action) |
||
89 | |||
90 | /** |
||
91 | * unction to check permission for a Module/Action. |
||
92 | * |
||
93 | * @param string $action |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function isPermitted(string $action): bool |
||
101 | |||
102 | /** |
||
103 | * Get fields and blocks. |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function loadFieldsFromApi(): void |
||
117 | |||
118 | /** |
||
119 | * Get all blocks. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getBlocks(): array |
||
130 | |||
131 | /** |
||
132 | * Get all fields. |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getFields(): array |
||
143 | |||
144 | /** |
||
145 | * Get inventory fields. |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function getInventoryFields(): array |
||
156 | |||
157 | /** |
||
158 | * Get field by name. |
||
159 | * |
||
160 | * @param string $name |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | public function getField(string $name): array |
||
174 | |||
175 | /** |
||
176 | * Get field model by name. |
||
177 | * |
||
178 | * @param string $name |
||
179 | * |
||
180 | * @return \YF\Modules\Base\FieldTypes\BaseField |
||
181 | */ |
||
182 | public function getFieldModel(string $name): \YF\Modules\Base\FieldTypes\BaseField |
||
189 | |||
190 | /** |
||
191 | * Get all field names. |
||
192 | * |
||
193 | * @return string[] |
||
194 | */ |
||
195 | public function getFieldNames(): array |
||
202 | |||
203 | /** |
||
204 | * Get form fields models. |
||
205 | * |
||
206 | * @return \YF\Modules\Base\FieldTypes\BaseField[] |
||
207 | */ |
||
208 | public function getFormFields(): array |
||
215 | |||
216 | /** |
||
217 | * Get fields models. |
||
218 | * |
||
219 | * @return \YF\Modules\Base\FieldTypes\BaseField[] |
||
220 | */ |
||
221 | public function getFieldsModels(): array |
||
228 | |||
229 | /** |
||
230 | * Load all fields models. |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | public function loadFieldsModels(): void |
||
250 | |||
251 | /** |
||
252 | * Get tabs. |
||
253 | * |
||
254 | * @param int $record |
||
255 | * |
||
256 | * @return array |
||
257 | */ |
||
258 | public function getTabsFromApi(int $record): array |
||
277 | |||
278 | /** |
||
279 | * Returns default view for module. |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | public function getDefaultView(): string |
||
287 | |||
288 | /** |
||
289 | * Returns default address url. |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function getDefaultUrl(): string |
||
297 | |||
298 | /** |
||
299 | * Function to check is quick create supported. |
||
300 | * |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function isQuickCreateSupported(): bool |
||
307 | } |
||
308 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.