GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 9ce3f7...9fd858 )
by Anton
03:51
created

src/Console/Input/Option.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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
The expression $values of type string|array<integer,str...string>|boolean|null"}> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. 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:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
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