Path   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 43
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setPath() 0 4 1
A getPath() 0 7 1
A __toString() 0 3 1
A doInitialize() 0 3 1
A getSegments() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Purl;
6
7
use function array_map;
8
use function explode;
9
use function implode;
10
use function str_replace;
11
12
/**
13
 * Path represents the part of a Url after the domain suffix and before the hashmark (#).
14
 */
15
class Path extends AbstractPart
16
{
17
    /** @var string|null The original path string. */
18
    private $path;
19
20 45
    public function __construct(?string $path = null)
21
    {
22 45
        $this->path = $path;
23 45
    }
24
25 30
    public function getPath() : string
26
    {
27 30
        $this->initialize();
28
29
        return implode('/', array_map(static function ($value) {
30 30
            return str_replace(' ', '%20', $value);
31 30
        }, $this->data));
32
    }
33
34 2
    public function setPath(string $path) : void
35
    {
36 2
        $this->initialized = false;
37 2
        $this->path        = $path;
38 2
    }
39
40
    /**
41
     * @return mixed[]
42
     */
43 1
    public function getSegments() : array
44
    {
45 1
        $this->initialize();
46
47 1
        return $this->data;
48
    }
49
50 28
    public function __toString() : string
51
    {
52 28
        return $this->getPath();
53
    }
54
55 31
    protected function doInitialize() : void
56
    {
57 31
        $this->data = explode('/', (string) $this->path);
58 31
    }
59
}
60