| Conditions | 17 |
| Paths | 115 |
| Total Lines | 61 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 88 | public function fetchprice(HTTPRequest $request) |
||
| 89 | { |
||
| 90 | if (!$id = $request->getVar('h:product_id')) { |
||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | if (!$product = Product::get()->byID(explode('||', $id)[0])) { |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | |||
| 98 | if (!$this->getIsDiscountable($product)) { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | $totalPrice = Discount::config()->get('calculate_total'); |
||
| 103 | $quantity = (int)$request->getVar('quantity'); |
||
| 104 | $cost = ($totalPrice) ? $product->Price * $quantity : $product->Price; |
||
| 105 | $optionsQuery = $this->getOptionsQuery($request->getVars()); |
||
| 106 | $options = $product->Options()->filter($optionsQuery); |
||
| 107 | |||
| 108 | foreach ($options as $option) { |
||
| 109 | switch ($option->PriceModifierAction) { |
||
| 110 | case 'Add': |
||
| 111 | if ($totalPrice) { |
||
| 112 | $cost += ($option->PriceModifier * $quantity); |
||
| 113 | } else { |
||
| 114 | $cost += $option->PriceModifier; |
||
| 115 | } |
||
| 116 | break; |
||
| 117 | case 'Subtract': |
||
| 118 | if ($totalPrice) { |
||
| 119 | $cost -= ($option->PriceModifier * $quantity); |
||
| 120 | } else { |
||
| 121 | $cost -= $option->ProceModifier; |
||
| 122 | } |
||
| 123 | break; |
||
| 124 | case 'Set': |
||
| 125 | if ($totalPrice) { |
||
| 126 | $cost = ($option->PriceModifier * $quantity); |
||
| 127 | } else { |
||
| 128 | $cost = $option->PriceModifier; |
||
| 129 | } |
||
| 130 | break; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | $discount = $this->getDiscount($quantity); |
||
| 135 | |||
| 136 | if ($discount instanceof DiscountTier && $discount->exists()) { |
||
| 137 | if ($discount->Discount()->Type == 'Percent') { |
||
| 138 | $discountAmount = $cost * ($discount->Percentage / 100); |
||
| 139 | } elseif ($discount->Discount()->Type == 'Amount') { |
||
| 140 | $discountAmount = $discount->Amount; |
||
| 141 | } |
||
| 142 | |||
| 143 | if (isset($discountAmount)) { |
||
| 144 | $cost = $cost - $discountAmount; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return $cost; |
||
| 149 | } |
||
| 196 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths