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

AdminAnidbController::index()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 22
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use App\Models\Release;
7
use Blacklight\AniDB;
8
9
class AdminAnidbController extends BasePageController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function index()
15
    {
16
        $this->setAdminPrefs();
17
18
        $AniDB = new AniDB();
19
        $title = $meta_title = 'AniDB List';
20
21
        $aname = '';
22
        if (request()->has('animetitle') && ! empty(request()->input('animetitle'))) {
23
            $aname = request()->input('animetitle');
24
        }
25
26
        $this->smarty->assign('animetitle', $aname);
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

26
        $this->smarty->/** @scrutinizer ignore-call */ 
27
                       assign('animetitle', $aname);

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...
27
28
        $anidblist = $AniDB->getAnimeRange($aname);
29
        $this->smarty->assign('anidblist', $anidblist);
30
31
        $content = $this->smarty->fetch('anidb-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('anidb-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
33
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
34
35
        $this->adminrender();
36
    }
37
38
    /**
39
     * @param $id
40
     *
41
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
42
     * @throws \Exception
43
     */
44
    public function edit($id)
45
    {
46
        $this->setAdminPrefs();
47
48
        $AniDB = new AniDB();
49
50
        // Set the current action.
51
        $action = request()->input('action') ?? 'view';
52
53
        switch ($action) {
54
            case 'submit':
55
                $AniDB->updateTitle(
56
                    request()->input('anidbid'),
57
                    request()->input('title'),
58
                    request()->input('type'),
59
                    request()->input('startdate'),
60
                    request()->input('enddate'),
61
                    request()->input('related'),
62
                    request()->input('similar'),
63
                    request()->input('creators'),
64
                    request()->input('description'),
65
                    request()->input('rating'),
66
                    request()->input('categories'),
67
                    request()->input('characters'),
68
                    request()->input('epnos'),
69
                    request()->input('airdates'),
70
                    request()->input('episodetitles')
71
                );
72
73
                return redirect('admin/anidb-list');
74
                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...
75
76
            case 'view':
77
            default:
78
                if (! empty($id)) {
79
                    $this->title = 'AniDB Edit';
80
                    $AniDBAPIArray = $AniDB->getAnimeInfo($id);
81
                    $this->smarty->assign('anime', $AniDBAPIArray);
82
                }
83
                break;
84
        }
85
86
        $title = 'Edit AniDB Data';
87
        $content = $this->smarty->fetch('anidb-edit.tpl');
88
89
        $this->smarty->assign(compact('title', 'content'));
90
91
        $this->adminrender();
92
    }
93
94
    /**
95
     * Remove the specified resource from storage.
96
     *
97
     * @param  int $id
98
     *
99
     * @throws \Exception
100
     */
101
    public function destroy($id)
102
    {
103
        $this->setAdminPrefs();
104
105
        $success = false;
106
107
        if (request()->has('id')) {
108
            $success = Release::removeAnidbIdFromReleases($id);
109
            $this->smarty->assign('anidbid', $id);
110
        }
111
        $this->smarty->assign('success', $success);
112
113
        $title = 'Remove anidbID from Releases';
114
        $content = $this->smarty->fetch('anidb-remove.tpl');
115
        $this->smarty->assign(compact('title', 'content'));
116
        $this->adminrender();
117
    }
118
}
119