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

AbstractResource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
transform() 0 1 ?
A __construct() 0 5 1
A getParams() 0 4 1
A __invoke() 0 7 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\Resources;
11
12
use Flipbox\Transform\Helpers\Object as ObjectHelper;
13
use Flipbox\Transform\ParamBag;
14
use Flipbox\Transform\Scope;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
abstract class AbstractResource implements ResourceInterface
21
{
22
    /**
23
     * @var Scope
24
     */
25
    protected $scope;
26
27
    /**
28
     * @param callable $transformer
29
     * @param $data
30
     * @return null|array
31
     */
32
    abstract public function transform(callable $transformer, $data);
33
34
    /**
35
     * @param Scope $scope
36
     * @param array $config
37
     */
38
    public function __construct(Scope $scope, array $config = [])
39
    {
40
        $this->scope = $scope;
41
        ObjectHelper::configure($this, $config);
42
    }
43
44
    /**
45
     * @return ParamBag
46
     */
47
    protected function getParams(): ParamBag
48
    {
49
        return $this->scope->getParams();
50
    }
51
52
    /**
53
     * @param $data
54
     * @param callable $transformer
55
     * @return array|null
56
     */
57
    public function __invoke($data, callable $transformer)
58
    {
59
        return $this->transform(
60
            $transformer,
61
            $data
62
        );
63
    }
64
}
65