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

AdminShowsController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 39
dl 0
loc 83
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 17 2
A edit() 0 29 6
A index() 0 18 3
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use App\Models\Release;
7
use App\Models\Video;
8
use Illuminate\Http\Request;
9
10
class AdminShowsController extends BasePageController
11
{
12
    /**
13
     * @param \Illuminate\Http\Request $request
14
     * @throws \Exception
15
     */
16
    public function index(Request $request)
17
    {
18
        $this->setAdminPrefs();
19
20
        $meta_title = $title = 'TV Shows List';
21
22
        $tvshowname = ($request->has('showname') && ! empty($request->input('showname')) ? $request->input('showname') : '');
23
24
        $this->smarty->assign(
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

24
        $this->smarty->/** @scrutinizer ignore-call */ 
25
                       assign(

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...
25
            [
26
                'showname'          => $tvshowname,
27
                'tvshowlist'        => Video::getRange($tvshowname),
28
            ]
29
        );
30
31
        $content = $this->smarty->fetch('show-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

31
        /** @scrutinizer ignore-call */ 
32
        $content = $this->smarty->fetch('show-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...
32
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
33
        $this->adminrender();
34
    }
35
36
    /**
37
     * @param \Illuminate\Http\Request $request
38
     * @throws \Exception
39
     */
40
    public function edit(Request $request)
41
    {
42
        $this->setAdminPrefs();
43
44
        switch ($request->input('action') ?? 'view') {
45
            case 'submit':
46
                if ($request->has('from') && ! empty($request->input('from'))) {
47
                    header('Location:'.$request->input('from'));
48
                    exit;
49
                }
50
51
                header('Location:'.url('admin/show-list'));
0 ignored issues
show
Bug introduced by
Are you sure url('admin/show-list') of type Illuminate\Contracts\Routing\UrlGenerator|string can be used in concatenation? ( Ignorable by Annotation )

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

51
                header('Location:'./** @scrutinizer ignore-type */ url('admin/show-list'));
Loading history...
52
                break;
53
54
            case 'view':
55
            default:
56
                if ($request->has('id')) {
57
                    $title = 'TV Show Edit';
0 ignored issues
show
Unused Code introduced by
The assignment to $title is dead and can be removed.
Loading history...
58
                    $show = Video::getByVideoID($request->input('id'));
59
                }
60
                break;
61
        }
62
63
        $this->smarty->assign('show', $show);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $show does not seem to be defined for all execution paths leading up to this point.
Loading history...
64
65
        $meta_title = $title = 'Edit TV Show Data';
66
        $content = $this->smarty->fetch('show-edit.tpl');
67
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
68
        $this->adminrender();
69
    }
70
71
    /**
72
     * @param $id
73
     *
74
     * @throws \Exception
75
     */
76
    public function destroy($id)
77
    {
78
        $this->setAdminPrefs();
79
80
        $success = false;
81
82
        if ($id) {
83
            $success = Release::removeVideoIdFromReleases($id);
84
            $this->smarty->assign('videoid', $id);
85
        }
86
87
        $this->smarty->assign('success', $success);
88
89
        $meta_title = $title = 'Remove Video and Episode IDs from Releases';
90
        $content = $this->smarty->fetch('show-remove.tpl');
91
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
92
        $this->adminrender();
93
    }
94
}
95