rogermelich /
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\Acme\Transformers\TaskTransformer; |
|||||||||||
| 9 | use App\Http\Requests; |
|||||||||||
| 10 | use App\Http\Controllers\Controller; |
|||||||||||
| 11 | use Illuminate\Support\Facades\Input; |
|||||||||||
| 12 | use phpDocumentor\Reflection\DocBlock\Tag; |
|||||||||||
| 13 | use Symfony\Component\HttpFoundation\Response; |
|||||||||||
| 14 | ||||||||||||
| 15 | class TaskController extends Controller |
|||||||||||
| 16 | { |
|||||||||||
| 17 | protected $taskTransformer; |
|||||||||||
| 18 | /** |
|||||||||||
| 19 | * TaskController constructor. |
|||||||||||
| 20 | */ |
|||||||||||
| 21 | public function __construct(TaskTransformer $taskTransformer) |
|||||||||||
| 22 | { |
|||||||||||
| 23 | $this->taskTransformer = $taskTransformer; |
|||||||||||
| 24 | $this->middleware('auth.basic', ['only' => 'store']); |
|||||||||||
| 25 | $this->middleware("auth.api"); |
|||||||||||
| 26 | } |
|||||||||||
| 27 | ||||||||||||
| 28 | /** |
|||||||||||
| 29 | * Display a listing of the resource. |
|||||||||||
| 30 | * |
|||||||||||
| 31 | * @return \Illuminate\Http\Response |
|||||||||||
| 32 | */ |
|||||||||||
| 33 | public function index() |
|||||||||||
| 34 | { |
|||||||||||
| 35 | //problema 1, no retorna: paginació |
|||||||||||
| 36 | $task = Task::all(); |
|||||||||||
| 37 | return $this->respond([ |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 38 | 'data' => $this->taskTransformer->transformCollection($task->all()) |
|||||||||||
| 39 | ]); |
|||||||||||
| 40 | } |
|||||||||||
| 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 | /** |
|||||||||||
| 53 | * Store a newly created resource in storage. |
|||||||||||
| 54 | * |
|||||||||||
| 55 | * @param \Illuminate\Http\Request $request |
|||||||||||
| 56 | * @return \Illuminate\Http\Response |
|||||||||||
| 57 | */ |
|||||||||||
| 58 | public function store(Request $request) |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 59 | { |
|||||||||||
| 60 | if (! Input::get('name') or ! Input::get('done') or ! Input::get('priority')) |
|||||||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. Loading history...
|
||||||||||||
| 61 | { |
|||||||||||
| 62 | return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY) |
|||||||||||
|
0 ignored issues
–
show
The method
setStatusCode does not exist on object<App\Http\Controllers\TaskController>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
||||||||||||
| 63 | ->respondWithError('Parameters failed validation for a task.'); |
|||||||||||
| 64 | } |
|||||||||||
| 65 | Task::create(Input::all()); |
|||||||||||
| 66 | return $this->respondCreated('Task successfully created.'); |
|||||||||||
|
0 ignored issues
–
show
The method
respondCreated() does not exist on App\Http\Controllers\TaskController. Did you maybe mean create()?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. Loading history...
|
||||||||||||
| 67 | } |
|||||||||||
| 68 | ||||||||||||
| 69 | /** |
|||||||||||
| 70 | * Display the specified resource. |
|||||||||||
| 71 | * |
|||||||||||
| 72 | * @param int $id |
|||||||||||
| 73 | * @return \Illuminate\Http\Response |
|||||||||||
| 74 | */ |
|||||||||||
| 75 | public function show($id) |
|||||||||||
| 76 | { |
|||||||||||
| 77 | $task = Task::find($id); |
|||||||||||
| 78 | if (!$task) { |
|||||||||||
| 79 | return $this->respondNotFound('La tasca no existeix!'); |
|||||||||||
|
0 ignored issues
–
show
The method
respondNotFound does not exist on object<App\Http\Controllers\TaskController>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
||||||||||||
| 80 | } |
|||||||||||
| 81 | return $this->respond([ |
|||||||||||
|
0 ignored issues
–
show
The method
respond does not exist on object<App\Http\Controllers\TaskController>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
||||||||||||
| 82 | 'data' => $this->taskTransformer->transform($task) |
|||||||||||
| 83 | ]); |
|||||||||||
| 84 | ||||||||||||
| 85 | //return $task = 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...
|
||||||||||||
| 86 | ||||||||||||
| 87 | //Es el mateix |
|||||||||||
| 88 | //$task = Tag::where('id', $id)->first(); |
|||||||||||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% 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...
|
||||||||||||
| 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) |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 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 | $task = Task::findOrFail($id); |
|||||||||||
| 112 | ||||||||||||
| 113 | $this->saveTask($request, $task); |
|||||||||||
| 114 | } |
|||||||||||
| 115 | ||||||||||||
| 116 | /** |
|||||||||||
| 117 | * Remove the specified resource from storage. |
|||||||||||
| 118 | * |
|||||||||||
| 119 | * @param int $id |
|||||||||||
| 120 | * @return \Illuminate\Http\Response |
|||||||||||
| 121 | */ |
|||||||||||
| 122 | public function destroy($id) |
|||||||||||
| 123 | { |
|||||||||||
| 124 | Task::destroy($id); |
|||||||||||
| 125 | } |
|||||||||||
| 126 | ||||||||||||
| 127 | /** |
|||||||||||
| 128 | * @param Request $request |
|||||||||||
| 129 | * @param $task |
|||||||||||
| 130 | */ |
|||||||||||
| 131 | public function saveTask(Request $request, $task) |
|||||||||||
| 132 | { |
|||||||||||
| 133 | $task->name = $request->name; |
|||||||||||
| 134 | $task->done = $request->done; |
|||||||||||
| 135 | $task->priority = $request->priority; |
|||||||||||
| 136 | $task->save(); |
|||||||||||
| 137 | } |
|||||||||||
| 138 | ||||||||||||
| 139 | public function transform ($tasks){ |
|||||||||||
| 140 | return arry_map(function ($task){ |
|||||||||||
| 141 | return [ |
|||||||||||
| 142 | 'name' => $task['name'], |
|||||||||||
| 143 | 'text' => $task['text'], |
|||||||||||
| 144 | 'done' => $task['done'], |
|||||||||||
| 145 | ]; |
|||||||||||
| 146 | }, $tasks->toArray()); |
|||||||||||
| 147 | } |
|||||||||||
| 148 | } |
|||||||||||
| 149 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: