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

File::getLineCoverageCount()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4286
cc 3
eloc 6
nc 3
nop 0
crap 12
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 File extends Stats implements StatsInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
    /**
20
     * @var array
21
     */
22
    private $class = array();
23
    /**
24
     * @var array
25
     */
26
    private $lines = array();
27
28
    /**
29
     * @param string $value
30
     */
31
    public function setName($value)
32
    {
33
        $this->name = $value;
34
    }
35
36
    /**
37
     * @param ClassDto $value
38
     */
39
    public function addClass(ClassDto $value)
40
    {
41
        $this->class[] = $value;
42
    }
43
44
    /**
45
     * @param integer $number
46
     * @param string $type
47
     * @param boolean $isCovered
48
     */
49
    public function addLine($number, $type, $isCovered)
50
    {
51
        $this->lines[$number] = array('number' => $number, 'type' => $type, 'isCovered' => $isCovered);
52
    }
53
54
    /**
55
     * @param string $basePath
56
     * @return string
57
     */
58
    public function getDestination($basePath)
59
    {
60
        return $this->getDirectory($basePath) . basename($this->name, '.php').'.html';
61
    }
62
63
    /**
64
     * @param string $basePath
65
     * @return string
66
     */
67
    public function getDirectory($basePath)
68
    {
69
        $dirname = dirname(str_replace($basePath, '', $this->name));
70
        return ($dirname === '.' ? '' : $dirname . '/');
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getName()
77
    {
78
        return $this->name;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getFileName()
85
    {
86
        return basename($this->name);
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getLink()
93
    {
94
        return basename($this->name, '.php').'.html';
95
    }
96
97
    /**
98
     * @return array
99
     */
100
    public function getClassCollection()
101
    {
102
        return $this->class;
103
    }
104
105
    /**
106
     * @return \CloverToHtml\LineIterator
107
     */
108
    public function getLineCollection()
109
    {
110
        return new LineIterator($this->name, $this->lines);
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getDir()
117
    {
118
        return dirname($this->name);
119
    }
120
121
    /**
122
     * @return array
123
     */
124
    public function getLineCoverage()
125
    {
126
        return $this->lines;
127
    }
128
129
    /**
130
     * @return number
131
     */
132
    public function getLineCoverageCount()
133
    {
134
        $lineCovered = 0;
135
136
        foreach ($this->lines as $line) {
137
            if ($line['isCovered'] === true) {
138
                ++$lineCovered;
139
            }
140
        }
141
142
        return $lineCovered;
143
    }
144
145
    /**
146
     * @return number
147
     */
148
    public function getCountClass()
149
    {
150
        return count($this->class);
151
    }
152
153
    /**
154
     * @return number
155
     */
156
    public function getMethodCoveredCount()
157
    {
158
        $methodCovered = 0;
159
160
        foreach ($this->class as $class) {
161
            $methodCovered += $class->getMethodCoveredCount();
162
        }
163
164
        return $methodCovered;
165
    }
166
167
    /**
168
     * @return number
169
     */
170
    public function getMethodCount()
171
    {
172
        $method = 0;
173
174
        foreach ($this->class as $class) {
175
            $method += $class->getMethodCount();
176
        }
177
178
        return $method;
179
    }
180
181
    /**
182
     * @return number
183
     */
184
    public function getLineCount()
185
    {
186
        $line = 0;
187
188
        foreach ($this->class as $class) {
189
            $line += $class->getLineCount();
190
        }
191
192
        return $line;
193
    }
194
}
195