Completed
Push — master ( 47b302...9a1097 )
by Nate
02:18
created

AbstractTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIncludes() 0 4 1
A item() 0 4 1
A collection() 0 4 1
A __invoke() 0 4 1
1
<?php
2
3
/**
4
 * @package   Transform
5
 * @author    Flipbox Factory
6
 * @copyright Copyright (c) 2017, Flipbox Digital
7
 * @link      https://github.com/flipbox/transform/releases/latest
8
 * @license   https://github.com/flipbox/transform/blob/master/LICENSE
9
 */
10
11
namespace flipbox\transform\transformers;
12
13
use flipbox\transform\helpers\Object as ObjectHelper;
14
use flipbox\transform\Scope;
15
16
/**
17
 * @package flipbox\transform\transformers
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
abstract class AbstractTransformer implements TransformerInterface
22
{
23
24
    /**
25
     * @param array $config
26
     */
27
    public function __construct(array $config = [])
28
    {
29
        ObjectHelper::configure($this, $config);
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function getIncludes(): array
36
    {
37
        return [];
38
    }
39
40
    /**
41
     * @param mixed $data
42
     * @param TransformerInterface|callable $transformer
43
     * @return Item
44
     */
45
    protected function item($data, $transformer): Item
46
    {
47
        return new Item(['data' => $data, 'transformer' => $transformer]);
48
    }
49
50
    /**
51
     * @param mixed $data
52
     * @param TransformerInterface|callable $transformer
53
     * @return Collection
54
     */
55
    protected function collection($data, $transformer): Collection
56
    {
57
        return new Collection(['data' => $data, 'transformer' => $transformer]);
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function __invoke($data, Scope $scope, string $identifier = null)
64
    {
65
        return $this->transform($data, $scope, $identifier);
66
    }
67
68
}
69