Completed
Push — master ( 83f315...077de2 )
by Demonchaux
02:12
created

Root::getAllDirIn()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 8.8571
cc 5
eloc 8
nc 3
nop 1
crap 30
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)
32
    {
33
        $this->basePath = $basePath;
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->getPath()] = $directory;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getBasePath()
56
    {
57
        return $this->basePath;
58
    }
59
60
    /**
61
     * @return File[]
62
     */
63
    public function getFileCollection()
64
    {
65
        return $this->files;
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function getDirectoryCollection()
72
    {
73
        return $this->directories;
74
    }
75
76
    /**
77
     * @param string $name
78
     *
79
     * @return bool
80
     */
81
    public function hasDirectory($name)
82
    {
83
        return isset($this->directories[$name]);
84
    }
85
86
    /**
87
     * @param string $name
88
     *
89
     * @return Directory
90
     */
91
    public function getDirectoryByName($name)
92
    {
93
        return $this->directories[$name];
94
    }
95
96
    /**
97
     * @param Directory $name
98
     * @return Directory[]
99
     */
100
    public function getAllDirIn(Directory $dir)
101
    {
102
        $dirCollection = array();
103
        $name          = $dir->getName();
104
105
        foreach ($this->directories as $dir) {
106
            /* @var $dir Directory */
107
            if (strlen($name) === 0 ||
108
                (substr($dir->getName(), 0, strlen($name)) === $name) && strlen($dir->getName()) > strlen($name)) {
109
                $dirCollection[] = $dir;
110
            }
111
        }
112
113
        return $dirCollection;
114
    }
115
}
116