Passed
Pull Request — master (#610)
by John
22:48
created

ImageHostingController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Tool;
4
5
use App\Models\Eloquent\Tool\ImageHosting;
6
use App\Models\Eloquent\User;
7
use App\Http\Controllers\Controller;
8
use Auth;
9
10
class ImageHostingController extends Controller
11
{
12
    /**
13
     * Show the Image Hosting Create Page.
14
     *
15
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Tool\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
16
     */
17
    public function create()
18
    {
19
        return view('tool.imagehosting.create', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('tool.imageh...()->hasPermission(26))) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Tool\Response.
Loading history...
20
            'page_title' => "Create",
21
            'site_title' => "Image Hosting",
22
            'navigation' => "Image Hosting",
23
            'permission' => Auth::user()->hasPermission(26)
0 ignored issues
show
Bug introduced by
The method hasPermission() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            'permission' => Auth::user()->/** @scrutinizer ignore-call */ hasPermission(26)
Loading history...
24
        ]);
25
    }
26
27
    /**
28
     * Show the Image Hosting Detail Page.
29
     *
30
     * @return Response
31
     */
32
    public function detail($id)
33
    {
34
        $image=ImageHosting::find($id);
35
        if (is_null($image)) {
36
            return abort('404');
0 ignored issues
show
Bug Best Practice introduced by
The expression return abort('404') returns the type void which is incompatible with the documented return type App\Http\Controllers\Tool\Response.
Loading history...
Bug introduced by
Are you sure the usage of abort('404') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
37
        }
38
        if (Auth::user()->id!=$image->user_id) {
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
            return abort('403');
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort('403') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug Best Practice introduced by
The expression return abort('403') returns the type void which is incompatible with the documented return type App\Http\Controllers\Tool\Response.
Loading history...
40
        }
41
        return view('tool.imagehosting.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('tool.imageh...g', 'image' => $image)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Tool\Response.
Loading history...
42
            'page_title' => "Detail",
43
            'site_title' => "Image Hosting",
44
            'navigation' => "Image Hosting",
45
            'image' => $image,
46
        ]);
47
    }
48
49
    /**
50
     * Show the Image Hosting List Page.
51
     *
52
     * @return Response
53
     */
54
    public function list()
55
    {
56
        $images=Auth::user()->imagehostings()->orderBy('created_at', 'desc')->get();
0 ignored issues
show
Bug introduced by
The method imagehostings() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $images=Auth::user()->/** @scrutinizer ignore-call */ imagehostings()->orderBy('created_at', 'desc')->get();
Loading history...
57
        return view('tool.imagehosting.list', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('tool.imageh..., 'images' => $images)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Tool\Response.
Loading history...
58
            'page_title' => "List",
59
            'site_title' => "Image Hosting",
60
            'navigation' => "Image Hosting",
61
            'images' => $images,
62
        ]);
63
    }
64
}
65