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

TransformerChain   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 28
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A transform() 0 8 2
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