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

TransformerChain::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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