Conditions | 12 |
Paths | 14 |
Total Lines | 71 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 1 | 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 |
||
13 | public function getIndex(Request $request, $categorySlug, $productId, $productSlug, $productAttributeId = false) |
||
14 | { |
||
15 | $product = ProductService::selectOneByShopIdAndId(config()->get('app.shop_id'), $productId, $request->get('combination_id')); |
||
16 | |||
17 | if ($product) { |
||
18 | if ($product->slug != $productSlug or $product->productCategory->slug != $categorySlug) { |
||
19 | return redirect()->route('product.item', array('productCategorySlug' => $product->productCategory->slug, 'productId' => $product->id, 'slug' => $product->slug)); |
||
20 | } |
||
21 | |||
22 | if ($product->ProductCategory and $product->ProductCategory->parent()->count()) { |
||
23 | $productCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $product->ProductCategory->parent()->first()->id, 'widescreen'); |
||
24 | } else { |
||
25 | $productCategories = ProductCategoryService::selectRootCategories(false, array('from_stock')); |
||
26 | } |
||
27 | |||
28 | if ($product->attributes->count() AND $product->attributeGroup AND $product->attributes->first()->combinations->count()) { |
||
29 | |||
30 | if ($product->attributeGroup) { |
||
31 | $attributeLeadingGroup = $product->attributeGroup; |
||
32 | } else { |
||
33 | $attributeLeadingGroup = $product->attributes->first()->combinations->first()->attribute->attributeGroup; |
||
34 | } |
||
35 | |||
36 | $pullDowns = ProductCombinationService::generatePulldowns($product, $productAttributeId, $attributeLeadingGroup); |
||
37 | $newPullDowns = $pullDowns['newPullDowns']; |
||
38 | |||
39 | $productAttribute = $pullDowns['productAttribute']; |
||
40 | $productImages = ProductService::ajaxProductImages($product, $productAttribute->combinations->pluck('attribute_id')->toArray(), $productAttribute->id); |
||
41 | |||
42 | $template = 'frontend.product.combinations'; |
||
43 | |||
44 | $leadingAttributeId = key(reset($newPullDowns)); |
||
45 | if($productAttributeId) { |
||
46 | $leadingAttributeId = $productAttributeId; |
||
47 | } else { |
||
48 | $productAttributeId = $pullDowns['productAttribute']->first()->id; |
||
49 | } |
||
50 | |||
51 | return view($template)->with( |
||
52 | array( |
||
53 | 'productImages' => $productImages, |
||
54 | 'productAttributeId' => $productAttributeId, |
||
55 | 'leadAttributeId' => $leadingAttributeId, |
||
56 | 'firstPulldown' => key($newPullDowns), |
||
57 | 'newPullDowns' => $newPullDowns, |
||
58 | 'priceDetails' => $productAttribute->getPriceDetails(), |
||
59 | 'childrenProductCategories' => $productCategories, |
||
60 | 'product' => $product |
||
61 | ) |
||
62 | ); |
||
63 | } |
||
64 | |||
65 | $productImages = $product->productImages; |
||
66 | |||
67 | if (isset($product['ancestors'])) { |
||
68 | $request->session()->put('category_id', $product['ancestors'][0]['id']); |
||
69 | } |
||
70 | |||
71 | $template = 'frontend.product.index'; |
||
72 | |||
73 | return view($template)->with( |
||
74 | array( |
||
75 | 'priceDetails' => $product->getPriceDetails(), |
||
76 | 'childrenProductCategories' => $productCategories, |
||
77 | 'product' => $product, |
||
78 | 'productImages' => $productImages |
||
79 | ) |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | abort(404); |
||
84 | } |
||
110 | } |