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 |
||
| 10 | class AddonRemoveCommand extends Command |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The console command signature. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $signature = 'addon:remove |
||
| 18 | {name : Name of addon.} |
||
| 19 | {--force : Force remove.} |
||
| 20 | '; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command description. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $description = 'Remove addon.'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \Illuminate\Filesystem\Filesystem |
||
| 31 | */ |
||
| 32 | protected $filesystem; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Execute the console command. |
||
| 36 | * |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | 3 | public function handle(Filesystem $filesystem, AddonEnvironment $env) |
|
| 62 | } |
||
| 63 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.