Completed
Push — master ( f0ae9a...e62c50 )
by Christopher
01:15
created

TagController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 3 1
A store() 0 9 1
A edit() 0 3 1
A update() 0 3 1
A destroy() 0 3 1
1
<?php
2
3
namespace Chriscreates\Blog\Controllers;
4
5
use Chriscreates\Blog\Requests\ValidateTagRequest;
6
use Chriscreates\Blog\Tag;
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Http\Request;
9
10
class TagController extends Controller
11
{
12
    /**
13
     * Instantiate a new controller instance.
14
     *
15
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
16
     */
17
    public function __construct()
18
    {
19
        $this->middleware('auth');
20
    }
21
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function index() : JsonResponse
28
    {
29
    }
30
31
    /**
32
     * Store a newly created resource in storage.
33
     *
34
     * @param  \Chriscreates\Blog\Requests\ValidateTagRequest  $request
35
     * @return \Illuminate\Http\Response
36
     */
37
    public function store(ValidateTagRequest $request) : JsonResponse
38
    {
39
        $tag = Tag::create($request->only([
40
            'name',
41
            'slug',
42
        ]));
43
44
        return response()->json($tag);
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...
45
    }
46
47
    /**
48
     * Show the form for editing the specified resource.
49
     *
50
     * @param  \Chriscreates\Blog\Tag  $tag
51
     * @return \Illuminate\Http\Response
52
     */
53
    public function edit(Tag $tag) : JsonResponse
0 ignored issues
show
Unused Code introduced by
The parameter $tag 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...
54
    {
55
    }
56
57
    /**
58
     * Update the specified resource in storage.
59
     *
60
     * @param  \Chriscreates\Blog\Requests\ValidateTagRequest  $request
61
     * @param  \Chriscreates\Blog\Tag  $tag
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function update(ValidateTagRequest $request, Tag $tag) : JsonResponse
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 $tag 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...
65
    {
66
    }
67
68
    /**
69
     * Remove the specified resource from storage.
70
     *
71
     * @param  \Chriscreates\Blog\Tag  $tag
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function destroy(Tag $tag) : JsonResponse
0 ignored issues
show
Unused Code introduced by
The parameter $tag 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...
75
    {
76
    }
77
}
78