|
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\value; |
|
13
|
|
|
|
|
14
|
|
|
use cloak\result\LineCountResult; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/*** |
|
18
|
|
|
* Class Coverage |
|
19
|
|
|
* @package cloak\value |
|
20
|
|
|
*/ |
|
21
|
|
|
class Coverage |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var float |
|
26
|
|
|
*/ |
|
27
|
|
|
private $value; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param float $value |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($value) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->value = (float) $value; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Coverage $value |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
|
|
public function equals(Coverage $value) |
|
43
|
|
|
{ |
|
44
|
|
|
return ($this->value() === $value->value()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Coverage $value |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
|
|
public function lessEquals(Coverage $value) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->value() <= $value->value(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param Coverage $value |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
public function lessThan(Coverage $value) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->value() < $value->value(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param Coverage $value |
|
67
|
|
|
* @return bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function greaterEqual(Coverage $value) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->value() >= $value->value(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param Coverage $value |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
public function greaterThan(Coverage $value) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->value() > $value->value(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return float |
|
85
|
|
|
*/ |
|
86
|
|
|
public function value() |
|
87
|
|
|
{ |
|
88
|
|
|
return (float) $this->value; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function formattedValue() |
|
95
|
|
|
{ |
|
96
|
|
|
return sprintf('%6.2f%%', $this->value()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param LineCountResult $result |
|
101
|
|
|
* @return \cloak\value\Coverage |
|
102
|
|
|
*/ |
|
103
|
|
|
public static function fromLineResult(LineCountResult $result) |
|
104
|
|
|
{ |
|
105
|
|
|
$value = 0.0; |
|
106
|
|
|
$executedLineCount = $result->getExecutedLineCount(); |
|
107
|
|
|
$executableLineCount = $result->getExecutableLineCount(); |
|
108
|
|
|
|
|
109
|
|
|
//PHP Warning: Division by zero in .... |
|
110
|
|
|
if ($executedLineCount <= 0 || $executableLineCount <= 0) { |
|
111
|
|
|
return new self($value); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$realCoverage = ($executedLineCount / $executableLineCount) * 100; |
|
115
|
|
|
$coverage = (float) round($realCoverage, 2); |
|
116
|
|
|
|
|
117
|
|
|
return new self($coverage); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function __toString() |
|
124
|
|
|
{ |
|
125
|
|
|
return (string) $this->value; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|