Conditions | 7 |
Paths | 12 |
Total Lines | 62 |
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; |
||
149 | protected function apply($totalOrSubTotalOrPrice, $conditionValue) |
||
150 | { |
||
151 | // if value has a percentage sign on it, we will get first |
||
152 | // its percentage then we will evaluate again if the value |
||
153 | // has a minus or plus sign so we can decide what to do with the |
||
154 | // percentage, whether to add or subtract it to the total/subtotal/price |
||
155 | // if we can't find any plus/minus sign, we will assume it as plus sign |
||
156 | if( $this->valueIsPercentage($conditionValue) ) |
||
157 | { |
||
158 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
159 | { |
||
160 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
161 | |||
162 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
163 | |||
164 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
165 | } |
||
166 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
167 | { |
||
168 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
169 | |||
170 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
171 | |||
172 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
173 | } |
||
174 | else |
||
175 | { |
||
176 | $value = Helpers::normalizePrice($conditionValue); |
||
177 | |||
178 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
179 | |||
180 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | // if the value has no percent sign on it, the operation will not be a percentage |
||
185 | // next is we will check if it has a minus/plus sign so then we can just deduct it to total/subtotal/price |
||
186 | else |
||
187 | { |
||
188 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
189 | { |
||
190 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
191 | |||
192 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
193 | } |
||
194 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
195 | { |
||
196 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
197 | |||
198 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
199 | } |
||
200 | else |
||
201 | { |
||
202 | $this->parsedRawValue = Helpers::normalizePrice($conditionValue); |
||
203 | |||
204 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
205 | } |
||
206 | } |
||
207 | |||
208 | // Do not allow items with negative prices. |
||
209 | return $result < 0 ? 0.00 : $result; |
||
210 | } |
||
211 | |||
278 |