TagController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 3
Metric Value
c 7
b 0
f 3
dl 0
loc 7
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\Task;
7
use App\Transformers\TagTransformer;
8
use Illuminate\Http\Response as IlluminateResponse;
9
use Illuminate\Http\Request;
10
11
use App\Http\Requests;
12
use App\Http\Controllers\Controller;
13
use Illuminate\Support\Facades\Input;
14
use Illuminate\Support\Facades\Response;
15
16
class TagController extends ApiController
17
{
18
    /**
19
     * @var TagTransformer
20
     */
21
    protected $tagTransformer;
22
    /**
23
     * TagController constructor.
24
     * @param $tagTransformer
25
     */
26
    public function __construct(TagTransformer $tagTransformer)
27
    {
28
        $this->tagTransformer = $tagTransformer;
29
    }
30
    /**
31
     * Display a listing of the resource.
32
     * @param null $taskId
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function index($taskId = null)
36
    {
37
        //1. No és retorna: paginació
38
        //return Tag::all();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
39
        $tag = $this->getTags($taskId);
40
        return $this->respond($this->tagTransformer->transformCollection($tag->all()));
41
    }
42
    /**
43
     * Show the form for creating a new resource.
44
     *
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function create()
48
    {
49
        //
50
    }
51
    /**
52
     * Store a newly created resource in storage.
53
     *  @return \Illuminate\Http\Response
54
     */
55
    public function store()
56
    {
57
        if (!Input::get('title'))
58
        {
59
            return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
60
                ->respondWithError('Parameters failed validation for a task.');
61
        }
62
        Tag::create(Input::all());
63
        return $this->respondCreated('Task successfully created.');
64
    }
65
    /**
66
     * Display the specified resource.
67
     *
68
     * @param  int $id
69
     * @return \Illuminate\Http\Response
70
     */
71 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...
72
    {
73
        $tag = Tag::find($id);
74
        if (!$tag) {
75
            return $this->respondNotFound('Tag does not exsist');
76
        }
77
        return $this->respond([
78
            'data' => $this->tagTransformer->transform($tag)
79
        ]);
80
    }
81
    /**
82
     * Show the form for editing the specified resource.
83
     *
84
     * @param  int $id
85
     * @return \Illuminate\Http\Response
86
     */
87
    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...
88
    {
89
        //
90
    }
91
    /**
92
     * Update the specified resource in storage.
93
     *
94
     * @param  \Illuminate\Http\Request $request
95
     * @param  int $id
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function update(Request $request, $id)
99
    {
100
        $tag = Tag::find($id);
101
        if (!$tag)
102
        {
103
            return $this->respondNotFound('Tag does not exist!');
104
        }
105
        $tag->title = $request->title;
106
        $tag->save();
107
    }
108
    /**
109
     * Remove the specified resource from storage.
110
     *
111
     * @param  int $id
112
     * @return \Illuminate\Http\Response
113
     */
114
    public function destroy($id)
115
    {
116
        Tag::destroy($id);
117
    }
118
    /**
119
     * @param $taskId
120
     * @return \Illuminate\Database\Eloquent\Collection|static[]
121
     */
122
    public function getTags($taskId)
123
    {
124
        return $taskId ? Task::findOrFail($taskId)->tags : Tag::all();
125
    }
126
127
}
128