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 ( 38eb10...d581fd )
by Anton
02:47
created

IOArguments::collect()   B

Complexity

Conditions 10
Paths 40

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 24
nc 40
nop 2
dl 0
loc 37
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* (c) Anton Medvedev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Deployer\Ssh;
12
13
use Deployer\Exception\Exception;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class IOArguments
18
{
19
    public static function collect(InputInterface $input, OutputInterface $output): array
20
    {
21
        $arguments = [];
22
        foreach ($input->getOptions() as $name => $value) {
23
            if (!$input->getOption($name)) {
24
                continue;
25
            }
26
            if ($name === 'file') {
27
                $arguments[] = "--file";
28
                $arguments[] = ltrim($value, '=');
29
                continue;
30
            }
31
            if (in_array($name, ['verbose'], true)) {
32
                continue;
33
            }
34
            if (!is_array($value)) {
35
                $value = [$value];
36
            }
37
            foreach ($value as $v) {
38
                if (is_bool($v)) {
39
                    $arguments[] = "--$name";
40
                    continue;
41
                }
42
43
                $arguments[] = "--$name";
44
                $arguments[] = $v;
45
            }
46
        }
47
48
        if ($output->isDecorated()) {
49
            $arguments[] = '--decorated';
50
        }
51
        $verbosity = self::verbosity($output->getVerbosity());
52
        if (!empty($verbosity)) {
53
            $arguments[] = $verbosity;
54
        }
55
        return $arguments;
56
    }
57
58
    private static function verbosity(int $verbosity): string
59
    {
60
        switch ($verbosity) {
61
            case OutputInterface::VERBOSITY_QUIET:
62
                return '-q';
63
            case OutputInterface::VERBOSITY_NORMAL:
64
                return '';
65
            case OutputInterface::VERBOSITY_VERBOSE:
66
                return '-v';
67
            case OutputInterface::VERBOSITY_VERY_VERBOSE:
68
                return '-vv';
69
            case OutputInterface::VERBOSITY_DEBUG:
70
                return '-vvv';
71
            default:
72
                throw new Exception('Unknown verbosity level: ' . $verbosity);
73
        }
74
    }
75
}
76