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 models. */ |
||
30 | protected $fieldsModels; |
||
31 | |||
32 | protected $defaultView = 'ListView'; |
||
33 | |||
34 | /** |
||
35 | * Get module model instance. |
||
36 | * |
||
37 | * @param string $moduleName |
||
38 | * |
||
39 | * @return self |
||
|
|||
40 | */ |
||
41 | public static function getInstance(string $moduleName): self |
||
49 | |||
50 | /** |
||
51 | * Constructor function. |
||
52 | * |
||
53 | * @param string $moduleName |
||
54 | */ |
||
55 | public function __construct(string $moduleName) |
||
59 | |||
60 | /** |
||
61 | * Function to check permission for a Module/Action. |
||
62 | * |
||
63 | * @param string $module |
||
64 | * @param string $action |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | public static function isPermittedByModule(string $module, string $action) |
||
83 | |||
84 | /** |
||
85 | * unction to check permission for a Module/Action. |
||
86 | * |
||
87 | * @param string $action |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function isPermitted(string $action): bool |
||
95 | |||
96 | /** |
||
97 | * Get all fields. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getFields(): array |
||
113 | |||
114 | /** |
||
115 | * Get all fields models. |
||
116 | * |
||
117 | * @return \YF\Modules\Base\FieldTypes\BaseField[] |
||
118 | */ |
||
119 | public function getFieldsModels(): array |
||
127 | |||
128 | /** |
||
129 | * Get fields and blocks. |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | public function getFieldsFromApi(): array |
||
143 | |||
144 | /** |
||
145 | * Get tabs. |
||
146 | * |
||
147 | * @param int $record |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getTabsFromApi(int $record): array |
||
170 | |||
171 | /** |
||
172 | * Get field by name. |
||
173 | * |
||
174 | * @param string $name |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | public function getField(string $name): array |
||
188 | |||
189 | /** |
||
190 | * Get field model by name. |
||
191 | * |
||
192 | * @param string $name |
||
193 | * |
||
194 | * @return \YF\Modules\Base\FieldTypes\BaseField |
||
195 | */ |
||
196 | public function getFieldModel(string $name): \YF\Modules\Base\FieldTypes\BaseField |
||
203 | |||
204 | /** |
||
205 | * Returns default view for module. |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | public function getDefaultView(): string |
||
213 | |||
214 | /** |
||
215 | * Returns default address url. |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getDefaultUrl(): string |
||
223 | } |
||
224 |
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.