Total Complexity | 7 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 92.31% |
Changes | 0 |
1 | <?php |
||
10 | class ResponseTransform implements ResponseTransformInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $transformers; |
||
16 | |||
17 | /** |
||
18 | * ResponseTransformer constructor. |
||
19 | * |
||
20 | * @param array $transformers |
||
21 | */ |
||
22 | 3 | public function __construct(array $transformers = []) |
|
23 | { |
||
24 | 3 | $this->transformers = $transformers; |
|
25 | 3 | } |
|
26 | |||
27 | /** |
||
28 | * It is possible to handle the Response data defining the Config key response_transformers |
||
29 | * with an instance of Closure or an instance of TransformerInterface. |
||
30 | * |
||
31 | * @param ResponseInterface $data |
||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | 2 | public function transform(ResponseInterface $data) |
|
36 | { |
||
37 | 2 | foreach ($this->transformers as $transformer) { |
|
38 | 2 | $this->applyResponseTransformer($transformer, $data); |
|
39 | } |
||
40 | 2 | } |
|
41 | |||
42 | /** |
||
43 | * Applied single response transformer |
||
44 | * |
||
45 | * @param ResponseTransformerInterface|\Closure $transformer |
||
46 | * @param ResponseInterface $data |
||
47 | */ |
||
48 | 2 | protected function applyResponseTransformer($transformer, ResponseInterface $data) |
|
57 | } |
||
58 | 2 | } |
|
59 | } |
||
60 |