Entry   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Test Coverage

Coverage 60.94%

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 190
ccs 39
cts 64
cp 0.6094
rs 10
c 0
b 0
f 0
wmc 26

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getTitle() 0 3 1
A setTitle() 0 3 1
A isHotPath() 0 2 2
A getParent() 0 3 1
A getUri() 0 3 1
A getPath() 0 3 1
A getFileinfo() 0 3 1
A setName() 0 3 1
A __construct() 0 8 2
A setUri() 0 10 3
A dump() 0 9 1
A getUrl() 0 11 3
A getParents() 0 9 3
A getRelativePath() 0 8 2
A setParent() 0 8 2
1
<?php namespace Todaymade\Daux\Tree;
2
3
use SplFileInfo;
4
5
abstract class Entry
6
{
7
    /** @var string */
8
    protected $title;
9
10
    /** @var string */
11
    protected $name;
12
13
    /** @var string */
14
    protected $uri;
15
16
    /** @var Directory */
17
    protected $parent;
18
19
    /** @var SplFileInfo */
20
    protected $info;
21
22
    /** @var string */
23
    protected $path;
24
25
    /**
26
     * @param Directory $parent
27
     * @param string $uri
28
     * @param SplFileInfo $info
29
     */
30 45
    public function __construct(Directory $parent, $uri, SplFileInfo $info = null)
31
    {
32 45
        $this->setUri($uri);
33 45
        $this->setParent($parent);
34
35 45
        if ($info !== null) {
36 17
            $this->info = $info;
37 17
            $this->path = $info->getPathname();
38
        }
39 45
    }
40
41
    /**
42
     * @return string
43
     */
44 30
    public function getName()
45
    {
46 30
        return $this->name;
47
    }
48
49
    /**
50
     * @param string $name
51
     */
52 34
    public function setName($name)
53
    {
54 34
        $this->name = $name;
55 34
    }
56
57
    /**
58
     * @return string
59
     */
60 45
    public function getUri()
61
    {
62 45
        return $this->uri;
63
    }
64
65
    /**
66
     * @param string $uri
67
     */
68 45
    public function setUri($uri)
69
    {
70 45
        if ($this->parent) {
71
            $this->parent->removeChild($this);
72
        }
73
74 45
        $this->uri = $uri;
75
76 45
        if ($this->parent) {
77
            $this->parent->addChild($this);
78
        }
79 45
    }
80
81
    /**
82
     * @return string
83
     */
84 7
    public function getTitle()
85
    {
86 7
        return $this->title;
87
    }
88
89
    /**
90
     * @param string $title
91
     */
92 23
    public function setTitle($title)
93
    {
94 23
        $this->title = $title;
95 23
    }
96
97
    /**
98
     * @return Directory
99
     */
100 16
    public function getParent()
101
    {
102 16
        return $this->parent;
103
    }
104
105
    /**
106
     * Return all parents starting with the root
107
     *
108
     * @return Directory[]
109
     */
110
    public function getParents()
111
    {
112
        $parents = [];
113
        if ($this->parent && !$this->parent instanceof Root) {
114
            $parents = $this->parent->getParents();
115
            $parents[] = $this->parent;
116
        }
117
118
        return $parents;
119
    }
120
121
    /**
122
     * @param Directory $parent
123
     */
124 45
    protected function setParent(Directory $parent)
125
    {
126 45
        if ($this->parent) {
127
            $this->parent->removeChild($this);
128
        }
129
130 45
        $parent->addChild($this);
131 45
        $this->parent = $parent;
132 45
    }
133
134
    /**
135
     * @return string
136
     */
137 17
    public function getPath()
138
    {
139 17
        return $this->path;
140
    }
141
142
    /**
143
     * Get the path to the file from the root of the documentation
144
     *
145
     * @return string
146
     */
147
    public function getRelativePath()
148
    {
149
        $root = $this;
150
        while ($root->getParent() != null) {
151
            $root = $root->getParent();
152
        }
153
154
        return substr($this->path, strlen($root->getPath()) + 1);
155
    }
156
157
    /**
158
     * @return SplFileInfo
159
     */
160
    public function getFileinfo()
161
    {
162
        return $this->info;
163
    }
164
165
    /**
166
     * @return string
167
     */
168 14
    public function getUrl()
169
    {
170 14
        $url = '';
171
172 14
        if ($this->getParent() && !$this->getParent() instanceof Root) {
173 14
            $url = $this->getParent()->getUrl() . '/' . $url;
174
        }
175
176 14
        $url .= $this->getUri();
177
178 14
        return $url;
179
    }
180
181
    public function dump()
182
    {
183
        return [
184
            'title' => $this->getTitle(),
185
            'type' => get_class($this),
186
            'name' => $this->getName(),
187
            'uri' => $this->getUri(),
188
            'url' => $this->getUrl(),
189
            'path' => $this->path,
190
        ];
191
    }
192
193
    public function isHotPath(Entry $node = null) {
194
        return $this->parent->isHotPath($node ?: $this);
195
    }
196
}
197