Aggregate::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

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