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 |
||
11 | class MissingCommand extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The name and signature of the console command. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $signature = 'autotrans:missing'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'Translates all source translations that are not set in your target translations'; |
||
26 | |||
27 | protected $phpTranslator; |
||
28 | protected $jsonTranslator; |
||
29 | |||
30 | /** |
||
31 | * Create a new command instance. |
||
32 | * |
||
33 | * @return void |
||
|
|||
34 | */ |
||
35 | View Code Duplication | public function __construct(PhpTranslator $phpTranslator, JsonTranslator $jsonTranslator) |
|
42 | |||
43 | /** |
||
44 | * Execute the console command. |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | View Code Duplication | public function handle() |
|
62 | |||
63 | View Code Duplication | public function translatePhpFiles() |
|
91 | |||
92 | View Code Duplication | public function translateJsonFiles() |
|
120 | } |
||
121 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.