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.

Cli::parseParameters()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.2888
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the "php-ipfs" package.
7
 *
8
 * (c) Robert Schönthal <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace IPFS\Driver;
15
16
use IPFS\Command\Command;
17
use IPFS\Utils\AnnotationReader;
18
use IPFS\Utils\CaseFormatter;
19
use Symfony\Component\Process\Process;
20
21
class Cli implements Driver
22
{
23
    /**
24
     * @var Process
25
     */
26
    private $builder;
27
    /**
28
     * @var string
29
     */
30
    private $binary;
31
    /**
32
     * @var AnnotationReader
33
     */
34
    private $reader;
35
36 2
    public function __construct(Process $builder, AnnotationReader $reader, $binary = 'ipfs')
37
    {
38 2
        $this->builder = $builder;
39 2
        $this->binary = $binary;
40 2
        $this->reader = $reader;
41 2
    }
42
43 1
    public function execute(Command $command)
44
    {
45
        //SYMFONY 3.2 compat
46 1
        $script = implode(' ', array_map(['\\Symfony\\Component\\Process\\ProcessUtils', 'escapeArgument'], $this->buildCommand($command)));
47
48 1
        $process = $this->builder
49 1
            ->setCommandLine($script)
50 1
            ->enableOutput()
51 1
            ->inheritEnvironmentVariables()
52 1
            ->setWorkingDirectory(getenv('CWD'))
53
        ;
54
55 1
        $process->start();
56 1
        $process->wait();
57
58 1
        return $process->getOutput() ?: $process->getErrorOutput();
59
    }
60
61 1
    private function buildCommand(Command $command): array
62
    {
63 1
        return array_merge(
64 1
            [$this->binary],
65 1
            explode(':', $command->getAction()),
66 1
            $this->parseParameters($command)
67
        );
68
    }
69
70 1
    private function parseParameters(Command $command): array
71
    {
72 1
        $parameters = $this->reader->getParameters($command->getMethod());
73
74 1
        $parsedParameters = [];
75
76 1
        foreach ($command->getArguments() as $name => $value) {
77 1
            if ($parameters[$name]->hasDefault() && $parameters[$name]->getDefault() !== $value) {
78 1
                $parsedParameters[] = sprintf('--%s=%s', CaseFormatter::camelToDash($name), var_export($value, true));
79 1
                continue;
80
            }
81
82 1
            if (!$parameters[$name]->hasDefault()) {
83 1
                $parsedParameters[] = $value;
84 1
                continue;
85
            }
86
        }
87
88 1
        return $parsedParameters;
89
    }
90
}
91