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

AbstractResource::transform()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 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\resources;
12
13
use flipbox\transform\helpers\Object as ObjectHelper;
14
use flipbox\transform\ParamBag;
15
use flipbox\transform\Scope;
16
17
/**
18
 * @package flipbox\transform\resources
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
abstract class AbstractResource implements ResourceInterface
23
{
24
25
    /**
26
     * @var Scope
27
     */
28
    protected $scope;
29
30
    /**
31
     * @param callable $transformer
32
     * @param $data
33
     * @return null|array
34
     */
35
    public abstract function transform(callable $transformer, $data);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
36
37
    /**
38
     * @param Scope $scope
39
     * @param array $config
40
     */
41
    public function __construct(Scope $scope, array $config = [])
42
    {
43
        $this->scope = $scope;
44
        ObjectHelper::configure($this, $config);
45
    }
46
47
    /**
48
     * @return ParamBag
49
     */
50
    protected function getParams(): ParamBag
51
    {
52
        return $this->scope->getParams();
53
    }
54
55
    /**
56
     * @param $data
57
     * @param callable $transformer
58
     * @return array|null
59
     */
60
    public function __invoke($data, callable $transformer)
61
    {
62
        return $this->transform(
63
            $transformer,
64
            $data
65
        );
66
    }
67
68
}
69