Test Failed
Push — develop ( 88d89c...00d2c4 )
by Remco
12:20
created

PhpCalculator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 72
c 0
b 0
f 0
rs 10
wmc 5
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A supported() 0 3 1
A add() 0 5 1
A subtract() 0 5 1
A multiply() 0 5 1
A divide() 0 5 1
1
<?php
2
/**
3
 * PHP Calculator
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Money
9
 */
10
11
namespace Pronamic\WordPress\Money\Calculator;
12
13
use Pronamic\WordPress\Money\Calculator;
14
15
/**
16
 * GMP Calculator
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.2.1
20
 * @since   1.0.0
21
 */
22
class PhpCalculator implements Calculator {
23
	/**
24
	 * {@inheritdoc}
25
	 */
26
	public static function supported() {
27
		return true;
28
	}
29
30
	/**
31
	 * {@inheritdoc}
32
	 *
33
	 * @link https://github.com/moneyphp/money/blob/v3.2.1/src/Calculator/PhpCalculator.php#L30-L40
34
	 *
35
	 * @param string $value  Value.
36
	 * @param string $addend Addend.
37
	 *
38
	 * @return string
39
	 */
40
	public function add( $value, $addend ) {
41
		$result = floatval( $value ) + floatval( $addend );
42
43
		return strval( $result );
44
	}
45
46
	/**
47
	 * {@inheritdoc}
48
	 *
49
	 * @link https://github.com/moneyphp/money/blob/v3.2.1/src/Calculator/PhpCalculator.php#L42-L52
50
	 *
51
	 * @param string $value      Value.
52
	 * @param string $subtrahend Subtrahend.
53
	 *
54
	 * @return string
55
	 */
56
	public function subtract( $value, $subtrahend ) {
57
		$result = floatval( $value ) - floatval( $subtrahend );
58
59
		return strval( $result );
60
	}
61
62
	/**
63
	 * {@inheritdoc}
64
	 *
65
	 * @link https://github.com/moneyphp/money/blob/v3.2.1/src/Calculator/PhpCalculator.php#L54-L64
66
	 *
67
	 * @param string           $value      Value.
68
	 * @param int|float|string $multiplier Multiplier.
69
	 *
70
	 * @return string
71
	 */
72
	public function multiply( $value, $multiplier ) {
73
		$result = floatval( $value ) * floatval( $multiplier );
74
75
		return strval( $result );
76
	}
77
78
	/**
79
	 * {@inheritdoc}
80
	 *
81
	 * @link https://github.com/moneyphp/money/blob/v3.2.1/src/Calculator/PhpCalculator.php#L66-L76
82
	 *
83
	 * @param string           $value   Value.
84
	 * @param int|float|string $divisor Divisor.
85
	 *
86
	 * @return string
87
	 */
88
	public function divide( $value, $divisor ) {
89
		$result = floatval( $value ) / floatval( $divisor );
90
91
		return strval( $result );
92
	}
93
}
94