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 | class Style extends SymfonyStyle |
||
11 | { |
||
12 | /** |
||
13 | * @var \Symfony\Component\Console\Helper\FormatterHelper |
||
14 | */ |
||
15 | protected $formatter; |
||
16 | |||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $align = 20; |
||
21 | |||
22 | /** |
||
23 | * Style constructor. |
||
24 | * |
||
25 | * @param InputInterface $input |
||
26 | * @param OutputInterface $output |
||
27 | * @param Command $command |
||
28 | */ |
||
29 | 7 | public function __construct(InputInterface $input, OutputInterface $output, Command $command) |
|
35 | |||
36 | /** |
||
37 | * @param int $align |
||
38 | * @return $this |
||
39 | */ |
||
40 | public function setAlign($align) |
||
46 | |||
47 | /** |
||
48 | * @return int |
||
49 | */ |
||
50 | public function getAlign() |
||
54 | |||
55 | /** |
||
56 | * @param string $section |
||
57 | * @param string $message |
||
58 | * @param string $style |
||
59 | * @throws \InvalidArgumentException |
||
60 | * @return $this |
||
61 | */ |
||
62 | 7 | public function formatSection($section, $message, $style = 'info') |
|
74 | |||
75 | /** |
||
76 | * @param string|array $messages |
||
77 | * @param string $style |
||
78 | * @param bool $large |
||
79 | * @throws \InvalidArgumentException |
||
80 | * @return $this |
||
81 | */ |
||
82 | public function formatBlock($messages, $style, $large = false) |
||
94 | |||
95 | /** |
||
96 | * @param array $message |
||
97 | * @throws \InvalidArgumentException |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function errorLine(array $message) |
||
108 | |||
109 | /** |
||
110 | * @param string|int $strLength |
||
111 | * @param int $align |
||
112 | * @return string |
||
113 | */ |
||
114 | 5 | public function align($strLength, $align) |
|
129 | |||
130 | /** |
||
131 | * @param $message |
||
132 | * @return $this |
||
133 | * @throws \InvalidArgumentException |
||
134 | */ |
||
135 | View Code Duplication | public function okMessage($message) |
|
144 | |||
145 | /** |
||
146 | * @param $message |
||
147 | * @return $this |
||
148 | * @throws \InvalidArgumentException |
||
149 | */ |
||
150 | 1 | View Code Duplication | public function errorMessage($message) |
159 | |||
160 | /** |
||
161 | * @param $message |
||
162 | * @return $this |
||
163 | * @throws \InvalidArgumentException |
||
164 | */ |
||
165 | View Code Duplication | public function warningMessage($message) |
|
174 | |||
175 | /** |
||
176 | * @param string $message |
||
177 | * @return $this |
||
178 | * @throws \InvalidArgumentException |
||
179 | */ |
||
180 | public function note($message) |
||
184 | |||
185 | /** |
||
186 | * @param string $message |
||
187 | * @return $this |
||
188 | * @throws \InvalidArgumentException |
||
189 | */ |
||
190 | public function caution($message) |
||
194 | |||
195 | /** |
||
196 | * @param string $message |
||
197 | * @return $this |
||
198 | * @throws \InvalidArgumentException |
||
199 | */ |
||
200 | public function success($message) |
||
204 | |||
205 | /** |
||
206 | * @param string $message |
||
207 | * @return $this |
||
208 | * @throws \InvalidArgumentException |
||
209 | */ |
||
210 | public function warning($message) |
||
214 | |||
215 | /** |
||
216 | * @param string $message |
||
217 | * @return $this |
||
218 | * @throws \InvalidArgumentException |
||
219 | */ |
||
220 | public function error($message) |
||
224 | |||
225 | /** |
||
226 | * @param string $message |
||
227 | * @param string $background |
||
228 | * @param string $type |
||
229 | * @param int $length |
||
230 | * @return $this |
||
231 | * @throws \InvalidArgumentException |
||
232 | */ |
||
233 | public function genericBlock($message, $background, $type, $length = 100) |
||
246 | |||
247 | /** |
||
248 | * @param int $lineNumber |
||
249 | * @param string $line |
||
250 | * @param string $coverage |
||
251 | * @throws \InvalidArgumentException |
||
252 | * @return $this |
||
253 | */ |
||
254 | 2 | public function formatUncoveredLine($lineNumber, $line, $coverage = '') |
|
266 | |||
267 | /** |
||
268 | * @param float $coverage |
||
269 | * @param string $namespace |
||
270 | * @return $this |
||
271 | * @throws \InvalidArgumentException |
||
272 | */ |
||
273 | 5 | public function formatCoverage($coverage, $namespace) |
|
290 | |||
291 | /** |
||
292 | * @param int $lineNumber |
||
293 | * @param int|string $lineCoverage |
||
294 | * @param string $line |
||
295 | * @throws \InvalidArgumentException |
||
296 | * @return $this |
||
297 | */ |
||
298 | 1 | public function formatCoveredLine($lineNumber, $lineCoverage, $line) |
|
315 | |||
316 | /** |
||
317 | * @param float $coverage |
||
318 | * @return string |
||
319 | */ |
||
320 | 6 | public function formatCoveragePercent($coverage) |
|
333 | } |
||
334 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: