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

AdminConsoleController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 40
dl 0
loc 79
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 15 1
C edit() 0 51 12
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\BasePageController;
6
use Blacklight\Console;
7
use Blacklight\Genres;
8
use Blacklight\utility\Utility;
9
use Illuminate\Http\Request;
10
11
class AdminConsoleController extends BasePageController
12
{
13
    /**
14
     * @throws \Exception
15
     */
16
    public function index()
17
    {
18
        $this->setAdminPrefs();
19
20
        $meta_title = $title = 'Console List';
21
22
        $consoleList = Utility::getRange('consoleinfo');
23
24
        $this->smarty->assign('consolelist', $consoleList);
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('consolelist', $consoleList);

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

26
        /** @scrutinizer ignore-call */ 
27
        $content = $this->smarty->fetch('console-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...
27
28
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
29
30
        $this->adminrender();
31
    }
32
33
    /**
34
     * @param \Illuminate\Http\Request $request
35
     *
36
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
37
     * @throws \Exception
38
     */
39
    public function edit(Request $request)
40
    {
41
        $this->setAdminPrefs();
42
        $console = new Console(['Settings' => null]);
43
        $gen = new Genres();
44
        $meta_title = $title = 'Console Edit';
45
46
        // set the current action
47
        $action = $request->input('action') ?? 'view';
48
49
        if ($request->has('id')) {
50
            $id = $request->input('id');
51
            $con = $console->getConsoleInfo($id);
52
53
            if (! $con) {
54
                $this->show404();
55
            }
56
57
            switch ($action) {
58
                case 'submit':
59
                    $coverLoc = resource_path().'/covers/console/'.$id.'.jpg';
60
61
                    if ($_FILES['cover']['size'] > 0) {
62
                        $tmpName = $_FILES['cover']['tmp_name'];
63
                        $file_info = getimagesize($tmpName);
64
                        if (! empty($file_info)) {
65
                            move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
66
                        }
67
                    }
68
69
                    $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
70
                    $request->merge(['salesrank' => (empty($request->input('salesrank')) || ! ctype_digit($request->input('salesrank'))) ? 'null' : $request->input('salesrank')]);
71
                    $request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $con['releasedate'] : Carbon::parse($request->input('releasedate'))->timestamp]);
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Admin\Carbon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
73
                    $console->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('salesrank'), $request->input('platform'), $request->input('publisher'), $request->input('releasedate'), $request->input('esrb'), $request->input('cover'), $request->input('genre'));
74
75
                    return redirect('admin/console-list.');
76
                    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...
77
                case 'view':
78
                default:
79
                    $this->smarty->assign('console', $con);
80
                    $this->smarty->assign('genres', $gen->getGenres(Genres::CONSOLE_TYPE));
81
                    break;
82
            }
83
        }
84
85
        $content = $this->smarty->fetch('console-edit.tpl');
86
87
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
88
89
        $this->adminrender();
90
    }
91
}
92