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 |
||
12 | class TestCommand extends Command |
||
13 | { |
||
14 | /** |
||
15 | * The name and signature of the console command. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $signature = 'test {--without-tty : Disable output to TTY}'; |
||
20 | |||
21 | /** |
||
22 | * The console command description. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $description = 'Run the application tests'; |
||
27 | |||
28 | /** |
||
29 | * The arguments to be used while calling phpunit. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $arguments = [ |
||
34 | '--printer', |
||
35 | 'NunoMaduro\Collision\Adapters\Phpunit\Printer', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * Create a new command instance. |
||
40 | * |
||
41 | * @return void |
||
|
|||
42 | */ |
||
43 | public function __construct() |
||
49 | |||
50 | /** |
||
51 | * Execute the console command. |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function handle() |
||
85 | |||
86 | /** |
||
87 | * Get the PHP binary to execute. |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | protected function binary() |
||
99 | |||
100 | /** |
||
101 | * Get the array of arguments for running PHPUnit. |
||
102 | * |
||
103 | * @param array $options |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | protected function phpunitArguments($options) |
||
119 | |||
120 | /** |
||
121 | * Gets an array with phpunit envs detected on the phpunit.xml file. |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | protected function phpunitEnvs() |
||
126 | { |
||
127 | $envs = []; |
||
128 | |||
129 | if (! file_exists($file = base_path('phpunit.xml'))) { |
||
130 | $file = base_path('phpunit.xml.dist'); |
||
131 | } |
||
132 | |||
133 | if (file_exists($file)) { |
||
134 | /** @var \SimpleXMLElement $xml */ |
||
135 | $xml = simplexml_load_string((string) file_get_contents($file)); |
||
136 | |||
137 | View Code Duplication | if (is_iterable($xml->php->server)) { |
|
138 | foreach ($xml->php->server as $env) { |
||
139 | if (isset($env['name'])) { |
||
140 | $envs[$env['name']->__toString()] = $env['value'] ? $env['value']->__toString() : false; |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | View Code Duplication | if (is_iterable($xml->php->env)) { |
|
146 | foreach ($xml->php->env as $env) { |
||
147 | if (isset($env['name'])) { |
||
148 | $envs[$env['name']->__toString()] = $env['value'] ? $env['value']->__toString() : false; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | |||
154 | |||
155 | if (! empty($envs['APP_ENV']) && ! $this->option('env')) { |
||
156 | $envs = array_merge($this->fromEnvFile($envs['APP_ENV']), $envs); |
||
157 | } |
||
158 | |||
159 | return $envs; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Loads the environment file if it exists otherwise returns empty array. |
||
164 | * |
||
165 | * @param string $environment |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | protected function fromEnvFile($environment) |
||
176 | } |
||
177 |
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.