Completed
Push — master ( 552cf0...ff5a3f )
by Саша
02:06
created

TransformerChain::transform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 4
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