| Conditions | 10 |
| Paths | 3 |
| Total Lines | 100 |
| Code Lines | 64 |
| 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 App\Http\Controllers\Backend; |
||
| 25 | public function index(Request $request, $productId) |
||
| 26 | { |
||
| 27 | $product = ProductService::find($productId); |
||
| 28 | |||
| 29 | if($product) { |
||
| 30 | if ($request->wantsJson()) { |
||
| 31 | |||
| 32 | $query = ProductCombinationService::getModel()->select( |
||
| 33 | ['id', 'tax_rate_id', 'amount', 'price', 'product_id', 'reference_code', |
||
| 34 | 'default_on'] |
||
| 35 | )->where('product_id', '=', $productId); |
||
| 36 | |||
| 37 | $datatables = \Datatables::of($query)->addColumn('action', function ($query) use ($productId) { |
||
|
|
|||
| 38 | $deleteLink = \Form::deleteajax(url()->route('product-combination.destroy', array('productId' => $productId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
||
| 39 | $links = '<a href="'.url()->route('product-combination.edit', array('productId' => $productId, 'id' => $query->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
||
| 40 | |||
| 41 | return $links; |
||
| 42 | }) |
||
| 43 | |||
| 44 | ->addColumn('amount', function ($query) { |
||
| 45 | return '<input type="text" class="change-amount-product-attribute" value="'.$query->amount.'" data-url="/admin/product/'.$query->product_id.'/product-combination/change-amount-attribute/'.$query->id.'">'; |
||
| 46 | }) |
||
| 47 | |||
| 48 | ->addColumn('price', function ($query) { |
||
| 49 | $result = 0; |
||
| 50 | if ($query->price) { |
||
| 51 | |||
| 52 | $taxRate = 0; |
||
| 53 | $priceInc = 0; |
||
| 54 | $taxValue = 0; |
||
| 55 | |||
| 56 | if (isset($query->taxRate->rate)) { |
||
| 57 | $taxRate = $query->taxRate->rate; |
||
| 58 | $priceInc = (($query->taxRate->rate / 100) * $query->price) + $query->price; |
||
| 59 | $taxValue = $priceInc - $query->price; |
||
| 60 | } |
||
| 61 | |||
| 62 | $discountPriceInc = false; |
||
| 63 | $discountPriceEx = false; |
||
| 64 | $discountTaxRate = 0; |
||
| 65 | if ($query->discount_value) { |
||
| 66 | if ($query->discount_type == 'amount') { |
||
| 67 | $discountPriceInc = $priceInc - $query->discount_value; |
||
| 68 | $discountPriceEx = $discountPriceInc / 1.21; |
||
| 69 | } elseif ($query->discount_type == 'percent') { |
||
| 70 | $tax = ($query->discount_value / 100) * $priceInc; |
||
| 71 | $discountPriceInc = $priceInc - $tax; |
||
| 72 | $discountPriceEx = $discountPriceInc / 1.21; |
||
| 73 | } |
||
| 74 | $discountTaxRate = $discountPriceInc - $discountPriceEx; |
||
| 75 | $discountPriceInc = $discountPriceInc; |
||
| 76 | $discountPriceEx = $discountPriceEx; |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | $output = array( |
||
| 81 | 'orginal_price_ex_tax' => $query->price, |
||
| 82 | 'orginal_price_ex_tax_number_format' => number_format($query->price, 2, '.', ''), |
||
| 83 | 'orginal_price_inc_tax' => $priceInc, |
||
| 84 | 'orginal_price_inc_tax_number_format' => number_format($priceInc, 2, '.', ''), |
||
| 85 | 'tax_rate' => $taxRate, |
||
| 86 | 'tax_value' => $taxValue, |
||
| 87 | 'currency' => 'EU', |
||
| 88 | 'discount_price_inc' => $discountPriceInc, |
||
| 89 | 'discount_price_inc_number_format' => number_format($discountPriceInc, 2, '.', ''), |
||
| 90 | 'discount_price_ex' => $discountPriceEx, |
||
| 91 | 'discount_price_ex_number_format' => number_format($discountPriceEx, 2, '.', ''), |
||
| 92 | 'discount_tax_value' => $discountTaxRate, |
||
| 93 | 'discount_value' => $query->discount_value, |
||
| 94 | 'amount' => $query->amount |
||
| 95 | ); |
||
| 96 | |||
| 97 | $result = '€ '.$output['orginal_price_ex_tax_number_format'].' / € '.$output['orginal_price_inc_tax_number_format']; |
||
| 98 | |||
| 99 | |||
| 100 | if ($query->discount_value) { |
||
| 101 | $result .= '<br/> discount: yes'; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return $result; |
||
| 106 | }) |
||
| 107 | |||
| 108 | ->addColumn('combinations', function ($query) use ($productId) { |
||
| 109 | $items = array(); |
||
| 110 | foreach ($query->combinations as $row) { |
||
| 111 | $items[] = $row->attribute->attributeGroup->title.': '.$row->attribute->value; |
||
| 112 | } |
||
| 113 | |||
| 114 | return implode(', ', $items); |
||
| 115 | }); |
||
| 116 | |||
| 117 | return $datatables->make(true); |
||
| 118 | |||
| 119 | } |
||
| 120 | |||
| 121 | return view('backend.product-combination.index')->with(array('product' => $product, 'attributeGroups' => AttributeService::selectAllGroups()->pluck('title', 'id'))); |
||
| 122 | } |
||
| 123 | |||
| 124 | return redirect()->route('product.index'); |
||
| 125 | } |
||
| 206 |
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