ComposerBinPluginCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 39
ccs 15
cts 15
cp 1
c 0
b 0
f 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A links() 0 3 1
A namespace() 0 3 1
A package() 0 3 1
A __toString() 0 3 1
A linkCommand() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Tool\Command;
4
5
use Zalas\Toolbox\Tool\Collection;
6
use Zalas\Toolbox\Tool\Command;
7
8
final class ComposerBinPluginCommand implements Command
9
{
10
    private string $package;
11
12
    private string $namespace;
13
14
    private Collection $links;
15
16 18
    public function __construct(string $package, string $namespace, Collection $links)
17
    {
18 18
        $this->package = $package;
19 18
        $this->namespace = $namespace;
20 18
        $this->links = $links;
21
    }
22
23 3
    public function __toString(): string
24
    {
25 3
        return \sprintf('composer global bin %s require --prefer-dist --update-no-dev -n %s%s', $this->namespace, $this->package, $this->linkCommand());
26
    }
27
28 6
    public function package(): string
29
    {
30 6
        return $this->package;
31
    }
32
33 6
    public function namespace(): string
34
    {
35 6
        return $this->namespace;
36
    }
37
38 7
    public function links(): Collection
39
    {
40 7
        return $this->links;
41
    }
42
43 3
    private function linkCommand(): string
44
    {
45 3
        return $this->links->reduce('', function (string $command, ComposerBinPluginLinkCommand $link) {
46 1
            return $command.' && '.$link;
47 3
        });
48
    }
49
}
50