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 TestCommand extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The name and signature of the console command. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $signature = 'test {--without-tty : Disable output to TTY}'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'Run the application tests'; |
||
26 | |||
27 | /** |
||
28 | * The arguments to be used while calling phpunit. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $arguments = [ |
||
33 | '--printer', |
||
34 | 'NunoMaduro\Collision\Adapters\Phpunit\Printer', |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * Create a new command instance. |
||
39 | * |
||
40 | * @return void |
||
|
|||
41 | */ |
||
42 | public function __construct() |
||
48 | |||
49 | /** |
||
50 | * Execute the console command. |
||
51 | * |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function handle() |
||
83 | |||
84 | /** |
||
85 | * Get the PHP binary to execute. |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | protected function binary() |
||
97 | |||
98 | /** |
||
99 | * Get the array of arguments for running PHPUnit. |
||
100 | * |
||
101 | * @param array $options |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | protected function phpunitArguments($options) |
||
117 | |||
118 | /** |
||
119 | * Gets an array with phpunit envs detected on the phpunit.xml file. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | protected function phpunitEnvs() |
||
154 | } |
||
155 |
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.