AnimeController   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 17
eloc 64
c 0
b 0
f 0
dl 0
loc 111
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B showList() 0 37 9
B showAnime() 0 41 7
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\AniDB;
7
use Blacklight\Releases;
8
use Illuminate\Http\Request;
9
10
class AnimeController extends BasePageController
11
{
12
    /**
13
     * @var AniDB
14
     */
15
    protected $aniDb;
16
17
    /**
18
     * @var Releases
19
     */
20
    protected $releases;
21
22
    /**
23
     * AnimeController constructor.
24
     *
25
     * @throws \Exception
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
        $this->aniDb = new AniDB;
31
        $this->releases = new Releases;
32
    }
33
34
    /**
35
     * @throws \Exception
36
     */
37
    public function showAnime(Request $request): void
38
    {
39
40
        if ($request->has('id') && ctype_digit($request->input('id'))) {
41
            // force the category to TV_ANIME as it should be for anime, as $catarray was NULL and we know the category for sure for anime
42
            $aniDbReleases = $this->releases->animeSearch($request->input('id'), 0, 1000, '', [Category::TV_ANIME], -1);
43
            $aniDbInfo = $this->aniDb->getAnimeInfo($request->input('id'));
44
            $title = $aniDbInfo->title;
45
            $meta_title = 'View Anime '.$aniDbInfo->title;
46
            $meta_keywords = 'view,anime,anidb,description,details';
47
            $meta_description = 'View '.$aniDbInfo->title.' Anime';
48
49
            if (! $this->releases && ! $aniDbInfo) {
50
                $this->smarty->assign('nodata', 'No releases and AniDB info for this series.');
0 ignored issues
show
Bug Best Practice introduced by
The property smarty does not exist on App\Http\Controllers\AnimeController. Did you maybe forget to declare it?
Loading history...
51
            } elseif (! $aniDbInfo) {
52
                $this->smarty->assign('nodata', 'No AniDB information for this series.');
53
            } elseif (! $aniDbReleases) {
54
                $this->smarty->assign('nodata', 'No releases for this series.');
55
            } else {
56
                $this->smarty->assign('animeEpisodeTitles', $aniDbReleases);
57
                $this->smarty->assign([
58
                    'animeAnidbid' => $aniDbInfo->anidbid,
59
                    'animeTitle' => $aniDbInfo->title,
60
                    'animeType' => $aniDbInfo->type,
61
                    'animePicture' => $aniDbInfo->picture,
62
                    'animeStartDate' => $aniDbInfo->startdate,
63
                    'animeEndDate' => $aniDbInfo->enddate,
64
                    'animeDescription' => $aniDbInfo->description,
65
                    'animeRating' => $aniDbInfo->rating,
66
                    'animeRelated' => $aniDbInfo->related,
67
                    'animeSimilar' => $aniDbInfo->similar,
68
                    'animeCategories' => $aniDbInfo->categories,
69
                    'animeCreators' => $aniDbInfo->creators,
70
                    'animeCharacters' => $aniDbInfo->characters,
71
                ]);
72
73
                $this->smarty->assign('nodata', '');
74
            }
75
            $content = $this->smarty->fetch('viewanime.tpl');
76
            $this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description'));
77
            $this->pagerender();
78
        }
79
    }
80
81
    /**
82
     * @throws \Exception
83
     */
84
    public function showList(Request $request): void
85
    {
86
        $letter = ($request->has('id') && preg_match('/^(0\-9|[A-Z])$/i', $request->input('id'))) ? $request->input('id') : '0-9';
87
88
        $animeTitle = ($request->has('title') && ! empty($request->input('title'))) ? $request->input('title') : '';
89
90
        if ($animeTitle !== '' && $request->missing('id')) {
91
            $letter = '';
92
        }
93
94
        $masterserieslist = $this->aniDb->getAnimeList($letter, $animeTitle);
95
96
        $title = 'Anime List';
97
        $meta_title = 'View Anime List';
98
        $meta_keywords = 'view,anime,series,description,details';
99
        $meta_description = 'View Anime List';
100
101
        $animelist = [];
102
        foreach ($masterserieslist as $s) {
103
            if (preg_match('/^[0-9]/', $s->title)) {
104
                $thisrange = '0-9';
105
            } else {
106
                preg_match('/([A-Z]).*/i', $s->title, $hits);
107
                $thisrange = strtoupper($hits[1]);
108
            }
109
            $animelist[$thisrange][] = $s;
110
        }
111
        ksort($animelist);
112
113
        $this->smarty->assign('animelist', $animelist);
0 ignored issues
show
Bug Best Practice introduced by
The property smarty does not exist on App\Http\Controllers\AnimeController. Did you maybe forget to declare it?
Loading history...
114
        $this->smarty->assign('animerange', range('A', 'Z'));
115
        $this->smarty->assign('animeletter', $letter);
116
        $this->smarty->assign('animetitle', $animeTitle);
117
        $content = $this->smarty->fetch('viewanimelist.tpl');
118
119
        $this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description'));
120
        $this->pagerender();
121
    }
122
}
123