ComposerBinPluginCommand::namespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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