PathBuilder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 109
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 5 1
A setDepth() 0 3 1
A __construct() 0 4 1
A setLength() 0 3 1
A setCharPad() 0 3 1
A string() 0 7 1
A generate() 0 3 1
A setTypePad() 0 3 1
1
<?php
2
3
namespace Bavix\SDK;
4
5
use Bavix\Foundation\SharedInstance;
6
use Bavix\Helpers\Arr;
7
use Bavix\Helpers\Str;
8
9
class PathBuilder
10
{
11
12
    use SharedInstance;
13
14
    /**
15
     * @var int
16
     */
17
    protected $depth = 2;
18
19
    /**
20
     * @var int
21
     */
22
    protected $length = 2;
23
24
    /**
25
     * @var string
26
     */
27
    protected $charPad = '0';
28
29
    /**
30
     * @var int
31
     */
32
    protected $typePad = STR_PAD_RIGHT;
33
34
    /**
35
     * PathBuilder constructor.
36
     *
37
     * @param int $length
38
     * @param int $depth
39
     */
40 7
    public function __construct($length = 2, $depth = 2)
41
    {
42 7
        $this->length = $length;
43 7
        $this->depth  = $depth;
44 7
    }
45
46
    /**
47
     * @param string $data
48
     *
49
     * @return string
50
     */
51 7
    protected function string($data)
52
    {
53 7
        return \str_pad(
54 7
            $data,
55 7
            $this->depth * $this->length,
56 7
            $this->charPad,
57 7
            $this->typePad
58
        );
59
    }
60
61
    /**
62
     * @param int $data
63
     */
64 4
    public function setLength($data)
65
    {
66 4
        $this->length = $data;
67 4
    }
68
69
    /**
70
     * @param int $data
71
     */
72 1
    public function setDepth($data)
73
    {
74 1
        $this->depth = $data;
75 1
    }
76
77
    /**
78
     * @param string $data
79
     */
80 3
    public function setCharPad($data)
81
    {
82 3
        $this->charPad = $data;
83 3
    }
84
85
    /**
86
     * @param int $data
87
     */
88 2
    public function setTypePad($data)
89
    {
90 2
        $this->typePad = $data;
91 2
    }
92
93
    /**
94
     * @param string $string
95
     *
96
     * @return array
97
     */
98 7
    public function hash($string)
99
    {
100 7
        return implode('/', Arr::slice(
101 7
            Str::split($this->string($string), $this->length),
102 7
            0, $this->depth
103
        ));
104
    }
105
106
    /**
107
     * <type>(/<config>)/<hash>{s1}/<hash>{s2}/<hash>
108
     *
109
     * @param string $type
110
     * @param string $hash
111
     * @param string $config
112
     *
113
     * @return string
114
     */
115 6
    public function generate($type, $config, $hash)
116
    {
117 6
        return $type . '/' . $config . '/' . $this->hash($hash) . '/' . $hash;
0 ignored issues
show
Bug introduced by
Are you sure $this->hash($hash) of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        return $type . '/' . $config . '/' . /** @scrutinizer ignore-type */ $this->hash($hash) . '/' . $hash;
Loading history...
118
    }
119
120
}
121