sergipineda /
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 Illuminate\Support\Facades\Response; |
|||||||||||
| 11 | use App\Transformers\TaskTransformer; |
|||||||||||
| 12 | ||||||||||||
| 13 | ||||||||||||
| 14 | class TaskController extends Controller |
|||||||||||
| 15 | { |
|||||||||||
| 16 | /** |
|||||||||||
| 17 | * TaskController constructor. |
|||||||||||
| 18 | */ |
|||||||||||
| 19 | public function __construct(TaskTransformer $taskTransformer) |
|||||||||||
| 20 | { |
|||||||||||
| 21 | $this->TaskTransformer = $taskTransformer; |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 22 | //$this->middleware('auth.basic', ['only' => 'store']); |
|||||||||||
|
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...
|
||||||||||||
| 23 | $this->middleware('auth:api'); |
|||||||||||
| 24 | } |
|||||||||||
| 25 | ||||||||||||
| 26 | /** |
|||||||||||
| 27 | * Display a listing of the resource. |
|||||||||||
| 28 | * |
|||||||||||
| 29 | * @return \Illuminate\Http\Response |
|||||||||||
| 30 | */ |
|||||||||||
| 31 | public function index() |
|||||||||||
| 32 | { |
|||||||||||
| 33 | ||||||||||||
| 34 | $tasks = Task::all(); |
|||||||||||
| 35 | // |
|||||||||||
| 36 | // |
|||||||||||
| 37 | //$task = Task::all(); |
|||||||||||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% 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...
|
||||||||||||
| 38 | // return $this->respond([ |
|||||||||||
| 39 | // 'data' => $this->TaskTransformer->transformCollection($task->all()) |
|||||||||||
| 40 | // ]); |
|||||||||||
| 41 | ||||||||||||
| 42 | return Response::json( |
|||||||||||
| 43 | $this->TaskTransformer->transformCollection($tasks), |
|||||||||||
| 44 | 200 |
|||||||||||
| 45 | ); |
|||||||||||
| 46 | } |
|||||||||||
| 47 | ||||||||||||
| 48 | /** |
|||||||||||
| 49 | * Show the form for creating a new resource. |
|||||||||||
| 50 | * |
|||||||||||
| 51 | * @return \Illuminate\Http\Response |
|||||||||||
| 52 | */ |
|||||||||||
| 53 | public function create() |
|||||||||||
| 54 | { |
|||||||||||
| 55 | // |
|||||||||||
| 56 | } |
|||||||||||
| 57 | ||||||||||||
| 58 | /** |
|||||||||||
| 59 | * Store a newly created resource in storage. |
|||||||||||
| 60 | * |
|||||||||||
| 61 | * @param \Illuminate\Http\Request $request |
|||||||||||
|
0 ignored issues
–
show
There is no parameter named
$request. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
||||||||||||
| 62 | * @return \Illuminate\Http\Response |
|||||||||||
| 63 | */ |
|||||||||||
| 64 | public function store() |
|||||||||||
| 65 | { |
|||||||||||
| 66 | ||||||||||||
| 67 | View Code Duplication | 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...
This code seems to be duplicated across 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...
|
||||||||||||
| 68 | { |
|||||||||||
| 69 | 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...
|
||||||||||||
| 70 | ->respondWithError('Parameters failed validation for a task.'); |
|||||||||||
| 71 | } |
|||||||||||
| 72 | Task::create(Input::all()); |
|||||||||||
| 73 | 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...
|
||||||||||||
| 74 | ||||||||||||
| 75 | } |
|||||||||||
| 76 | ||||||||||||
| 77 | /** |
|||||||||||
| 78 | * Display the specified resource. |
|||||||||||
| 79 | * |
|||||||||||
| 80 | * @param int $id |
|||||||||||
| 81 | * @return \Illuminate\Http\Response |
|||||||||||
| 82 | */ |
|||||||||||
| 83 | public function show($id) |
|||||||||||
| 84 | { |
|||||||||||
| 85 | ||||||||||||
| 86 | $task = Task::find($id); |
|||||||||||
| 87 | // $task = Task::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...
|
||||||||||||
| 88 | ||||||||||||
| 89 | if (! $task){ |
|||||||||||
| 90 | return Response::json([ |
|||||||||||
| 91 | ||||||||||||
| 92 | 'error' => [ |
|||||||||||
| 93 | 'message' => 'La tasca no existeix', |
|||||||||||
| 94 | 'code' |
|||||||||||
| 95 | ] |
|||||||||||
| 96 | ], 404); |
|||||||||||
| 97 | } |
|||||||||||
| 98 | return Response::json([ |
|||||||||||
| 99 | $this->taskTransfomer->transform($task) |
|||||||||||
|
0 ignored issues
–
show
The property
taskTransfomer does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
||||||||||||
| 100 | ], 200); |
|||||||||||
| 101 | } |
|||||||||||
| 102 | ||||||||||||
| 103 | /** |
|||||||||||
| 104 | * Show the form for editing the specified resource. |
|||||||||||
| 105 | * |
|||||||||||
| 106 | * @param int $id |
|||||||||||
| 107 | * @return \Illuminate\Http\Response |
|||||||||||
| 108 | */ |
|||||||||||
| 109 | public function edit($id) |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 110 | { |
|||||||||||
| 111 | // |
|||||||||||
| 112 | } |
|||||||||||
| 113 | ||||||||||||
| 114 | /** |
|||||||||||
| 115 | * Update the specified resource in storage. |
|||||||||||
| 116 | * |
|||||||||||
| 117 | * @param \Illuminate\Http\Request $request |
|||||||||||
| 118 | * @param int $id |
|||||||||||
| 119 | * @return \Illuminate\Http\Response |
|||||||||||
| 120 | */ |
|||||||||||
| 121 | public function update(Request $request, $id) |
|||||||||||
| 122 | { |
|||||||||||
| 123 | $task = Task::findorFail($id); |
|||||||||||
| 124 | $this->saveTask($request, $task); |
|||||||||||
| 125 | } |
|||||||||||
| 126 | ||||||||||||
| 127 | /** |
|||||||||||
| 128 | * Remove the specified resource from storage. |
|||||||||||
| 129 | * |
|||||||||||
| 130 | * @param int $id |
|||||||||||
| 131 | * @return \Illuminate\Http\Response |
|||||||||||
| 132 | */ |
|||||||||||
| 133 | public function destroy($id) |
|||||||||||
| 134 | { |
|||||||||||
| 135 | Task::destroy($id); |
|||||||||||
| 136 | } |
|||||||||||
| 137 | ||||||||||||
| 138 | /** |
|||||||||||
| 139 | * @param Request $request |
|||||||||||
| 140 | * @param $task |
|||||||||||
| 141 | */ |
|||||||||||
| 142 | public function saveTask(Request $request, $task) |
|||||||||||
| 143 | { |
|||||||||||
| 144 | $task->name = $request->name; |
|||||||||||
| 145 | $task->priority = $request->priority; |
|||||||||||
| 146 | $task->done = $request->done; |
|||||||||||
| 147 | $task->save(); |
|||||||||||
| 148 | } |
|||||||||||
| 149 | ||||||||||||
| 150 | ||||||||||||
| 151 | } |
|||||||||||
| 152 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: