|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Acme\Transformers\TagTransformer; |
|
6
|
|
|
use App\Tag; |
|
7
|
|
|
use App\Task; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
use Illuminate\Http\Response as IlluminateResponse; |
|
10
|
|
|
use Illuminate\Support\Facades\Input; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class TagController |
|
14
|
|
|
* @package App\Http\Controllers |
|
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
|
|
|
/** |
|
32
|
|
|
* Display a listing of the resource. |
|
33
|
|
|
* @param null $taskId |
|
34
|
|
|
* @return \Illuminate\Http\Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function index($taskId = null) |
|
37
|
|
|
{ |
|
38
|
|
|
//1. No és retorna: paginació |
|
39
|
|
|
//return Tag::all(); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$tag = $this->getTags($taskId); |
|
42
|
|
|
return $this->respond($this->tagTransformer->transformCollection($tag->all())); |
|
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
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!Input::get('title')) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY) |
|
64
|
|
|
->respondWithError('Parameters failed validation for a task.'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
Tag::create(Input::all()); |
|
68
|
|
|
|
|
69
|
|
|
return $this->respondCreated('Task successfully created.'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Display the specified resource. |
|
74
|
|
|
* |
|
75
|
|
|
* @param int $id |
|
76
|
|
|
* @return \Illuminate\Http\Response |
|
77
|
|
|
*/ |
|
78
|
|
View Code Duplication |
public function show($id) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$tag = Tag::find($id); |
|
81
|
|
|
|
|
82
|
|
|
if (!$tag) { |
|
83
|
|
|
return $this->respondNotFound('Tag does not exsist'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->respond([ |
|
87
|
|
|
'data' => $this->tagTransformer->transform($tag) |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Show the form for editing the specified resource. |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $id |
|
95
|
|
|
* @return \Illuminate\Http\Response |
|
96
|
|
|
*/ |
|
97
|
|
|
public function edit($id) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
// |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Update the specified resource in storage. |
|
104
|
|
|
* |
|
105
|
|
|
* @param \Illuminate\Http\Request $request |
|
106
|
|
|
* @param int $id |
|
107
|
|
|
* @return \Illuminate\Http\Response |
|
108
|
|
|
*/ |
|
109
|
|
|
public function update(Request $request, $id) |
|
110
|
|
|
{ |
|
111
|
|
|
$tag = Tag::find($id); |
|
112
|
|
|
if (!$tag) |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->respondNotFound('Tag does not exist!'); |
|
115
|
|
|
} |
|
116
|
|
|
$tag->title = $request->title; |
|
|
|
|
|
|
117
|
|
|
$tag->save(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Remove the specified resource from storage. |
|
122
|
|
|
* |
|
123
|
|
|
* @param int $id |
|
124
|
|
|
* @return \Illuminate\Http\Response |
|
125
|
|
|
*/ |
|
126
|
|
|
public function destroy($id) |
|
127
|
|
|
{ |
|
128
|
|
|
Tag::destroy($id); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param $taskId |
|
133
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getTags($taskId) |
|
136
|
|
|
{ |
|
137
|
|
|
return $taskId ? Task::findOrFail($taskId)->tags : Tag::all(); |
|
138
|
|
|
} |
|
139
|
|
|
} |
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.