TransformerChain::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Extraload\Transformer;
4
5
class TransformerChain implements TransformerInterface
6
{
7
    private $transformers;
8
9
    public function __construct(array $transformers)
10
    {
11
        foreach ($transformers as $transformer) {
12
            if ($transformer instanceof TransformerInterface) {
13
                continue;
14
            }
15
16
            throw new \InvalidArgumentException(
17
                'All transformers in the chain should implement TransformerInterface.'
18
            );
19
        }
20
21
        $this->transformers = $transformers;
22
    }
23
24
    public function transform($data)
25
    {
26
        foreach ($this->transformers as $transformer) {
27
            $data = $transformer->transform($data);
28
        }
29
30
        return $data;
31
    }
32
}
33