Passed
Push — master ( 414f0a...c0888e )
by Pierre
03:03
created

DictionaryDataCollector::addDictionary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\DataCollector;
6
7
use Generator;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9
10
final class DictionaryDataCollector extends DataCollector
11
{
12 1
    use DictionaryDataCollector\SymfonyCompatibilityTrait;
13
14
    /**
15
     * @param array<mixed> $keys
16
     * @param array<mixed> $values
17
     */
18 9
    public function addDictionary(string $name, array $keys, array $values): void
19
    {
20 9
        $this->data[$name] = array_map(
21 9
            function ($key, $value): array {
22 9
                return ['key' => $key, 'value' => $value];
23 9
            },
24
            $keys,
25
            $values
26
        );
27 9
    }
28
29
    /**
30
     * @return Generator<string, array>
31
     */
32 9
    public function getDictionaries(): Generator
33
    {
34 9
        foreach ($this->data as $name => $keyValuePairs) {
35 8
            yield $name => $keyValuePairs;
36
        }
37 9
    }
38
39
    public function reset(): void
40
    {
41
    }
42
43 1
    public function getName()
44
    {
45 1
        return 'dictionary';
46
    }
47
}
48