pdavila13 /
tasksAPI
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\Task; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | |||
| 8 | use App\Http\Requests; |
||
| 9 | use App\Http\Controllers\Controller; |
||
| 10 | use Response; |
||
| 11 | |||
| 12 | class TaskController extends Controller { |
||
| 13 | /** |
||
| 14 | * TaskController constructor. |
||
| 15 | */ |
||
| 16 | public function __construct(){ |
||
| 17 | //$this->middleware('auth:api'); |
||
|
0 ignored issues
–
show
|
|||
| 18 | } |
||
| 19 | |||
| 20 | |||
| 21 | /** |
||
| 22 | * Display a listing of the resource. |
||
| 23 | * |
||
| 24 | * @return \Illuminate\Http\Response |
||
| 25 | */ |
||
| 26 | public function index() { |
||
| 27 | // 1. No es retorna: paginacion |
||
| 28 | //return Task::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...
|
|||
| 29 | |||
| 30 | $task = Task::all(); |
||
| 31 | |||
| 32 | return Response::json([ |
||
| 33 | 'data' => $this->transformCollection($task) |
||
| 34 | //'data' => $task->toArray() |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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 | ],200); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Show the form for creating a new resource. |
||
| 40 | * |
||
| 41 | * @return \Illuminate\Http\Response |
||
| 42 | */ |
||
| 43 | public function create() { |
||
| 44 | // |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Store a newly created resource in storage. |
||
| 49 | * |
||
| 50 | * @param \Illuminate\Http\Request $request |
||
| 51 | * @return \Illuminate\Http\Response |
||
| 52 | */ |
||
| 53 | public function store(Request $request) { |
||
| 54 | $task = new Task(); |
||
| 55 | |||
| 56 | $this->saveTask($request, $task); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Display the specified resource. |
||
| 61 | * |
||
| 62 | * @param int $id |
||
| 63 | * @return \Illuminate\Http\Response |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function show($id) { |
|
|
0 ignored issues
–
show
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...
|
|||
| 66 | //return $tag = Task::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...
|
|||
| 67 | |||
| 68 | $task = Task::find($id); |
||
| 69 | |||
| 70 | if (!$task) { |
||
| 71 | return Response::json([ |
||
| 72 | 'error' => [ |
||
| 73 | 'message' => 'Task does not exist', |
||
| 74 | 'code' => 195 |
||
| 75 | ] |
||
| 76 | ], 404); |
||
| 77 | } |
||
| 78 | |||
| 79 | return Response::json([ |
||
| 80 | 'data' => $this->transform($task->toArray()) |
||
| 81 | //'data' => $task->toArray() |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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...
|
|||
| 82 | ],200); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Show the form for editing the specified resource. |
||
| 87 | * |
||
| 88 | * @param int $id |
||
| 89 | * @return \Illuminate\Http\Response |
||
| 90 | */ |
||
| 91 | public function edit($id) { |
||
|
0 ignored issues
–
show
|
|||
| 92 | // |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Update the specified resource in storage. |
||
| 97 | * |
||
| 98 | * @param \Illuminate\Http\Request $request |
||
| 99 | * @param int $id |
||
| 100 | * @return \Illuminate\Http\Response |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function update(Request $request, $id) { |
|
|
0 ignored issues
–
show
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...
|
|||
| 103 | //$task = Task::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...
|
|||
| 104 | |||
| 105 | $task = Task::find($id); |
||
| 106 | |||
| 107 | if (!$task) { |
||
| 108 | return Response::json([ |
||
| 109 | 'error' => [ |
||
| 110 | 'message' => 'Task does not exist', |
||
| 111 | 'code' => 195 |
||
| 112 | ] |
||
| 113 | ], 404); |
||
| 114 | } |
||
| 115 | |||
| 116 | return Response::json([ |
||
| 117 | 'data' => $task->toArray() |
||
| 118 | ],200); |
||
| 119 | |||
| 120 | $this->saveTask($request, $task); |
||
|
0 ignored issues
–
show
$this->saveTask($request, $task); 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 function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last Loading history...
|
|||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Remove the specified resource from storage. |
||
| 125 | * |
||
| 126 | * @param int $id |
||
| 127 | * @return \Illuminate\Http\Response |
||
| 128 | */ |
||
| 129 | public function destroy($id) { |
||
| 130 | Task::destroy($id); |
||
| 131 | } |
||
| 132 | |||
| 133 | public function transformCollection($task) { |
||
| 134 | return array_map([$this, 'transform'], $task->toArray()); |
||
| 135 | } |
||
| 136 | |||
| 137 | private function transform($task){ |
||
| 138 | return [ |
||
| 139 | 'name' => $task['name'], |
||
| 140 | 'priority' => (boolean) $task['priority'], |
||
| 141 | 'done' => $task['done'] |
||
| 142 | ]; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param Request $request |
||
| 147 | * @param $tag |
||
| 148 | */ |
||
| 149 | public function saveTask(Request $request, $task) { |
||
| 150 | $task->name = $request->name; |
||
| 151 | $task->priority = $request->priority; |
||
| 152 | $task->done = $request->done; |
||
| 153 | $task->save(); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
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.