These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types=1); |
||
2 | /* (c) Anton Medvedev <[email protected]> |
||
3 | * |
||
4 | * For the full copyright and license information, please view the LICENSE |
||
5 | * file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace Deployer\Console\Input; |
||
9 | |||
10 | use Symfony\Component\Console\Input\InputInterface; |
||
11 | use Symfony\Component\Console\Input\InputOption; |
||
12 | |||
13 | final class Option |
||
14 | { |
||
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) { |
|
0 ignored issues
–
show
|
|||
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.