DataTransformer::supports()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Grid\DataTransformer;
6
7
use LAG\AdminBundle\Metadata\Property\PropertyInterface;
8
9
class DataTransformer implements DataTransformerInterface
10
{
11
    public function __construct(
12
        /** @var iterable<DataTransformerInterface> $transformers */
13
        private iterable $transformers
14
    ) {
15
    }
16
17
    public function supports(PropertyInterface $property, mixed $data): bool
18
    {
19
        foreach ($this->transformers as $transformer) {
20
            if ($transformer->supports($property, $data)) {
21
                return true;
22
            }
23
        }
24
25
        return false;
26
    }
27
28
    public function transform(PropertyInterface $property, mixed $data): mixed
29
    {
30
        foreach ($this->transformers as $transformer) {
31
            if ($transformer->supports($property, $data)) {
32
                return $transformer->transform($property, $data);
33
            }
34
        }
35
36
        return $data;
37
    }
38
}
39