Completed
Push — master ( 72a657...653b9d )
by Andrii
02:10
created

PhpCalculator   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 90
ccs 8
cts 24
cp 0.3333
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 0 4 1
A add() 0 6 1
A subtract() 0 6 1
A multiply() 0 6 1
A divide() 0 6 1
A ceil() 0 4 1
A floor() 0 4 1
A absolute() 0 4 1
A round() 0 4 1
A compare() 0 4 3
1
<?php
2
/**
3
 * PHP Units of Measure Library
4
 *
5
 * @link      https://github.com/hiqdev/php-units
6
 * @package   php-units
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\units\calculators;
12
13
use hiqdev\php\units\CalculatorInterface;
14
15
/**
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class PhpCalculator implements CalculatorInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public static function isSupported()
24
    {
25
        return true;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public function compare($a, $b)
32
    {
33 2
        return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function add($amount, $addend)
40
    {
41
        $result = $amount + $addend;
42
43
        return $result;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function subtract($amount, $subtrahend)
50
    {
51
        $result = $amount - $subtrahend;
52
53
        return $result;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 4
    public function multiply($amount, $multiplier)
60
    {
61 4
        $result = $amount * $multiplier;
62
63 4
        return $result;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 3
    public function divide($amount, $divisor)
70
    {
71 3
        $result = $amount / $divisor;
72
73 3
        return $result;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function ceil($number)
80
    {
81
        return ceil($number);
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function floor($number)
88
    {
89
        return floor($number);
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function absolute($number)
96
    {
97
        throw new \Exception();
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function round($number, $roundingMode)
104
    {
105
        throw new \Exception();
106
    }
107
}
108