Coverage   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 108
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A equals() 0 4 1
A lessEquals() 0 4 1
A lessThan() 0 4 1
A greaterEqual() 0 4 1
A greaterThan() 0 4 1
A value() 0 4 1
A formattedValue() 0 4 1
A __toString() 0 4 1
A fromLineResult() 0 16 3
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