1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Clover to Html package. |
5
|
|
|
* |
6
|
|
|
* (c) Stéphane Demonchaux <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
namespace CloverToHtml; |
12
|
|
|
|
13
|
|
|
class Directory extends Stats implements StatsInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $path; |
19
|
|
|
/** |
20
|
|
|
* @var File[] |
21
|
|
|
*/ |
22
|
|
|
private $files = array(); |
23
|
|
|
/** |
24
|
|
|
* @var Directory[] |
25
|
|
|
*/ |
26
|
|
|
private $directories = array(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $path |
30
|
|
|
*/ |
31
|
|
|
public function setPath($path) |
32
|
|
|
{ |
33
|
|
|
$this->path = $path; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param File $file |
38
|
|
|
*/ |
39
|
|
|
public function addFile(File $file) |
40
|
|
|
{ |
41
|
|
|
$this->files[] = $file; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Directory $directory |
46
|
|
|
*/ |
47
|
|
|
public function addDirectory(Directory $directory) |
48
|
|
|
{ |
49
|
|
|
$this->directories[] = $directory; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getPath(): string |
56
|
|
|
{ |
57
|
|
|
return $this->path; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getDestination(): string |
64
|
|
|
{ |
65
|
|
|
return $this->path.'index.html'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getBreadcrumb(): array |
72
|
|
|
{ |
73
|
|
|
$paths = array(); |
74
|
|
|
|
75
|
|
|
$pathExploded = explode('/', $this->path); |
76
|
|
|
|
77
|
|
|
foreach ($pathExploded as $number => $dirName) { |
78
|
|
|
if ($number === count($pathExploded) - 1) { |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$repeat = count($pathExploded) - $number - 2; |
83
|
|
|
if ($repeat < 0) { |
84
|
|
|
$repeat = 0; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$paths[] = array( |
88
|
|
|
'link' => str_repeat('../', $repeat) . 'index.html', |
89
|
|
|
'name' => (trim($dirName) === '') ? '.' : $dirName, |
90
|
|
|
'active' => $number === (count($pathExploded) - 2) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $paths; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return File[] |
99
|
|
|
*/ |
100
|
|
|
public function getFileCollection(): array |
101
|
|
|
{ |
102
|
|
|
return $this->files; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return Directory[] |
107
|
|
|
*/ |
108
|
|
|
public function getDirectoryCollection(): array |
109
|
|
|
{ |
110
|
|
|
return $this->directories; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getLink(): string |
117
|
|
|
{ |
118
|
|
|
return $this->getName() . '/index.html'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getName(): string |
125
|
|
|
{ |
126
|
|
|
return basename($this->path); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return number |
131
|
|
|
*/ |
132
|
|
|
public function getLineCount() |
133
|
|
|
{ |
134
|
|
|
return $this->countMagic('getLineCount'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return number |
139
|
|
|
*/ |
140
|
|
|
public function getLineCoverageCount() |
141
|
|
|
{ |
142
|
|
|
return $this->countMagic('getLineCoverageCount'); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return number |
147
|
|
|
*/ |
148
|
|
|
public function getCountClass() |
149
|
|
|
{ |
150
|
|
|
return $this->countMagic('getCountClass'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return number |
155
|
|
|
*/ |
156
|
|
|
public function getMethodCoveredCount() |
157
|
|
|
{ |
158
|
|
|
return $this->countMagic('getMethodCoveredCount'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return number |
163
|
|
|
*/ |
164
|
|
|
public function getMethodCount() |
165
|
|
|
{ |
166
|
|
|
return $this->countMagic('getMethodCount'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $method |
171
|
|
|
* @return number |
172
|
|
|
*/ |
173
|
|
|
private function countMagic($method) |
174
|
|
|
{ |
175
|
|
|
$line = 0; |
176
|
|
|
|
177
|
|
|
foreach ($this->files as $file) { |
178
|
|
|
$line += $file->$method(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $line; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|