Entry   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Test Coverage

Coverage 60.94%

Importance

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

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 1
A isHotPath() 0 2 2
A getParent() 0 3 1
A getUri() 0 3 1
A dump() 0 9 1
A setParent() 0 8 2
A __construct() 0 8 2
A getName() 0 3 1
A setTitle() 0 3 1
A setUri() 0 10 3
A getUrl() 0 11 3
A getPath() 0 3 1
A getParents() 0 9 3
A getRelativePath() 0 8 2
A getFileinfo() 0 3 1
A setName() 0 3 1
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 49
    public function __construct(Directory $parent, $uri, SplFileInfo $info = null)
31
    {
32 49
        $this->setUri($uri);
33 49
        $this->setParent($parent);
34
35 49
        if ($info !== null) {
36 20
            $this->info = $info;
37 20
            $this->path = $info->getPathname();
38
        }
39 49
    }
40
41
    /**
42
     * @return string
43
     */
44 33
    public function getName()
45
    {
46 33
        return $this->name;
47
    }
48
49
    /**
50
     * @param string $name
51
     */
52 38
    public function setName($name)
53
    {
54 38
        $this->name = $name;
55 38
    }
56
57
    /**
58
     * @return string
59
     */
60 49
    public function getUri()
61
    {
62 49
        return $this->uri;
63
    }
64
65
    /**
66
     * @param string $uri
67
     */
68 49
    public function setUri($uri)
69
    {
70 49
        if ($this->parent) {
71
            $this->parent->removeChild($this);
72
        }
73
74 49
        $this->uri = $uri;
75
76 49
        if ($this->parent) {
77
            $this->parent->addChild($this);
78
        }
79 49
    }
80
81
    /**
82
     * @return string
83
     */
84 8
    public function getTitle()
85
    {
86 8
        return $this->title;
87
    }
88
89
    /**
90
     * @param string $title
91
     */
92 27
    public function setTitle($title)
93
    {
94 27
        $this->title = $title;
95 27
    }
96
97
    /**
98
     * @return Directory
99
     */
100 20
    public function getParent()
101
    {
102 20
        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 49
    protected function setParent(Directory $parent)
125
    {
126 49
        if ($this->parent) {
127
            $this->parent->removeChild($this);
128
        }
129
130 49
        $parent->addChild($this);
131 49
        $this->parent = $parent;
132 49
    }
133
134
    /**
135
     * @return string
136
     */
137 20
    public function getPath()
138
    {
139 20
        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 18
    public function getUrl()
169
    {
170 18
        $url = '';
171
172 18
        if ($this->getParent() && !$this->getParent() instanceof Root) {
173 18
            $url = $this->getParent()->getUrl() . '/' . $url;
174
        }
175
176 18
        $url .= $this->getUri();
177
178 18
        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