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 |
||
| 17 | class AddonMakeCommand extends Command |
||
| 18 | { |
||
| 19 | use Functions; |
||
| 20 | use MakeCommandTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command signature. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $signature = 'make:addon |
||
| 28 | {name : The name of the addon.} |
||
| 29 | {skeleton? : Skeleton of addon.} |
||
| 30 | {--space= : Addons space.} |
||
| 31 | {--namespace= : PHP namespace of addon. Slash OK.} |
||
| 32 | {--no-namespace : No PHP namespace.} |
||
| 33 | {--language= : Languages, comma separated.} |
||
| 34 | {--yes : No confirm.} |
||
| 35 | '; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The console command description. |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $description = 'Create a new addon directory'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $skeletons = [ |
||
| 48 | 1 => 'minimum', |
||
| 49 | 2 => 'simple', |
||
| 50 | 3 => 'asset', |
||
| 51 | 4 => 'library', |
||
| 52 | 5 => 'api', |
||
| 53 | 6 => 'ui', |
||
| 54 | 11 => 'ui-sample', |
||
| 55 | 12 => 'debug', |
||
| 56 | 13 => 'generator', |
||
| 57 | 14 => 'laravel5', |
||
| 58 | 15 => 'laravel5-auth', |
||
| 59 | ]; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $default_skeleton = 'ui-sample'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Execute the console command. |
||
| 68 | * |
||
| 69 | * @param \Jumilla\Addomnipot\Laravel\Addons\AddonGenerator $generator |
||
| 70 | * |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | 3 | public function handle(Filesystem $filesystem, AddonEnvironment $env, AddonGenerator $generator) |
|
| 141 | } |
||
| 142 |
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.