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

AdminMusicController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 13 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\Genres;
7
use Blacklight\Music;
8
use Blacklight\utility\Utility;
9
use Illuminate\Http\Request;
10
11
class AdminMusicController extends BasePageController
12
{
13
    /**
14
     * @throws \Exception
15
     */
16
    public function index()
17
    {
18
        $this->setAdminPrefs();
19
20
        $meta_title = $title = 'Music List';
21
22
        $musicList = Utility::getRange('musicinfo');
23
24
        $this->smarty->assign('musiclist', $musicList);
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('musiclist', $musicList);

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('music-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('music-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
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
28
        $this->adminrender();
29
    }
30
31
    /**
32
     * @param \Illuminate\Http\Request $request
33
     *
34
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
35
     * @throws \Exception
36
     */
37
    public function edit(Request $request)
38
    {
39
        $this->setAdminPrefs();
40
        $music = new Music();
41
        $gen = new Genres();
42
43
        $meta_title = $title = 'Music Edit';
44
45
        // set the current action
46
        $action = $request->input('action') ?? 'view';
47
48
        if ($request->has('id')) {
49
            $id = $request->input('id');
50
            $mus = $music->getMusicInfo($id);
51
52
            if (! $mus) {
0 ignored issues
show
introduced by
$mus is of type App\Models\MusicInfo, thus it always evaluated to true.
Loading history...
53
                $this->show404();
54
            }
55
56
            switch ($action) {
57
                case 'submit':
58
                    $coverLoc = resource_path().'/covers/music/'.$id.'.jpg';
59
60
                    if ($_FILES['cover']['size'] > 0) {
61
                        $tmpName = $_FILES['cover']['tmp_name'];
62
                        $file_info = getimagesize($tmpName);
63
                        if (! empty($file_info)) {
64
                            move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
65
                        }
66
                    }
67
68
                    $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
69
                    $request->merge(['salesrank' => (empty($request->input('salesrank')) || ! ctype_digit($request->input('salesrank'))) ? 'null' : $request->input('salesrank')]);
70
                    $request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $mus['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...
71
72
                    $music->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('salesrank'), $request->input('artist'), $request->input('publisher'), $request->input('releasedate'), $request->input('year'), $request->input('tracks'), $request->input('cover'), $request->input('genre'));
73
74
                    return redirect('admin/music-list');
75
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('music', $mus);
80
                    $this->smarty->assign('genres', $gen->getGenres(Genres::MUSIC_TYPE));
81
                    break;
82
            }
83
        }
84
85
        $content = $this->smarty->fetch('music-edit.tpl');
86
        $this->smarty->assign(compact('title', 'meta_title', 'content'));
87
        $this->adminrender();
88
    }
89
}
90