Conditions | 7 |
Paths | 12 |
Total Lines | 63 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php namespace Darryldecode\Cart; |
||
164 | protected function apply($totalOrSubTotalOrPrice, $conditionValue) |
||
165 | { |
||
166 | $totalOrSubTotalOrPrice = Helpers::normalizePrice( $totalOrSubTotalOrPrice, $this->getConfig() ); |
||
167 | // if value has a percentage sign on it, we will get first |
||
168 | // its percentage then we will evaluate again if the value |
||
169 | // has a minus or plus sign so we can decide what to do with the |
||
170 | // percentage, whether to add or subtract it to the total/subtotal/price |
||
171 | // if we can't find any plus/minus sign, we will assume it as plus sign |
||
172 | if( $this->valueIsPercentage($conditionValue) ) |
||
173 | { |
||
174 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
175 | { |
||
176 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue), $this->getConfig() ); |
||
177 | |||
178 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
179 | |||
180 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
181 | } |
||
182 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
183 | { |
||
184 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue), $this->getConfig() ); |
||
185 | |||
186 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
187 | |||
188 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
189 | } |
||
190 | else |
||
191 | { |
||
192 | $value = Helpers::normalizePrice($conditionValue, $this->getConfig()); |
||
193 | |||
194 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
195 | |||
196 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | // if the value has no percent sign on it, the operation will not be a percentage |
||
201 | // next is we will check if it has a minus/plus sign so then we can just deduct it to total/subtotal/price |
||
202 | else |
||
203 | { |
||
204 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
205 | { |
||
206 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue), $this->getConfig() ); |
||
207 | |||
208 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
209 | } |
||
210 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
211 | { |
||
212 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue), $this->getConfig() ); |
||
213 | |||
214 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
215 | } |
||
216 | else |
||
217 | { |
||
218 | $this->parsedRawValue = Helpers::normalizePrice($conditionValue, $this->getConfig()); |
||
219 | |||
220 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | // Do not allow items with negative prices. |
||
225 | return $result < 0 ? 0.00 : $result; |
||
226 | } |
||
227 | |||
304 |