Combined::supports()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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