Passed
Push — dev ( 9d591d...c59ba0 )
by Darko
22:01
created

CartController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 13
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Release;
6
use App\Models\UsersRelease;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Auth;
9
10
class CartController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function index()
16
    {
17
        $this->setPrefs();
18
        $meta_title = 'My Download Basket';
19
        $meta_keywords = 'search,add,to,cart,download,basket,nzb,description,details';
20
        $meta_description = 'Manage Your Download Basket';
21
22
        $results = UsersRelease::getCart(Auth::id());
23
        $this->smarty->assign('results', $results);
0 ignored issues
show
Bug introduced by
The method assign() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $this->smarty->/** @scrutinizer ignore-call */ 
24
                       assign('results', $results);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
25
        $content = $this->smarty->fetch('cart.tpl');
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $content = $this->smarty->fetch('cart.tpl');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
27
        $this->pagerender();
28
    }
29
30
    /**
31
     * @param \Illuminate\Http\Request $request
32
     *
33
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
34
     * @throws \Exception
35
     */
36
    public function store(Request $request)
37
    {
38
        $this->setPrefs();
39
        $guids = explode(',', $request->input('id'));
40
41
        $data = Release::query()->whereIn('guid', $guids)->select(['id'])->get();
42
43
        if (empty($data)) {
44
            return redirect('/cart/index');
45
        }
46
47
        foreach ($data as $d) {
48
            $check = UsersRelease::whereReleasesId($d['id'])->first();
49
            if (empty($check)) {
50
                UsersRelease::addCart($this->userdata->id, $d['id']);
51
            }
52
        }
53
54
        return redirect('/cart/index');
55
    }
56
57
    /**
58
     * @param string|array $id
59
     *
60
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
61
     * @throws \Exception
62
     */
63
    public function destroy($id)
64
    {
65
        $this->setPrefs();
66
        $ids = null;
67
        if (! empty($id) && ! \is_array($id)) {
68
            $ids = explode(',', $id);
69
        } elseif (\is_array($id)) {
70
            $ids = $id;
71
        }
72
73
        if (! empty($ids) && UsersRelease::delCartByGuid($ids, $this->userdata->id)) {
74
            return redirect('/cart/index');
75
        }
76
77
        if (! $id) {
78
            return redirect('/cart/index');
79
        }
80
81
        return redirect('/cart/index');
82
    }
83
}
84