Combined   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 29
ccs 7
cts 10
cp 0.7
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 2
A supports() 0 3 2
A __construct() 0 1 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\Dictionary\Factory;
6
7
use Knp\DictionaryBundle\Dictionary;
8
use Knp\DictionaryBundle\Dictionary\Collection;
9
use Knp\DictionaryBundle\Dictionary\Factory;
10
11
final class Combined implements Factory
12
{
13
    /**
14
     * @var string
15
     */
16
    private const TYPE = 'combined';
17
18
    public function __construct(private Collection $collection) {}
19
20
    public function create(string $name, array $config): Dictionary
21
    {
22
        if (!isset($config['dictionaries'])) {
23
            throw new \InvalidArgumentException(\sprintf(
24 4
                'Dictionary of type %s must contains a key "dictionaries".',
25
                self::TYPE
26 4
            ));
27 4
        }
28
29 1
        $dictionaries = array_map(
30
            fn ($name): Dictionary => $this->collection[$name],
31 1
            $config['dictionaries']
32
        );
33
34
        return new Dictionary\Combined($name, ...$dictionaries);
35
    }
36
37
    public function supports(array $config): bool
38 1
    {
39 1
        return isset($config['type']) && self::TYPE === $config['type'];
40 1
    }
41
}
42