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

AbstractResource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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