Path   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A stringify() 0 4 1
A __toString() 0 4 1
A fromString() 0 4 1
A join() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of cloak.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace cloak\value;
13
14
use Eloquent\Pathogen\Factory\PathFactory;
15
use Eloquent\Pathogen\RelativePath;
16
17
18
/**
19
 * Class Path
20
 * @package cloak\value
21
 */
22
final class Path
23
{
24
25
    /**
26
     * @var \Eloquent\Pathogen\PathInterface
27
     */
28
    private $rootPath;
29
30
31
    /**
32
     * @param string $path
33
     */
34
    public function __construct($path)
35
    {
36
        $this->rootPath = PathFactory::instance()->create($path);
37
    }
38
39
    /**
40
     * @param string $path
41
     */
42
    public function join($path)
43
    {
44
        $relativePath = RelativePath::fromString($path);
45
46
        $resultPath = $this->rootPath->join($relativePath);
47
        $newRootPath = $resultPath->normalize()->string();
48
49
        return Path::fromString($newRootPath);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function stringify()
56
    {
57
        return $this->rootPath->normalize()->string();
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function __toString()
64
    {
65
        return $this->stringify();
66
    }
67
68
    /**
69
     * @param string $path
70
     * @return Path
71
     */
72
    public static function fromString($path)
73
    {
74
        return new self($path);
75
    }
76
77
}
78