Passed
Branch master (7b18cd)
by Jakub
03:40
created

ComposerGlobalMultiInstallCommand::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Tool\Command;
4
5
use InvalidArgumentException;
6
use Zalas\Toolbox\Tool\Collection;
7
use Zalas\Toolbox\Tool\Command;
8
9
final class ComposerGlobalMultiInstallCommand implements Command
10
{
11
    private $commands;
12
13 4
    public function __construct(Collection $commands)
14
    {
15 4
        if ($commands->empty()) {
16 1
            throw new InvalidArgumentException('Collection of composer global install commands cannot be empty.');
17
        }
18
19 3
        $this->commands = $commands->filter(function (ComposerGlobalInstallCommand $c) {
20 3
            return $c;
21 3
        });
22
    }
23
24 2
    public function __toString(): string
25
    {
26 2
        $packages = \implode(' ', \array_map(function (ComposerGlobalInstallCommand $command) {
27 2
            return $command->package();
28 2
        }, $this->commands->toArray()));
29
30 2
        return \sprintf('composer global require --no-suggest --prefer-dist --update-no-dev -n %s', $packages);
31
    }
32
}
33