1 | <?php |
||
5 | class Fraction |
||
6 | { |
||
7 | /** @var int $whole */ |
||
8 | private $whole; |
||
9 | |||
10 | /** @var int $numerator */ |
||
11 | private $numerator; |
||
12 | |||
13 | /** @var int $denominator */ |
||
14 | private $denominator; |
||
15 | |||
16 | /** @var bool $negative */ |
||
17 | private $negative; |
||
18 | |||
19 | 4 | public function __construct($whole = 0, $numerator = 0, $denominator = 1) |
|
26 | |||
27 | /** |
||
28 | * @return int |
||
29 | */ |
||
30 | 1 | public function getWhole() |
|
34 | |||
35 | /** |
||
36 | * @param int $whole |
||
37 | * @return Fraction |
||
38 | */ |
||
39 | 4 | public function setWhole($whole) |
|
44 | |||
45 | /** |
||
46 | * @return int |
||
47 | */ |
||
48 | 1 | public function getNumerator() |
|
52 | |||
53 | /** |
||
54 | * @param int $numerator |
||
55 | * @return Fraction |
||
56 | */ |
||
57 | 4 | public function setNumerator($numerator) |
|
62 | |||
63 | /** |
||
64 | * @return int |
||
65 | */ |
||
66 | 1 | public function getDenominator() |
|
70 | |||
71 | /** |
||
72 | * @param int $denominator |
||
73 | * @return Fraction |
||
74 | */ |
||
75 | 4 | public function setDenominator($denominator) |
|
80 | |||
81 | 1 | private function refactor() |
|
89 | |||
90 | 1 | private function refactorWhole() |
|
97 | |||
98 | 1 | private function refactorFraction() |
|
104 | |||
105 | /** |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function isNegative() |
||
112 | |||
113 | /** |
||
114 | * @param bool $negative |
||
115 | * @return Fraction |
||
116 | */ |
||
117 | public function setNegative($negative) |
||
122 | |||
123 | /** |
||
124 | * @return bool |
||
125 | */ |
||
126 | 1 | public function isInteger() |
|
130 | |||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | 1 | public function __toString() |
|
145 | |||
146 | /** |
||
147 | * @return float |
||
148 | */ |
||
149 | 1 | public function toDecimal() |
|
156 | } |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: