ProjectController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Moderator;
4
use App;
5
use App\Comment;
6
use App\Creator;
7
use App\Project;
8
use Illuminate\Http\Request;
9
10
use App\Http\Requests;
11
use App\Http\Controllers\Controller;
12
13
class ProjectController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index()
21
    {
22
        $data = [
23
            'projects' => Project::all(),
24
            'commentLast' => Comment::all()->sortByDesc('id')->take(4),
25
            ];
26
        return view('Admin.moderator.project')->with($data);
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
27
    }
28
29
    /**
30
     * Show the form for creating a new resource.
31
     *
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function create()
35
    {
36
        //
37
    }
38
39
    /**
40
     * Store a newly created resource in storage.
41
     *
42
     * @param  \Illuminate\Http\Request  $request
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function store(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        //
48
    }
49
50
    /**
51
     * Display the specified resource.
52
     *
53
     * @param  int  $id
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function show($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        //
59
    }
60
61
    /**
62
     * Show the form for editing the specified resource.
63
     *
64
     * @param  int  $id
65
     * @return \Illuminate\Http\Response
66
     */
67
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        //
70
    }
71
72
    /**
73
     * Update the specified resource in storage.
74
     *
75
     * @param  \Illuminate\Http\Request  $request
76
     * @param  int  $id
77
     * @return \Illuminate\Http\Response
78
     */
79
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        //
82
    }
83
84
    /**
85
     * Remove the specified resource from storage.
86
     *
87
     * @param  int  $id
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function destroy($id)
91
    {
92
        $project = Project::findOrFail($id);
93
        $project->delete();
94
        return redirect(route('moderator.project.index'));
95
    }
96
}
97