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