Completed
Push — dev ( 0e49c0...603655 )
by Darko
08:12
created

ShowsController::edit()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 29
rs 9.0111
c 0
b 0
f 0
cc 6
nc 6
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Models\Video;
6
use App\Models\Release;
7
use Illuminate\Http\Request;
8
use Blacklight\processing\tv\TV;
9
use App\Http\Controllers\BasePageController;
10
11
class ShowsController extends BasePageController
12
{
13
    /**
14
     * @param \Illuminate\Http\Request $request
15
     * @throws \Exception
16
     */
17
    public function index(Request $request)
18
    {
19
        $this->setAdminPrefs();
20
21
        $meta_title = $title = 'TV Shows List';
22
23
        $tvshowname = ($request->has('showname') && ! empty($request->input('showname')) ? $request->input('showname') : '');
24
25
        $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

25
        $this->smarty->/** @scrutinizer ignore-call */ 
26
                       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...
26
            [
27
                'showname'          => $tvshowname,
28
                'tvshowlist'        => Video::getRange($tvshowname),
29
            ]
30
        );
31
32
        $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

32
        /** @scrutinizer ignore-call */ 
33
        $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...
33
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
34
        $this->adminrender();
35
    }
36
37
    /**
38
     * @param \Illuminate\Http\Request $request
39
     * @throws \Exception
40
     */
41
    public function edit(Request $request)
42
    {
43
        $this->setAdminPrefs();
44
45
        switch ($request->input('action') ?? 'view') {
46
            case 'submit':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
47
                if ($request->has('from') && ! empty($request->input('from'))) {
48
                    header('Location:'.$request->input('from'));
49
                    exit;
50
                }
51
52
                header('Location:'.WWW_TOP.'admin/show-list');
0 ignored issues
show
Bug introduced by
The constant App\Http\Controllers\Admin\WWW_TOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
                break;
54
55
            case 'view':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
56
            default:
57
                if ($request->has('id')) {
58
                    $title = 'TV Show Edit';
0 ignored issues
show
Unused Code introduced by
The assignment to $title is dead and can be removed.
Loading history...
59
                    $show = Video::getByVideoID($request->input('id'));
60
                }
61
                break;
62
        }
63
64
        $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...
65
66
        $meta_title = $title = 'Edit TV Show Data';
67
        $content = $this->smarty->fetch('show-edit.tpl');
68
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
69
        $this->adminrender();
70
    }
71
72
    /**
73
     * @param $id
74
     *
75
     * @throws \Exception
76
     */
77
    public function destroy($id)
78
    {
79
        $this->setAdminPrefs();
80
81
        $success = false;
82
83
        if ($id) {
84
            $success = Release::removeVideoIdFromReleases($id);
85
            $this->smarty->assign('videoid', $id);
86
        }
87
88
        $this->smarty->assign('success', $success);
89
90
        $meta_title = $title = 'Remove Video and Episode IDs from Releases';
91
        $content = $this->smarty->fetch('show-remove.tpl');
92
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
93
        $this->adminrender();
94
    }
95
}
96