Completed
Push — master ( b5fb47...8bb9d4 )
by Nate
02:22
created

AbstractTransform::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Transform;
11
12
use Flipbox\Transform\Helpers\Object as ObjectHelper;
13
use Flipbox\Transform\ParamBag;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
abstract class AbstractTransform implements TransformInterface
20
{
21
    /**
22
     * The character used to separate modifier parameters.
23
     *
24
     * @var string
25
     */
26
    public $paramDelimiter = '|';
27
28
    /**
29
     * Upper limit to how many levels of included data are allowed.
30
     *
31
     * @var int
32
     */
33
    public $recursionLimit = 10;
34
35
    /**
36
     * Array containing modifiers as keys and an array value of params.
37
     *
38
     * @var array
39
     */
40
    protected $params = [];
41
42
    /**
43
     * @param array $config
44
     */
45
    public function __construct(array $config = [])
46
    {
47
        ObjectHelper::configure($this, $config);
48
    }
49
50
    /**
51
     * @param string $include
52
     *
53
     * @return ParamBag
54
     */
55
    public function getParams($include): ParamBag
56
    {
57
        $params = isset($this->params[$include]) ? $this->params[$include] : [];
58
        return new ParamBag($params);
59
    }
60
61
    /**
62
     * Trim to Acceptable Recursion Level
63
     *
64
     * @param string $includeName
65
     *
66
     * @return string
67
     */
68
    protected function trimToAcceptableRecursionLevel($includeName)
69
    {
70
        return implode('.', array_slice(explode('.', $includeName), 0, $this->recursionLimit));
71
    }
72
}
73