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

AdminGameController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use Blacklight\Games;
7
use Blacklight\Genres;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Carbon;
10
11
class AdminGameController extends BasePageController
12
{
13
    /**
14
     * @throws \Exception
15
     */
16
    public function index()
17
    {
18
        $this->setAdminPrefs();
19
        $game = new Games(['Settings' => null]);
20
21
        $meta_title = $title = 'Game List';
22
23
        $gamelist = $game->getRange();
24
25
        $this->smarty->assign('gamelist', $gamelist);
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('gamelist', $gamelist);

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
        $content = $this->smarty->fetch('game-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

27
        /** @scrutinizer ignore-call */ 
28
        $content = $this->smarty->fetch('game-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...
28
29
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
30
31
        $this->adminrender();
32
    }
33
34
    /**
35
     * @param \Illuminate\Http\Request $request
36
     *
37
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
38
     * @throws \Exception
39
     */
40
    public function edit(Request $request)
41
    {
42
        $this->setAdminPrefs();
43
        $games = new Games(['Settings' => null]);
44
        $gen = new Genres(['Settings' => null]);
45
        $meta_title = $title = 'Game Edit';
46
47
        // Set the current action.
48
        $action = $request->input('action') ?? 'view';
49
50
        if ($request->has('id')) {
51
            $id = $request->input('id');
52
            $game = $games->getGamesInfoById($id);
53
54
            if (! $game) {
55
                $this->show404();
56
            }
57
58
            switch ($action) {
59
                case 'submit':
60
                    $coverLoc = NN_COVERS.'games/'.$id.'.jpg';
61
62
                    if ($_FILES['cover']['size'] > 0) {
63
                        $tmpName = $_FILES['cover']['tmp_name'];
64
                        $file_info = getimagesize($tmpName);
65
                        if (! empty($file_info)) {
66
                            move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
67
                        }
68
                    }
69
70
                    $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
71
                    $request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $game['releasedate'] : Carbon::parse($request->input('releasedate'))->timestamp]);
72
73
                    $games->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('publisher'), $request->input('releasedate'), $request->input('esrb'), $request->input('cover'), $request->input('trailerurl'), $request->input('genre'));
74
75
                    return redirect('admin/game-list');
76
77
                    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...
78
79
                case 'view':
80
                default:
81
                    $this->smarty->assign('game', $game);
82
                    $this->smarty->assign('genres', $gen->getGenres(Genres::GAME_TYPE));
83
                    break;
84
            }
85
        }
86
87
        $content = $this->smarty->fetch('game-edit.tpl');
88
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
89
        $this->adminrender();
90
    }
91
}
92