| Conditions | 10 |
| Paths | 20 |
| Total Lines | 31 |
| 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 |
||
| 65 | public function updateCalculatedPrice($price = null) |
||
| 66 | { |
||
| 67 | if($this->getCanBeDiscounted()) { |
||
| 68 | $hasDiscount = false; |
||
| 69 | $coupons = $this->owner->DirectlyApplicableDiscountCoupons(); |
||
| 70 | if ($coupons && $coupons->count()) { |
||
| 71 | $discountPercentage = 0; |
||
| 72 | $discountAbsolute = 0; |
||
| 73 | foreach ($coupons as $coupon) { |
||
| 74 | if ($coupon->isValid()) { |
||
| 75 | $hasDiscount = true; |
||
| 76 | if ($coupon->DiscountPercentage > $discountPercentage) { |
||
| 77 | $discountPercentage = $coupon->DiscountPercentage; |
||
| 78 | } |
||
| 79 | if ($coupon->DiscountAbsolute > $discountAbsolute) { |
||
| 80 | $discountAbsolute = $coupon->DiscountAbsolute; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | if ($hasDiscount) { |
||
| 85 | $priceWithPercentageDiscount = $price - ($price * ($discountPercentage / 100)); |
||
| 86 | $priceWithAbsoluteDiscount = $price - $discountAbsolute; |
||
| 87 | if ($priceWithPercentageDiscount < $priceWithAbsoluteDiscount) { |
||
| 88 | return $priceWithPercentageDiscount; |
||
| 89 | } else { |
||
| 90 | return $priceWithAbsoluteDiscount; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 144 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: