1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestServedCold\PhalueObjects\Mathematical\Operator; |
4
|
|
|
|
5
|
|
|
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ArithmeticTrait |
9
|
|
|
* |
10
|
|
|
* @package BestServedCold\PhalueObjects\Mathematical\Operator |
11
|
|
|
* @author Adam Lewis <[email protected]> |
12
|
|
|
* @copyright Copyright (c) 2015 Best Served Cold Media Limited |
13
|
|
|
* @license http://http://opensource.org/licenses/GPL-3.0 GPL License |
14
|
|
|
* @link http://bestservedcold.com |
15
|
|
|
* @since 0.0.1-alpha |
16
|
|
|
* @version 0.0.2-alpha |
17
|
|
|
*/ |
18
|
|
|
trait ArithmeticTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @return mixed |
22
|
|
|
*/ |
23
|
|
|
public abstract function getValue(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return static |
27
|
|
|
*/ |
28
|
7 |
|
public function absolute() |
29
|
|
|
{ |
30
|
7 |
|
return new static(abs($this->getValue())); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return static |
35
|
|
|
*/ |
36
|
5 |
|
public function makeNegative() |
37
|
|
|
{ |
38
|
5 |
|
return new static(-$this->absolute()->getValue()); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return static |
43
|
|
|
*/ |
44
|
4 |
|
public function makePositive() |
45
|
|
|
{ |
46
|
4 |
|
return new static($this->absolute()->getValue()); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return static |
51
|
|
|
*/ |
52
|
2 |
|
public function reversePolarity() |
53
|
|
|
{ |
54
|
2 |
|
if ($this->isNegative() || $this->isZero()) { |
|
|
|
|
55
|
2 |
|
return new static($this->makePositive()->getValue()); |
|
|
|
|
56
|
|
|
} else { |
57
|
2 |
|
return new static($this->makeNegative()->getValue()); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param ValueObjectInterface $object |
63
|
|
|
* @return static |
64
|
|
|
*/ |
65
|
18 |
|
public function add(ValueObjectInterface $object) |
66
|
|
|
{ |
67
|
18 |
|
return new static($this->getValue() + $object->getValue()); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param ValueObjectInterface $object |
72
|
|
|
* @return static |
73
|
|
|
*/ |
74
|
1 |
|
public function subtract(ValueObjectInterface $object) |
75
|
|
|
{ |
76
|
1 |
|
return new static($this->getValue() - $object->getValue()); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param ValueObjectInterface $object |
81
|
|
|
* @return static |
82
|
|
|
*/ |
83
|
18 |
|
public function multiply(ValueObjectInterface $object) |
84
|
|
|
{ |
85
|
18 |
|
return new static($this->getValue() * $object->getValue()); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param ValueObjectInterface $object |
90
|
|
|
* @return static |
91
|
|
|
*/ |
92
|
1 |
|
public function divide(ValueObjectInterface $object) |
93
|
|
|
{ |
94
|
1 |
|
return new static($this->getValue() / $object->getValue()); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param ValueObjectInterface $object |
99
|
|
|
* @return static |
100
|
|
|
*/ |
101
|
1 |
|
public function modulus(ValueObjectInterface $object) |
102
|
|
|
{ |
103
|
1 |
|
return new static($this->getValue() % $object->getValue()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param ValueObjectInterface $object |
108
|
|
|
* @return static |
109
|
|
|
*/ |
110
|
1 |
|
public function exponentiation(ValueObjectInterface $object) |
111
|
|
|
{ |
112
|
1 |
|
return new static(pow($this->getValue(), $object->getValue())); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.