Passed
Pull Request — master (#73)
by Jakub
03:51
created

ComposerBinPluginCommandFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A importLinks() 0 9 1
A import() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Json\Factory;
4
5
use Zalas\Toolbox\Tool\Collection;
6
use Zalas\Toolbox\Tool\Command;
7
use Zalas\Toolbox\Tool\Command\ComposerBinPluginCommand;
8
use Zalas\Toolbox\Tool\Command\ComposerBinPluginLinkCommand;
9
10
final class ComposerBinPluginCommandFactory
11
{
12 10
    public static function import(array $command): Command
13
    {
14 10
        Assert::requireFields(['package', 'namespace'], $command, 'ComposerBinPluginCommand');
15
16 8
        return new ComposerBinPluginCommand($command['package'], $command['namespace'], self::importLinks($command));
17
    }
18
19 8
    private static function importLinks(array $command): Collection
20
    {
21 8
        $links = $command['links'] ?? [];
22 8
        $namespace = $command['namespace'];
23
24 8
        return Collection::create(
25
            \array_map(function (string $source, string $target) use ($namespace) {
26 1
                return new ComposerBinPluginLinkCommand($source, $target, $namespace);
27 8
            }, \array_values($links), \array_keys($links))
28
        );
29
    }
30
}
31