Passed
Push — dev ( c55b95...34fb50 )
by Darko
06:54
created

AdminCategoryController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 36
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 43 4
A index() 0 13 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use App\Models\Category;
7
use Illuminate\Http\Request;
8
9
class AdminCategoryController extends BasePageController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function index()
15
    {
16
        $this->setAdminPrefs();
17
        $meta_title = $title = 'Category List';
18
19
        $categorylist = Category::getFlat();
20
21
        $this->smarty->assign('categorylist', $categorylist);
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

21
        $this->smarty->/** @scrutinizer ignore-call */ 
22
                       assign('categorylist', $categorylist);

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...
22
23
        $content = $this->smarty->fetch('category-list.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

23
        /** @scrutinizer ignore-call */ 
24
        $content = $this->smarty->fetch('category-list.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...
24
25
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
26
        $this->adminrender();
27
    }
28
29
    /**
30
     * @param \Illuminate\Http\Request $request
31
     *
32
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
33
     * @throws \Exception
34
     */
35
    public function edit(Request $request)
36
    {
37
        $this->setAdminPrefs();
38
39
        // set the current action
40
        $action = $request->input('action') ?? 'view';
41
42
        switch ($action) {
43
            case 'submit':
44
                Category::updateCategory(
45
                    $request->input('id'),
46
                    $request->input('status'),
47
                    $request->input('description'),
48
                    $request->input('disablepreview'),
49
                    $request->input('minsizetoformrelease'),
50
                    $request->input('maxsizetoformrelease')
51
                );
52
53
                return redirect('admin/category-list');
54
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
55
            case 'view':
56
            default:
57
                if ($request->has('id')) {
58
                    $this->title = 'Category Edit';
59
                    $id = $request->input('id');
60
                    $cat = Category::find($id);
61
                    $this->smarty->assign('category', $cat);
62
                }
63
                break;
64
        }
65
66
        $this->smarty->assign('status_ids', [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE, Category::STATUS_DISABLED]);
67
        $this->smarty->assign('status_names', ['Yes', 'No', 'Disabled']);
68
69
        $content = $this->smarty->fetch('category-edit.tpl');
70
71
        $this->smarty->assign(
72
            [
73
                'content' => $content,
74
                'meta_title' => 'View/Edit categories',
75
            ]
76
        );
77
        $this->adminrender();
78
    }
79
}
80