AnalyzedCoverageResult   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 22
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 186
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getCodeCoverage() 0 4 1
A isCoverageLessThan() 0 4 1
A isCoverageGreaterEqual() 0 4 1
A hasChildResults() 0 4 1
A getChildResults() 0 4 1
A accept() 0 4 1
A fromAnalyzeResult() 0 5 1
A parseResult() 0 15 2
A getFiles() 0 5 1
A getLineCount() 0 10 2
A getDeadLineCount() 0 10 2
A getExecutedLineCount() 0 10 2
A getUnusedLineCount() 0 10 2
A getExecutableLineCount() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of cloak.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace cloak;
13
14
use cloak\value\Coverage;
15
use cloak\result\FileResult;
16
use cloak\result\CoverageResultNode;
17
use cloak\result\CoverageResultVisitor;
18
use cloak\result\collection\LineResultCollection;
19
use cloak\result\collection\CoverageResultCollection;
20
use cloak\analyzer\AnalyzedResult;
21
22
23
/**
24
 * Class AnalyzedCoverageResult
25
 * @package cloak
26
 */
27
class AnalyzedCoverageResult implements CoverageResultNode
28
{
29
30
    /**
31
     * @var result\CoverageResultNodeCollection
32
     */
33
    private $fileResults;
34
35
36
    /**
37
     * @param FileResult[] $files
38
     */
39
    public function __construct($files = [])
40
    {
41
        $this->fileResults = new CoverageResultCollection($files);
42
    }
43
44
45
    /**
46
     * @param \cloak\analyzer\AnalyzedResult $result
47
     * @return AnalyzedCoverageResult
48
     */
49
    public static function fromAnalyzeResult(AnalyzedResult $result)
50
    {
51
        $files = static::parseResult($result);
52
        return new self($files);
53
    }
54
55
    /**
56
     * @param \cloak\analyzer\AnalyzedResult $result
57
     * @return array
58
     */
59
    public static function parseResult(AnalyzedResult $result)
60
    {
61
        $files = [];
62
        $fileResults = $result->getFiles();
63
64
        foreach ($fileResults as $fileResult) {
65
            $path = $fileResult->getPath();
66
            $lineResults = LineResultCollection::from( $fileResult->getLineResults() );
67
68
            $file = new FileResult($path, $lineResults);
69
            $files[$path] = $file;
70
        }
71
72
        return $files;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getName()
79
    {
80
        return 'Package';
81
    }
82
83
    /**
84
     * @return \cloak\result\CoverageResultNodeCollection
85
     */
86
    public function getFiles()
87
    {
88
        $fileResults = $this->fileResults->toArray();
89
        return new CoverageResultCollection($fileResults);
90
    }
91
92
    /**
93
     * @return int
94
     */
95
    public function getLineCount()
96
    {
97
        $totalLineCount = 0;
98
99
        foreach ($this->fileResults as $fileResult) {
100
            $totalLineCount += $fileResult->getLineCount();
101
        }
102
103
        return $totalLineCount;
104
    }
105
106
    /**
107
     * @return int
108
     */
109
    public function getDeadLineCount()
110
    {
111
        $totalLineCount = 0;
112
113
        foreach ($this->fileResults as $fileResult) {
114
            $totalLineCount += $fileResult->getDeadLineCount();
115
        }
116
117
        return $totalLineCount;
118
    }
119
120
    /**
121
     * @return int
122
     */
123
    public function getExecutedLineCount()
124
    {
125
        $totalLineCount = 0;
126
127
        foreach ($this->fileResults as $fileResult) {
128
            $totalLineCount += $fileResult->getExecutedLineCount();
129
        }
130
131
        return $totalLineCount;
132
    }
133
134
    /**
135
     * @return int
136
     */
137
    public function getUnusedLineCount()
138
    {
139
        $totalLineCount = 0;
140
141
        foreach ($this->fileResults as $fileResult) {
142
            $totalLineCount += $fileResult->getUnusedLineCount();
143
        }
144
145
        return $totalLineCount;
146
    }
147
148
    /**
149
     * @return int
150
     */
151
    public function getExecutableLineCount()
152
    {
153
        $totalLineCount = 0;
154
155
        foreach ($this->fileResults as $fileResult) {
156
            $totalLineCount += $fileResult->getExecutableLineCount();
157
        }
158
159
        return $totalLineCount;
160
    }
161
162
    /**
163
     * @return Coverage
164
     */
165
    public function getCodeCoverage()
166
    {
167
        return Coverage::fromLineResult($this);
168
    }
169
170
    /**
171
     * @param Coverage $coverage
172
     * @return bool
173
     */
174
    public function isCoverageLessThan(Coverage $coverage)
175
    {
176
        return $this->getCodeCoverage()->lessThan($coverage);
177
    }
178
179
    /**
180
     * @param Coverage $coverage
181
     * @return bool
182
     */
183
    public function isCoverageGreaterEqual(Coverage $coverage)
184
    {
185
        return $this->getCodeCoverage()->greaterEqual($coverage);
186
    }
187
188
    /**
189
     * @return bool
190
     */
191
    public function hasChildResults()
192
    {
193
        return $this->fileResults->isEmpty() === false;
194
    }
195
196
    /**
197
     * @return result\CoverageResultNodeCollection
198
     */
199
    public function getChildResults()
200
    {
201
        return $this->getFiles();
202
    }
203
204
    /**
205
     * @param CoverageResultVisitor $visitor
206
     */
207
    public function accept(CoverageResultVisitor $visitor)
208
    {
209
        $visitor->visit($this);
210
    }
211
212
}
213