AbstractTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 21.43%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 42
ccs 3
cts 14
cp 0.2143
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A item() 0 10 1
A collection() 0 8 2
1
<?php
2
3
/**
4
 * @author    Flipbox Factory
5
 * @copyright Copyright (c) 2017, Flipbox Digital
6
 * @link      https://github.com/flipbox/transform/releases/latest
7
 * @license   https://github.com/flipbox/transform/blob/master/LICENSE
8
 */
9
10
namespace Flipbox\Transform\Transformers;
11
12
use Flipbox\Transform\Helpers\ObjectHelper;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 3.0.0
17
 */
18
abstract class AbstractTransformer
19
{
20
    /**
21
     * @param array $config
22
     */
23 18
    public function __construct(array $config = [])
24
    {
25 18
        ObjectHelper::configure($this, $config);
26 18
    }
27
28
    /**
29
     * @param mixed $data
30
     * @param callable $transformer
31
     * @param array $extra
32
     * @return mixed
33
     */
34
    protected function item($data, callable $transformer, array $extra = [])
35
    {
36
        return call_user_func_array(
37
            $transformer,
38
            array_merge(
39
                [$data],
40
                $extra
41
            )
42
        );
43
    }
44
45
    /**
46
     * @param mixed $data
47
     * @param callable $transformer
48
     * @param array $extra
49
     * @return mixed
50
     */
51
    protected function collection($data, callable $transformer, array $extra = [])
52
    {
53
        $items = [];
54
        foreach ($data as $item) {
55
            $items[] = $this->item($item, $transformer, $extra);
56
        }
57
        return $items;
58
    }
59
}
60