Completed
Push — master ( 9a1097...9d1cce )
by Nate
04:06
created

AbstractTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 46
ccs 0
cts 20
cp 0
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
 * @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\Object as ObjectHelper;
13
use Flipbox\Transform\Scope;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
abstract class AbstractTransformer implements TransformerInterface
20
{
21
    /**
22
     * @param array $config
23
     */
24
    public function __construct(array $config = [])
25
    {
26
        ObjectHelper::configure($this, $config);
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getIncludes(): array
33
    {
34
        return [];
35
    }
36
37
    /**
38
     * @param mixed $data
39
     * @param TransformerInterface|callable $transformer
40
     * @return Item
41
     */
42
    protected function item($data, $transformer): Item
43
    {
44
        return new Item(['data' => $data, 'transformer' => $transformer]);
45
    }
46
47
    /**
48
     * @param mixed $data
49
     * @param TransformerInterface|callable $transformer
50
     * @return Collection
51
     */
52
    protected function collection($data, $transformer): Collection
53
    {
54
        return new Collection(['data' => $data, 'transformer' => $transformer]);
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function __invoke($data, Scope $scope, string $identifier = null)
61
    {
62
        return $this->transform($data, $scope, $identifier);
63
    }
64
}
65