@@ 116-140 (lines=25) @@ | ||
113 | * |
|
114 | * @return double |
|
115 | */ |
|
116 | protected function applyOperation($value, $operator, $operand) |
|
117 | { |
|
118 | $processedValue = $value; |
|
119 | ||
120 | switch ($operator) { |
|
121 | case "div": |
|
122 | if ($operand !== 0) { |
|
123 | $processedValue = $processedValue / $operand; |
|
124 | } |
|
125 | break; |
|
126 | case "mul": |
|
127 | $processedValue = $processedValue * $operand; |
|
128 | break; |
|
129 | case "add": |
|
130 | $processedValue = $processedValue + $operand; |
|
131 | break; |
|
132 | case "sub": |
|
133 | $processedValue = $processedValue - $operand; |
|
134 | break; |
|
135 | default: |
|
136 | throw new UnknownOperatorException(); |
|
137 | } |
|
138 | ||
139 | return $processedValue; |
|
140 | } |
|
141 | ||
142 | /** |
|
143 | * Convert a value in a standard unit to a final unit |
|
@@ 185-209 (lines=25) @@ | ||
182 | * |
|
183 | * @return double |
|
184 | */ |
|
185 | protected function applyReversedOperation($value, $operator, $operand) |
|
186 | { |
|
187 | $processedValue = $value; |
|
188 | ||
189 | switch ($operator) { |
|
190 | case "div": |
|
191 | $processedValue = $processedValue * $operand; |
|
192 | break; |
|
193 | case "mul": |
|
194 | if ($operand !== 0) { |
|
195 | $processedValue = $processedValue / $operand; |
|
196 | } |
|
197 | break; |
|
198 | case "add": |
|
199 | $processedValue = $processedValue - $operand; |
|
200 | break; |
|
201 | case "sub": |
|
202 | $processedValue = $processedValue + $operand; |
|
203 | break; |
|
204 | default: |
|
205 | throw new UnknownOperatorException(); |
|
206 | } |
|
207 | ||
208 | return $processedValue; |
|
209 | } |
|
210 | } |
|
211 |