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

ComposerGlobalMultiInstallCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 7 1
A __construct() 0 8 2
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