Conditions | 13 |
Paths | 35 |
Total Lines | 48 |
Code Lines | 34 |
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 |
||
115 | public function fetchprice(HTTPRequest $request) |
||
116 | { |
||
117 | if (!$id = $request->getVar('h:product_id')) { |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | if (!$product = Product::get()->byID(explode('||', $id)[0])) { |
||
122 | return; |
||
123 | } |
||
124 | |||
125 | if (!$this->getIsDiscountable($product)) { |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | $totalPrice = Discount::config()->get('calculate_total'); |
||
130 | $quantity = (int)$request->getVar('quantity'); |
||
131 | $cost = ($totalPrice) ? $product->Price * $quantity : $product->Price; |
||
132 | $optionsQuery = $this->getOptionsQuery($request->getVars()); |
||
133 | $options = $product->Options()->filter($optionsQuery); |
||
134 | |||
135 | foreach ($options as $option) { |
||
136 | switch ($option->PriceModifierAction) { |
||
137 | case 'Add': |
||
138 | if ($totalPrice) { |
||
139 | $cost += ($option->PriceModifier * $quantity); |
||
140 | } else { |
||
141 | $cost += $option->PriceModifier; |
||
142 | } |
||
143 | break; |
||
144 | case 'Subtract': |
||
145 | if ($totalPrice) { |
||
146 | $cost -= ($option->PriceModifier * $quantity); |
||
147 | } else { |
||
148 | $cost -= $option->ProceModifier; |
||
149 | } |
||
150 | break; |
||
151 | case 'Set': |
||
152 | if ($totalPrice) { |
||
153 | $cost = ($option->PriceModifier * $quantity); |
||
154 | } else { |
||
155 | $cost = $option->PriceModifier; |
||
156 | } |
||
157 | break; |
||
158 | } |
||
159 | } |
||
160 | return $this->getDiscountHelper() instanceof DiscountHelper |
||
161 | ? $cost - $this->getDiscountHelper()->getDiscountedPrice()->getValue() |
||
162 | : $cost; |
||
163 | } |
||
194 |
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