| Conditions | 13 |
| Paths | 2 |
| Total Lines | 160 |
| Code Lines | 94 |
| 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; |
||
| 28 | public function index(Request $request) |
||
| 29 | { |
||
| 30 | if ($request->wantsJson()) { |
||
| 31 | |||
| 32 | $product = ProductService::getModel()->select( |
||
| 33 | ['product.*', |
||
| 34 | 'brand.title as brandtitle', |
||
| 35 | 'product_category.title as categorytitle'] |
||
| 36 | )->with(array('productCategory', 'brand', 'subcategories', 'attributes', 'productImages','taxRate')) |
||
| 37 | |||
| 38 | ->leftJoin('product_category as product_category', 'product_category.id', '=', 'product.product_category_id') |
||
| 39 | |||
| 40 | ->leftJoin('brand as brand', 'brand.id', '=', 'product.brand_id') |
||
| 41 | |||
| 42 | ->where('product.shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
||
| 43 | |||
| 44 | $datatables = \Datatables::of($product) |
||
| 45 | ->filterColumn('reference_code', function ($query, $keyword) { |
||
| 46 | $query->whereRaw("product.reference_code like ?", ["%{$keyword}%"]); |
||
| 47 | }) |
||
| 48 | ->filterColumn('active', function ($query, $keyword) { |
||
| 49 | $query->whereRaw("product.active like ?", ["%{$keyword}%"]); |
||
| 50 | ; |
||
| 51 | }) |
||
| 52 | |||
| 53 | ->addColumn('rank', function ($product) { |
||
| 54 | return '<input type="text" class="change-rank" value="'.$product->rank.'" style="width:50px;" data-url="/admin/product/change-rank/'.$product->id.'">'; |
||
| 55 | |||
| 56 | }) |
||
| 57 | |||
| 58 | ->filterColumn('title', function ($query, $keyword) { |
||
| 59 | |||
| 60 | $query->where( |
||
| 61 | function ($query) use ($keyword) { |
||
| 62 | $query->whereRaw("product.title like ?", ["%{$keyword}%"]); |
||
| 63 | $query->orWhereRaw("product.reference_code like ?", ["%{$keyword}%"]); |
||
| 64 | $query->orWhereRaw("brand.title like ?", ["%{$keyword}%"]); |
||
| 65 | ; |
||
| 66 | } |
||
| 67 | ); |
||
| 68 | }) |
||
| 69 | |||
| 70 | ->filterColumn('categorytitle', function ($query, $keyword) { |
||
| 71 | $query->whereRaw("product_category.title like ?", ["%{$keyword}%"]); |
||
| 72 | }) |
||
| 73 | |||
| 74 | ->addColumn('active', function ($product) { |
||
| 75 | if ($product->active) { |
||
| 76 | return '<a href="#" class="change-active" data-url="'.url()->route('product.change-active', array('productId' => $product->id)).'"><span class="glyphicon glyphicon-ok icon-green"></span></a>'; |
||
| 77 | } |
||
| 78 | |||
| 79 | return '<a href="#" class="change-active" data-url="'.url()->route('product.change-active', array('productId' => $product->id)).'"><span class="glyphicon glyphicon-remove icon-red"></span></a>'; |
||
| 80 | }) |
||
| 81 | |||
| 82 | ->addColumn('title', function ($product) { |
||
| 83 | if ($product->brand) { |
||
| 84 | return $product->brand->title.' | '.$product->title; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $product->title; |
||
| 88 | }) |
||
| 89 | |||
| 90 | |||
| 91 | ->addColumn('amount', function ($product) { |
||
| 92 | if ($product->attributes->count()) { |
||
| 93 | return '<a href="/admin/product/'.$product->id.'/product-combination">combinations</a>'; |
||
| 94 | } |
||
| 95 | |||
| 96 | return '<input type="text" class="change-amount" value="'.$product->amount.'" style="width:50px;" data-url="'.url()->route('product.change-amount', array('productId' => $product->id)).'">'; |
||
| 97 | }) |
||
| 98 | |||
| 99 | ->addColumn('image', function ($product) { |
||
| 100 | if ($product->productImages->count()) { |
||
| 101 | return '<img src="/files/product/100x100/'.$product->id.'/'.$product->productImages->first()->file.'" />'; |
||
| 102 | } |
||
| 103 | }) |
||
| 104 | ->addColumn('price', function ($product) { |
||
| 105 | |||
| 106 | $result = ""; |
||
| 107 | if ($product->price) { |
||
| 108 | |||
| 109 | $taxRate = 0; |
||
| 110 | $priceInc = 0; |
||
| 111 | $taxValue = 0; |
||
| 112 | |||
| 113 | if (isset($product->taxRate->rate)) { |
||
| 114 | $taxRate = $product->taxRate->rate; |
||
| 115 | $priceInc = (($product->taxRate->rate / 100) * $product->price) + $product->price; |
||
| 116 | $taxValue = $priceInc - $product->price; |
||
| 117 | } |
||
| 118 | |||
| 119 | $discountPriceInc = false; |
||
| 120 | $discountPriceEx = false; |
||
| 121 | $discountTaxRate = 0; |
||
| 122 | if ($product->discount_value) { |
||
| 123 | if ($product->discount_type == 'amount') { |
||
| 124 | $discountPriceInc = $priceInc - $product->discount_value; |
||
| 125 | $discountPriceEx = $discountPriceInc / 1.21; |
||
| 126 | } elseif ($product->discount_type == 'percent') { |
||
| 127 | $tax = ($product->discount_value / 100) * $priceInc; |
||
| 128 | $discountPriceInc = $priceInc - $tax; |
||
| 129 | $discountPriceEx = $discountPriceInc / 1.21; |
||
| 130 | } |
||
| 131 | $discountTaxRate = $discountPriceInc - $discountPriceEx; |
||
| 132 | $discountPriceInc = $discountPriceInc; |
||
| 133 | $discountPriceEx = $discountPriceEx; |
||
| 134 | } |
||
| 135 | |||
| 136 | |||
| 137 | $output = array( |
||
| 138 | 'orginal_price_ex_tax' => $product->price, |
||
| 139 | 'orginal_price_ex_tax_number_format' => number_format($product->price, 2, '.', ''), |
||
| 140 | 'orginal_price_inc_tax' => $priceInc, |
||
| 141 | 'orginal_price_inc_tax_number_format' => number_format($priceInc, 2, '.', ''), |
||
| 142 | 'tax_rate' => $taxRate, |
||
| 143 | 'tax_value' => $taxValue, |
||
| 144 | 'currency' => 'EU', |
||
| 145 | 'discount_price_inc' => $discountPriceInc, |
||
| 146 | 'discount_price_inc_number_format' => number_format($discountPriceInc, 2, '.', ''), |
||
| 147 | 'discount_price_ex' => $discountPriceEx, |
||
| 148 | 'discount_price_ex_number_format' => number_format($discountPriceEx, 2, '.', ''), |
||
| 149 | 'discount_tax_value' => $discountTaxRate, |
||
| 150 | 'discount_value' => $product->discount_value, |
||
| 151 | 'amount' => $product->amount |
||
| 152 | ); |
||
| 153 | |||
| 154 | $result = '€ '.$output['orginal_price_ex_tax_number_format'].' / € '.$output['orginal_price_inc_tax_number_format']; |
||
| 155 | |||
| 156 | |||
| 157 | if ($product->discount_value) { |
||
| 158 | $result .= '<br/> discount: yes'; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | return $result; |
||
| 163 | }) |
||
| 164 | |||
| 165 | |||
| 166 | ->addColumn('categorytitle', function ($product) { |
||
| 167 | if ($product->subcategories()->count()) { |
||
| 168 | $subcategories = $product->subcategories()->pluck('title')->toArray(); |
||
| 169 | return $product->categorytitle.', <small> '.implode(', ', $subcategories).'</small>'; |
||
| 170 | } |
||
| 171 | |||
| 172 | return $product->categorytitle; |
||
| 173 | }) |
||
| 174 | |||
| 175 | ->addColumn('action', function ($product) { |
||
| 176 | $deleteLink = \Form::deleteajax(url()->route('product.destroy', $product->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'), $product->title); |
||
| 177 | $copy = '<a href="'.url()->route('product.copy', $product->id).'" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Copy</a>'; |
||
| 178 | |||
| 179 | $links = '<a href="'.url()->route('product.edit', $product->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$copy.' '.$deleteLink; |
||
| 180 | |||
| 181 | return $links; |
||
| 182 | }); |
||
| 183 | |||
| 184 | return $datatables->make(true); |
||
| 185 | } |
||
| 186 | |||
| 187 | return view('backend.product.index')->with('product', ProductService::selectAll()); |
||
| 188 | } |
||
| 431 |
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