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 Root |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private $directories = array(); |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private $files = array(); |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $basePath; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $basePath |
30
|
|
|
*/ |
31
|
|
|
public function setBasePath($basePath): void |
32
|
|
|
{ |
33
|
|
|
$this->basePath = $basePath; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param File $file |
38
|
|
|
*/ |
39
|
|
|
public function addFile(File $file): void |
40
|
|
|
{ |
41
|
|
|
$this->files[] = $file; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Directory $directory |
46
|
|
|
*/ |
47
|
|
|
public function addDirectory(Directory $directory): void |
48
|
|
|
{ |
49
|
|
|
$this->directories[$directory->getPath()] = $directory; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getBasePath(): string |
56
|
|
|
{ |
57
|
|
|
return $this->basePath; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return File[] |
62
|
|
|
*/ |
63
|
|
|
public function getFileCollection(): array |
64
|
|
|
{ |
65
|
|
|
return $this->files; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getDirectoryCollection(): array |
72
|
|
|
{ |
73
|
|
|
return $this->directories; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $name |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function hasDirectory($name): bool |
82
|
|
|
{ |
83
|
|
|
return isset($this->directories[$name]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $name |
88
|
|
|
* |
89
|
|
|
* @return Directory |
90
|
|
|
*/ |
91
|
|
|
public function getDirectoryByName($name): Directory |
92
|
|
|
{ |
93
|
|
|
return $this->directories[$name]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param Directory $directory |
98
|
|
|
* @return Directory[] |
99
|
|
|
*/ |
100
|
|
|
public function getAllDirIn(Directory $directory): array |
101
|
|
|
{ |
102
|
|
|
$dirCollection = array(); |
|
|
|
|
103
|
|
|
$currentDir = trim($directory->getPath()); |
|
|
|
|
104
|
|
|
|
105
|
|
|
foreach ($this->directories as $path => $dir) { |
106
|
|
|
/* @var $dir Directory */ |
107
|
|
|
if ($currentDir !== '' && |
108
|
|
|
trim($path) !== $currentDir && |
109
|
|
|
strpos(trim($path), $currentDir) === 0 |
110
|
|
|
) { |
111
|
|
|
$dirCollection[] = $dir; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $dirCollection; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.