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