Passed
Pull Request — master (#149)
by Pierre
03:06
created

Aggregate::supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

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 5
cts 5
cp 1
crap 3
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 ValueTransformer[]
13
     */
14
    private $transformers = [];
15
16 2
    public function addTransformer(ValueTransformer $transformer): void
17
    {
18 2
        $this->transformers[] = $transformer;
19 2
    }
20
21 1
    public function supports($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($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