Passed
Push — master ( f4b030...a2b3af )
by Matthijs
22:06 queued 15:53
created

ProductRelatedProductController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
4
/**
5
 * ProductRelatedProductController
6
 *
7
 * This is the controller of the product related products of the shop
8
 * @author Matthijs Neijenhuijs <[email protected]>
9
 * @version 0.1
10
 */
11
12
use App\Http\Controllers\Controller;
13
14
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
15
use Hideyo\Ecommerce\Framework\Services\Product\ProductRelatedProductFacade as ProductRelatedProductService;
0 ignored issues
show
Bug introduced by
The type Hideyo\Ecommerce\Framewo...uctRelatedProductFacade was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
use Illuminate\Http\Request;
18
use Notification;
19
20
class ProductRelatedProductController extends Controller
21
{
22
    public function index(Request $request, $productId)
23
    {
24
        $product = ProductService::find($productId);
25
        if ($request->wantsJson()) {
26
27
            $query = ProductRelatedProductService::getModel()->where('product_id', '=', $productId);
28
            
29
            $datatables = \Datatables::of($query)
0 ignored issues
show
Bug introduced by
The type Datatables was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
                ->addColumn('related', function ($query) use ($productId) {
0 ignored issues
show
Unused Code introduced by
The import $productId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
31
                    return $query->RelatedProduct->title;
32
                })
33
                ->addColumn('product', function ($query) use ($productId) {
0 ignored issues
show
Unused Code introduced by
The import $productId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
34
                    return $query->Product->title;
35
                })
36
                ->addColumn('action', function ($query) use ($productId) {
37
                    $deleteLink = \Form::deleteajax(url()->route('product.related-product.destroy', array('productId' => $productId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
38
                    
39
                    return $deleteLink;
40
                });
41
42
                return $datatables->make(true);
43
        }
44
        
45
        return view('backend.product_related_product.index')->with(array('product' => $product));
46
    }
47
48
    public function create($productId)
49
    {
50
        $product = ProductService::find($productId);
51
        $products = ProductService::selectAll()->pluck('title', 'id');
52
53
        return view('backend.product_related_product.create')->with(array('products' => $products, 'product' => $product));
54
    }
55
    
56
    public function store(Request $request, $productId)
57
    {
58
        $result  = ProductRelatedProductService::create($request->all(), $productId);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
59
        return redirect()->route('product.related-product.index', $productId);
60
    }
61
62
    public function destroy($productId, $productRelatedProductId)
63
    {
64
        $result  = ProductRelatedProductService::destroy($productRelatedProductId);
65
66
        if ($result) {
67
            Notification::success('The related product is deleted.');
68
            return redirect()->route('product.related-product.index', $productId);
69
        }
70
    }
71
}
72