DataTransformer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 28
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 9 3
A transform() 0 9 3
A __construct() 0 4 1
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