Aggregate   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 32
ccs 12
cts 13
cp 0.9231
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 9 3
A addTransformer() 0 3 1
A transform() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\ValueTransformer;
6
7
use Knp\DictionaryBundle\ValueTransformer;
8
9
final class Aggregate implements ValueTransformer
10
{
11
    /**
12
     * @var array<ValueTransformer>
13
     */
14
    private array $transformers = [];
15
16 2
    public function addTransformer(ValueTransformer $valueTransformer): void
17
    {
18 2
        $this->transformers[] = $valueTransformer;
19 2
    }
20
21 1
    public function supports(mixed $value): bool
22
    {
23 1
        foreach ($this->transformers as $transformer) {
24 1
            if ($transformer->supports($value)) {
25 1
                return true;
26
            }
27
        }
28
29 1
        return false;
30
    }
31
32 1
    public function transform(mixed $value)
33
    {
34 1
        foreach ($this->transformers as $transformer) {
35 1
            if ($transformer->supports($value)) {
36 1
                return $transformer->transform($value);
37
            }
38
        }
39
40
        return $value;
41
    }
42
}
43