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 |
||
| 14 | abstract class Module |
||
| 15 | { |
||
| 16 | use Macroable; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The laravel|lumen application instance. |
||
| 20 | * |
||
| 21 | * @var \Illuminate\Contracts\Foundation\Application|\Laravel\Lumen\Application |
||
| 22 | */ |
||
| 23 | protected $app; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The module name. |
||
| 27 | * |
||
| 28 | * @var |
||
| 29 | */ |
||
| 30 | protected $name; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The module path. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $path; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array of cached Json objects, keyed by filename |
||
| 41 | */ |
||
| 42 | protected $moduleJson = []; |
||
| 43 | /** |
||
| 44 | * @var CacheManager |
||
| 45 | */ |
||
| 46 | private $cache; |
||
| 47 | /** |
||
| 48 | * @var Filesystem |
||
| 49 | */ |
||
| 50 | private $files; |
||
| 51 | /** |
||
| 52 | * @var Translator |
||
| 53 | */ |
||
| 54 | private $translator; |
||
| 55 | /** |
||
| 56 | * @var ActivatorInterface |
||
| 57 | */ |
||
| 58 | private $activator; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The constructor. |
||
| 62 | * @param Container $app |
||
| 63 | * @param $name |
||
| 64 | * @param $path |
||
| 65 | */ |
||
| 66 | 177 | View Code Duplication | public function __construct(Container $app, string $name, $path) |
| 76 | |||
| 77 | /** |
||
| 78 | * Get name. |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | 26 | public function getName(): string |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Get name in lower case. |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | 134 | public function getLowerName(): string |
|
| 96 | |||
| 97 | /** |
||
| 98 | * Get name in studly case. |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | 120 | public function getStudlyName(): string |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Get name in snake case. |
||
| 109 | * |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | 6 | public function getSnakeName(): string |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Get description. |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | 2 | public function getDescription(): string |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Get alias. |
||
| 129 | * |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | 4 | public function getAlias(): string |
|
| 136 | |||
| 137 | /** |
||
| 138 | * Get priority. |
||
| 139 | * |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function getPriority(): string |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Get module requirements. |
||
| 149 | * |
||
| 150 | * @return array |
||
| 151 | */ |
||
| 152 | 3 | public function getRequires(): array |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Get path. |
||
| 159 | * |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | 140 | public function getPath(): string |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Set path. |
||
| 169 | * |
||
| 170 | * @param string $path |
||
| 171 | * |
||
| 172 | * @return $this |
||
| 173 | */ |
||
| 174 | public function setPath($path): Module |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Bootstrap the application events. |
||
| 183 | */ |
||
| 184 | 2 | public function boot(): void |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Register module's translation. |
||
| 199 | * |
||
| 200 | * @return void |
||
| 201 | */ |
||
| 202 | 2 | protected function registerTranslation(): void |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Get json contents from the cache, setting as needed. |
||
| 215 | * |
||
| 216 | * @param string $file |
||
| 217 | * |
||
| 218 | * @return Json |
||
| 219 | */ |
||
| 220 | 20 | public function json($file = null) : Json |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Get a specific data from json file by given the key. |
||
| 233 | * |
||
| 234 | * @param string $key |
||
| 235 | * @param null $default |
||
| 236 | * |
||
| 237 | * @return mixed |
||
| 238 | */ |
||
| 239 | 13 | public function get(string $key, $default = null) |
|
| 243 | |||
| 244 | /** |
||
| 245 | * Get a specific data from composer.json file by given the key. |
||
| 246 | * |
||
| 247 | * @param $key |
||
| 248 | * @param null $default |
||
| 249 | * |
||
| 250 | * @return mixed |
||
| 251 | */ |
||
| 252 | 2 | public function getComposerAttr($key, $default = null) |
|
| 256 | |||
| 257 | /** |
||
| 258 | * Register the module. |
||
| 259 | */ |
||
| 260 | public function register(): void |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Register the module event. |
||
| 275 | * |
||
| 276 | * @param string $event |
||
| 277 | */ |
||
| 278 | 10 | protected function fireEvent($event): void |
|
| 282 | /** |
||
| 283 | * Register the aliases from this module. |
||
| 284 | */ |
||
| 285 | abstract public function registerAliases(): void; |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Register the service providers from this module. |
||
| 289 | */ |
||
| 290 | abstract public function registerProviders(): void; |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get the path to the cached *_module.php file. |
||
| 294 | * |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | abstract public function getCachedServicesPath(): string; |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Register the files from this module. |
||
| 301 | */ |
||
| 302 | protected function registerFiles(): void |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Handle call __toString. |
||
| 311 | * |
||
| 312 | * @return string |
||
| 313 | */ |
||
| 314 | 3 | public function __toString() |
|
| 318 | |||
| 319 | /** |
||
| 320 | * Determine whether the given status same with the current module status. |
||
| 321 | * |
||
| 322 | * @param bool $status |
||
| 323 | * |
||
| 324 | * @return bool |
||
| 325 | */ |
||
| 326 | 5 | public function isStatus(bool $status) : bool |
|
| 330 | |||
| 331 | /** |
||
| 332 | * Determine whether the current module activated. |
||
| 333 | * |
||
| 334 | * @return bool |
||
| 335 | */ |
||
| 336 | 8 | public function isEnabled() : bool |
|
| 337 | { |
||
| 338 | 8 | return $this->activator->hasStatus($this, true); |
|
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Determine whether the current module not disabled. |
||
| 343 | * |
||
| 344 | * @return bool |
||
| 345 | */ |
||
| 346 | 2 | public function isDisabled() : bool |
|
| 347 | { |
||
| 348 | 2 | return !$this->isEnabled(); |
|
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Set active state for current module. |
||
| 353 | * |
||
| 354 | * @param bool $active |
||
| 355 | * |
||
| 356 | * @return bool |
||
| 357 | */ |
||
| 358 | public function setActive(bool $active): bool |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Disable the current module. |
||
| 365 | */ |
||
| 366 | 4 | public function disable(): void |
|
| 375 | |||
| 376 | /** |
||
| 377 | * Enable the current module. |
||
| 378 | */ |
||
| 379 | 4 | public function enable(): void |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Delete the current module. |
||
| 391 | * |
||
| 392 | * @return bool |
||
| 393 | */ |
||
| 394 | 2 | public function delete(): bool |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Get extra path. |
||
| 403 | * |
||
| 404 | * @param string $path |
||
| 405 | * |
||
| 406 | * @return string |
||
| 407 | */ |
||
| 408 | 3 | public function getExtraPath(string $path) : string |
|
| 412 | |||
| 413 | /** |
||
| 414 | * Check if can load files of module on boot method. |
||
| 415 | * |
||
| 416 | * @return bool |
||
| 417 | */ |
||
| 418 | 2 | protected function isLoadFilesOnBoot(): bool |
|
| 424 | |||
| 425 | 8 | private function flushCache(): void |
|
| 431 | |||
| 432 | /** |
||
| 433 | * Register a translation file namespace. |
||
| 434 | * |
||
| 435 | * @param string $path |
||
| 436 | * @param string $namespace |
||
| 437 | * @return void |
||
| 438 | */ |
||
| 439 | 2 | private function loadTranslationsFrom(string $path, string $namespace): void |
|
| 443 | } |
||
| 444 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..