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 | View Code Duplication | class ResourceMakeCommand extends BaseCommand |
|
| 11 | { |
||
| 12 | use GeneratorCommandTrait; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The console command singature. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $signature = 'make:request |
||
| 20 | {name : The name of the class} |
||
| 21 | {--a|addon= : The name of the addon} |
||
| 22 | {--c|collection= : Create a resource collection} |
||
| 23 | '; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The console command description. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $description = '[+] Create a new resource'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The type of class being generated. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $type = 'Resource'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The constructor. |
||
| 41 | */ |
||
| 42 | 5 | public function __construct() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Get the default namespace for the class. |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | 3 | protected function getDefaultNamespace() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Get the stub file for the generator. |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | 3 | protected function getStub() |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Generate file. |
||
| 71 | * |
||
| 72 | * @param \Jumilla\Generators\FileGenerator $generator |
||
| 73 | * @param string $path |
||
| 74 | * @param string $fqcn |
||
| 75 | * |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | 3 | protected function generateFile(FileGenerator $generator, $path, $fqcn) |
|
| 88 | } |
||
| 89 |