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

DictionaryDataCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 36
ccs 13
cts 15
cp 0.8667
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A addDictionary() 0 8 1
A reset() 0 2 1
A getDictionaries() 0 4 2
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