Conditions | 8 |
Paths | 8 |
Total Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 8 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
15 | 35 | public static function toString( |
|
16 | InputInterface $input, |
||
17 | InputOption $option |
||
18 | ): string { |
||
19 | 35 | $name = $option->getName(); |
|
20 | 35 | $values = $input->getOption($name); |
|
21 | |||
22 | 35 | if (!$option->acceptValue()) { |
|
23 | 6 | return true === $values |
|
24 | 5 | ? \sprintf('--%s', $name) |
|
25 | 6 | : ''; |
|
26 | } |
||
27 | |||
28 | 29 | if (!$option->isArray()) { |
|
29 | 16 | $values = [$values]; |
|
30 | } |
||
31 | |||
32 | 29 | $isValueRequired = $option->isValueRequired(); |
|
33 | /** @var string[] $outputs */ |
||
34 | 29 | $outputs = []; |
|
35 | 29 | foreach ($values as $value) { |
|
|
|||
36 | 29 | if ($isValueRequired && \null === $value) { |
|
37 | 8 | continue; |
|
38 | } |
||
39 | 23 | $value = sprintf( |
|
40 | 23 | '--%s%s%s', |
|
41 | $name, |
||
42 | 23 | \null === $value ? '' : '=', |
|
43 | $value |
||
44 | ); |
||
45 | |||
46 | 23 | $outputs[] = $value; |
|
47 | } |
||
48 | |||
49 | 29 | return \implode(' ', $outputs); |
|
50 | } |
||
51 | } |
||
52 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.