Conditions | 8 |
Paths | 24 |
Total Lines | 66 |
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; |
||
159 | protected function apply($totalOrSubTotalOrPrice, $conditionValue) |
||
160 | { |
||
161 | // if type of condition is multiply we make count it or |
||
162 | // if value has a percentage sign on it, we will get first |
||
163 | // its percentage then we will evaluate again if the value |
||
164 | // has a minus or plus sign so we can decide what to do with the |
||
165 | // percentage, whether to add or subtract it to the total/subtotal/price |
||
166 | // if we can't find any plus/minus sign, we will assume it as plus sign |
||
167 | if( $this->getType() == 'multiply' ){ |
||
168 | $result = $totalOrSubTotalOrPrice + ( $this->getValue() * $this->getQuantity() ); |
||
|
|||
169 | } |
||
170 | if( $this->valueIsPercentage($conditionValue) ) |
||
171 | { |
||
172 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
173 | { |
||
174 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
175 | |||
176 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
177 | |||
178 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
179 | } |
||
180 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
181 | { |
||
182 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
183 | |||
184 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
185 | |||
186 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
187 | } |
||
188 | else |
||
189 | { |
||
190 | $value = Helpers::normalizePrice($conditionValue); |
||
191 | |||
192 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
||
193 | |||
194 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | // if the value has no percent sign on it, the operation will not be a percentage |
||
199 | // next is we will check if it has a minus/plus sign so then we can just deduct it to total/subtotal/price |
||
200 | else |
||
201 | { |
||
202 | if( $this->valueIsToBeSubtracted($conditionValue) ) |
||
203 | { |
||
204 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
205 | |||
206 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
||
207 | } |
||
208 | else if ( $this->valueIsToBeAdded($conditionValue) ) |
||
209 | { |
||
210 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
||
211 | |||
212 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
213 | } |
||
214 | else |
||
215 | { |
||
216 | $this->parsedRawValue = Helpers::normalizePrice($conditionValue); |
||
217 | |||
218 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
||
219 | } |
||
220 | } |
||
221 | |||
222 | // Do not allow items with negative prices. |
||
223 | return $result < 0 ? 0.00 : $result; |
||
224 | } |
||
225 | |||
292 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.