Path::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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