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

AbstractTransformer::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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