Option   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B toString() 0 36 8
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) {
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