GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Percentage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 87
ccs 19
cts 19
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A equals() 0 4 1
A getPercent() 0 4 1
A add() 0 6 1
A sub() 0 6 1
A __toString() 0 4 1
A convert() 0 4 1
A invert() 0 4 1
1
<?php
2
3
namespace WSW\Money;
4
5
/**
6
 * Class Percentage
7
 *
8
 * @package WSW\Money
9
 * @author Ronaldo Matos Rodrigues <[email protected]>
10
 */
11
final class Percentage
12
{
13
    const DECIMALS = 6;
14
15
    /**
16
     * @var float
17
     */
18
    private $percentage;
19
20
    /**
21
     * @param string $percentage
22
     */
23 7
    public function __construct($percentage)
24
    {
25 7
        $this->percentage = $this->convert(preg_replace("/[^0-9.]/", "", $percentage));
26 7
    }
27
28
    /**
29
     * @param Percentage $other
30
     *
31
     * @return bool
32
     */
33 1
    public function equals(Percentage $other)
34
    {
35 1
        return (bool) ($this->getPercent() === $other->getPercent());
36
    }
37
38
    /**
39
     * @return float
40
     */
41 6
    public function getPercent()
42
    {
43 6
        return $this->percentage;
44
    }
45
46
    /**
47
     * @param Percentage $addend
48
     *
49
     * @return Percentage
50
     */
51 1
    public function add(Percentage $addend)
52
    {
53 1
        $newValue = bcadd($this->getPercent(), $addend->getPercent(), static::DECIMALS);
54
55 1
        return new static($this->invert($newValue));
56
    }
57
58
    /**
59
     * @param Percentage $subtrahend
60
     *
61
     * @return Percentage
62
     */
63 1
    public function sub(Percentage $subtrahend)
64
    {
65 1
        $newValue = bcsub($this->getPercent(), $subtrahend->getPercent(), static::DECIMALS);
66
67 1
        return new static($this->invert($newValue));
68
    }
69
70
    /**
71
     * @return string
72
     */
73 3
    public function __toString()
74
    {
75 3
        return $this->invert($this->percentage) . "%";
76
    }
77
78
    /**
79
     * @param string|float|int $value
80
     *
81
     * @return float
82
     */
83 7
    private function convert($value)
84
    {
85 7
        return (float) ($value / 100);
86
    }
87
88
    /**
89
     * @param float $percent
90
     *
91
     * @return string
92
     */
93 3
    private function invert($percent)
94
    {
95 3
        return ($percent * 100);
96
    }
97
}
98