TagController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 9
c 4
b 0
f 1
lcom 1
cbo 5
dl 0
loc 115
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 13 1
A create() 0 4 1
A store() 0 5 1
A show() 0 16 2
A edit() 0 4 1
A update() 0 6 1
A destroy() 0 5 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
use App\Http\Requests;
8
use App\Http\Controllers\Controller;
9
use App\Tag;
10
use App\Http\Transformers\TagTransformer;
11
12
class TagController extends Controller
13
{
14
15
    protected $TagTransformer;
16
17
    /**
18
     * TagController constructor.
19
     * @param $tagTransformer
20
     */
21
    public function __construct(TagTransformer $tagTransformer)
22
    {
23
        $this->TagTransformer = $tagTransformer;
24
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function index()
32
    {
33
        $tags = Tag::get();
34
//        return response() -> json([
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
35
//            "msg" => "Success",
36
//            "tags" => $this->TagTransformer->transformCollection($tags),
37
//        ], 200
38
//        );
39
        return response() -> json(
40
            $this->TagTransformer->transformCollection($tags),
41
            200
42
        );
43
    }
44
45
    /**
46
     * Show the form for creating a new resource.
47
     *
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function create()
51
    {
52
        //
53
    }
54
55
    /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @param  \Illuminate\Http\Request  $request
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(Request $request)
62
    {
63
        Tag::create($request->all());
64
        return ['created' => true];
65
    }
66
67
    /**
68
     * Display the specified resource.
69
     *
70
     * @param  int  $id
71
     * @return \Illuminate\Http\Response
72
     */
73
    public function show($id)
74
    {
75
        $tag = Tag::find($id);
76
        if(!$tag){
77
            return response() -> json([
78
                "msg" => "does not exist"
79
            ], 404
80
            );
81
        }else{
82
            return response() -> json([
83
                "msg" => "Success",
84
                "tag" =>  $this->TagTransformer->transform($tag)
85
            ], 200
86
            );
87
        }
88
    }
89
90
    /**
91
     * Show the form for editing the specified resource.
92
     *
93
     * @param  int  $id
94
     * @return \Illuminate\Http\Response
95
     */
96
    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...
97
    {
98
        //
99
    }
100
101
    /**
102
     * Update the specified resource in storage.
103
     *
104
     * @param  \Illuminate\Http\Request  $request
105
     * @param  int  $id
106
     * @return \Illuminate\Http\Response
107
     */
108
    public function update(Request $request, $id)
109
    {
110
        $task = Tag::find($id);
111
        $task->update($request->all());
112
        return ['updated' => true];
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param  int  $id
119
     * @return \Illuminate\Http\Response
120
     */
121
    public function destroy($id)
122
    {
123
        Tag::destroy($id);
124
        return ['deleted' => true];
125
    }
126
}
127