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) |
|
63 | |||
64 | /** |
||
65 | * @return int |
||
66 | */ |
||
67 | 1 | public function getDenominator() |
|
71 | |||
72 | /** |
||
73 | * @param int $denominator |
||
74 | * @return Fraction |
||
75 | */ |
||
76 | 4 | public function setDenominator($denominator) |
|
82 | |||
83 | 4 | private function refactor() |
|
87 | |||
88 | /** |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function isNegative() |
||
95 | |||
96 | /** |
||
97 | * @param bool $negative |
||
98 | * @return Fraction |
||
99 | */ |
||
100 | public function setNegative($negative) |
||
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | 2 | public function isInteger() |
|
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | 1 | public function __toString() |
|
128 | |||
129 | /** |
||
130 | * @return float |
||
131 | */ |
||
132 | 1 | public function toDecimal() |
|
139 | } |
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: