TagController::transform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Tag;
6
use App\Transformers\TagTransformer;
7
use Illuminate\Http\Request;
8
9
use App\Http\Requests;
10
use App\Http\Controllers\Controller;
11
use Response;
12
13
class TagController extends Controller {
14
    /**
15
     * TagController constructor.
16
     */
17
    public function __construct() {
18
        // $this->middleware('auth:api');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
19
    }
20
21
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function index() {
28
29
        $tag = Tag::all();
30
31
        return Response::json([
32
            'data' => $this->transformCollection($tag)
33
        ],200);
34
    }
35
36
    /**
37
     * Show the form for creating a new resource.
38
     *
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function create() {
42
        //
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param  \Illuminate\Http\Request  $request
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function store(Request $request) {
52
        $tag = new Tag();
53
54
        $this->saveTag($request, $tag);
55
    }
56
57
    /**
58
     * Display the specified resource.
59
     *
60
     * @param  int  $id
61
     * @return \Illuminate\Http\Response
62
     */
63 View Code Duplication
    public function show($id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
        //return $tag = Tag::findOrFail($id);
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...
65
        //$tag = Tag::where('id',$id)->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
66
67
        $tag = Tag::find($id);
68
69
        if (!$tag) {
70
            return Response::json([
71
                'error' => [
72
                    'message' => 'Tag does not exist',
73
                    'code' => 195
74
                ]
75
            ], 404);
76
        }
77
78
        return Response::json([
79
            'data' => $this->transform($tag->toArray())
80
        ],200);
81
    }
82
83
    /**
84
     * Show the form for editing the specified resource.
85
     *
86
     * @param  int  $id
87
     * @return \Illuminate\Http\Response
88
     */
89
    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...
90
        //
91
    }
92
93
    /**
94
     * Update the specified resource in storage.
95
     *
96
     * @param  \Illuminate\Http\Request  $request
97
     * @param  int  $id
98
     * @return \Illuminate\Http\Response
99
     */
100 View Code Duplication
    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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
        //$tag = Tag::findOrFail($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
102
103
        $tag = Tag::find($id);
104
105
        if (!$tag) {
106
            return Response::json([
107
                'error' => [
108
                    'message' => 'Task does not exist',
109
                    'code' => 195
110
                ]
111
            ], 404);
112
        }
113
114
        return Response::json([
115
            'data' => $tag->toArray()
116
        ],200);
117
118
        $this->saveTag($request, $tag);
0 ignored issues
show
Unused Code introduced by
$this->saveTag($request, $tag); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
119
    }
120
121
    /**
122
     * Remove the specified resource from storage.
123
     *
124
     * @param  int  $id
125
     * @return \Illuminate\Http\Response
126
     */
127
    public function destroy($id) {
128
        Tag::destroy($id);
129
    }
130
131
    public function transformCollection($tag) {
132
        return array_map([$this, 'transform'], $tag->toArray());
133
    }
134
135
    private function transform($tag){
136
        return [
137
            'name' => $tag['name']
138
        ];
139
    }
140
141
    /**
142
     * @param Request $request
143
     * @param $tag
144
     */
145
    public function saveTag(Request $request, $tag) {
146
        $tag->name = $request->name;
1 ignored issue
show
Bug introduced by
The property name does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
147
        $tag->save();
148
    }
149
}
150