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

Directory::countMagic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
crap 6
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()
56
    {
57
        return $this->path;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getDestination()
64
    {
65
        return $this->path.'index.html';
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function getBreadcrumb()
72
    {
73
        $paths = array();
74
75
        $pathExploded = explode('/', $this->path);
76
77
        foreach ($pathExploded as $number => $dirName) {
78
            $paths[] = array(
79
                'link' => str_repeat('../', $number + 1) . 'index.html',
80
                'name' => ($dirName == '') ? 'Home' : $dirName,
81
                'active' => ($number == count($pathExploded) - 1)
82
            );
83
        }
84
85
        return $paths;
86
    }
87
88
    /**
89
     * @return File[]
90
     */
91
    public function getFileCollection()
92
    {
93
        return $this->files;
94
    }
95
96
    /**
97
     * @return Directory[]
98
     */
99
    public function getDirectoryCollection()
100
    {
101
        return $this->directories;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getLink()
108
    {
109
        return $this->getName() . '/index.html';
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getName()
116
    {
117
        return basename($this->path);
118
    }
119
120
    /**
121
     * @return number
122
     */
123
    public function getLineCount()
124
    {
125
        return $this->countMagic('getLineCount');
126
    }
127
128
    /**
129
     * @return number
130
     */
131
    public function getLineCoverageCount()
132
    {
133
        return $this->countMagic('getLineCoverageCount');
134
    }
135
136
    /**
137
     * @return number
138
     */
139
    public function getCountClass()
140
    {
141
        return $this->countMagic('getCountClass');
142
    }
143
144
    /**
145
     * @return number
146
     */
147
    public function getMethodCoveredCount()
148
    {
149
        return $this->countMagic('getMethodCoveredCount');
150
    }
151
152
    /**
153
     * @return number
154
     */
155
    public function getMethodCount()
156
    {
157
        return $this->countMagic('getMethodCount');
158
    }
159
160
    /**
161
     * @param string $method
162
     * @return number
163
     */
164
    private function countMagic($method)
165
    {
166
        $line = 0;
167
168
        foreach ($this->files as $file) {
169
            $line += $file->$method();
170
        }
171
172
        return $line;
173
    }
174
}
175