| Conditions | 3 |
| Paths | 2 |
| Total Lines | 62 |
| Code Lines | 41 |
| 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 |
||
| 56 | public function _setProductsDataStructure($products) |
||
| 57 | { |
||
| 58 | $orderData = [ |
||
| 59 | 'products' => null, |
||
| 60 | 'sub_total_amount' => null, |
||
| 61 | 'discount_amount' => null, |
||
| 62 | 'total_amount' => null, |
||
| 63 | ]; |
||
| 64 | |||
| 65 | if(!empty($products)) |
||
| 66 | { |
||
| 67 | |||
| 68 | $orderItems = []; |
||
| 69 | $sub_total_amount = 0; |
||
| 70 | $total_discount = 0; |
||
| 71 | $orderItems['products'] = []; |
||
| 72 | |||
| 73 | foreach ($products as $key => $product) { |
||
| 74 | //Product Price |
||
| 75 | $price = $product['price'] ; |
||
| 76 | $sale_price = $product['sale_price']; |
||
| 77 | $quantity = $product['quantity'] ?? 1; |
||
| 78 | |||
| 79 | //Product options |
||
| 80 | $product_options = $this->_setProductOptionsDataStructure($product); |
||
| 81 | |||
| 82 | $options_price = $product_options['price']; |
||
| 83 | $options = $product_options['options']; |
||
| 84 | |||
| 85 | |||
| 86 | #Product charges |
||
| 87 | $discount = ( $price - $sale_price ) * $quantity; |
||
| 88 | $product_price = ( $price + $options_price ) * $quantity; |
||
| 89 | $product_sub_total = ( $price + $options_price ) * $quantity; |
||
| 90 | |||
| 91 | $orderItems['products'][] = [ |
||
| 92 | "id" => $product['id'], |
||
| 93 | "name" => $product['name'], |
||
| 94 | "sku" => $product['sku'], |
||
| 95 | "quantity" => $quantity, |
||
| 96 | "price" => $price, |
||
| 97 | "sale_price" => $sale_price, |
||
| 98 | "discount" => $discount, |
||
| 99 | "sub_total" => $product_price, |
||
| 100 | "image" => $product['image'], |
||
| 101 | "short_description" => $product['short_description'], |
||
| 102 | "description" => $product['description'], |
||
| 103 | "product_options" => $options |
||
| 104 | ]; |
||
| 105 | |||
| 106 | $total_discount += $discount; |
||
| 107 | $sub_total_amount += $product_sub_total; |
||
| 108 | } |
||
| 109 | |||
| 110 | $order_grand_total = $sub_total_amount-$total_discount; |
||
| 111 | |||
| 112 | $orderData['products'] = $orderItems['products']; |
||
| 113 | $orderData['sub_total_amount'] = $sub_total_amount; |
||
| 114 | $orderData['discount_amount'] = $total_discount; |
||
| 115 | $orderData['total_amount'] = $order_grand_total; |
||
| 116 | } |
||
| 117 | return $orderData; |
||
| 118 | } |
||
| 192 |
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