Completed
Push — master ( 198b3f...28f717 )
by Nate
02:18
created

AbstractResourceTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
createResource() 0 1 ?
A transform() 0 13 1
A setTransformer() 0 5 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\resources\ResourceInterface;
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 AbstractResourceTransformer extends AbstractTransformer
22
{
23
24
    /**
25
     * @var mixed
26
     */
27
    public $data;
28
29
    /**
30
     * @var callable|TransformerInterface
31
     */
32
    protected $transformer;
33
34
    /**
35
     * @param Scope $scope
36
     * @return ResourceInterface
37
     */
38
    protected abstract function createResource(Scope $scope): ResourceInterface;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
39
40
    /**
41
     * @param Scope $scope
42
     * @param string|null $identifier
43
     * @return mixed
44
     */
45
    public function transform(Scope $scope, string $identifier = null)
46
    {
47
48
        $resource = $this->createResource(
49
            $scope->childScope($identifier)
50
        );
51
52
        return $resource->transform(
53
            $this->transformer,
54
            $this->data
55
        );
56
57
    }
58
59
    /**
60
     * @param callable $transformer
61
     * @return $this
62
     */
63
    public function setTransformer(callable $transformer)
64
    {
65
        $this->transformer = $transformer;
66
        return $this;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function __invoke($data, Scope $scope, string $identifier = null)
73
    {
74
        return $this->transform($scope, $identifier);
75
    }
76
77
}