Completed
Push — master ( f8f8d3...65f853 )
by Christopher
01:21
created

CategoryController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Chriscreates\Blog\Controllers;
4
5
use Chriscreates\Blog\Category;
6
use Chriscreates\Blog\Requests\ValidateCategoryRequest;
7
use Illuminate\Http\Request;
8
9
class CategoryController extends Controller
10
{
11
    /**
12
     * Display a listing of the resource.
13
     *
14
     * @return \Illuminate\Http\Response
15
     */
16
    public function index()
17
    {
18
    }
19
20
    /**
21
     * Show the form for creating a new resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function create()
26
    {
27
    }
28
29
    /**
30
     * Store a newly created resource in storage.
31
     *
32
     * @param  \Chriscreates\Blog\Requests\ValidateCategoryRequest  $request
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function store(ValidateCategoryRequest $request)
36
    {
37
        $category = Category::create($request->only([
38
            'name',
39
            'slug',
40
            'parent_id',
41
        ]));
42
43
        return response()->json($category);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
44
    }
45
46
    /**
47
     * Display the specified resource.
48
     *
49
     * @param  \Chriscreates\Blog\Category  $category
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function show(Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $category 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...
53
    {
54
    }
55
56
    /**
57
     * Show the form for editing the specified resource.
58
     *
59
     * @param  \Chriscreates\Blog\Category  $category
60
     * @return \Illuminate\Http\Response
61
     */
62
    public function edit(Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $category 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...
63
    {
64
    }
65
66
    /**
67
     * Update the specified resource in storage.
68
     *
69
     * @param  \Illuminate\Http\Request  $request
70
     * @param  \Chriscreates\Blog\Requests\ValidateCategoryRequest  $request
71
     * @return \Illuminate\Http\Response
72
     */
73
    public function update(ValidateCategoryRequest $request, Category $category)
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 $category 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...
74
    {
75
    }
76
77
    /**
78
     * Remove the specified resource from storage.
79
     *
80
     * @param  \Chriscreates\Blog\Category  $category
81
     * @return \Illuminate\Http\Response
82
     */
83
    public function destroy(Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $category 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...
84
    {
85
    }
86
}
87