Path::back()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Lneicelis\Transformer\ValueObject;
4
5
class Path
6
{
7
    /** @var string[] */
8
    private $segments;
9
10 19
    public function __construct(array $segments = [])
11
    {
12 19
        $this->segments = $segments;
13 19
    }
14
15
    public function isInRoot(): bool
16
    {
17
        return empty($this->segments);
18
    }
19
20 8
    public function stepIn(string $segment): Path
21
    {
22 8
        return new Path(array_merge($this->segments, [$segment]));
23
    }
24
25
    public function back(): Path
26
    {
27
        return new Path(array_slice($this->segments, 0, count($this->segments) - 1));
28
    }
29
30 9
    public function getSegments(): array
31
    {
32 9
        return $this->segments;
33
    }
34
35 2
    public function __toString()
36
    {
37 2
        return implode('.', $this->segments);
38
    }
39
}
40