maksymkhar /
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\Acme\Transformers\TaskTransformer; |
|||||||||||
| 6 | use App\Task; |
|||||||||||
| 7 | use Illuminate\Http\Request; |
|||||||||||
| 8 | ||||||||||||
| 9 | use App\Http\Requests; |
|||||||||||
| 10 | use Illuminate\Support\Facades\Input; |
|||||||||||
| 11 | use Response; |
|||||||||||
| 12 | ||||||||||||
| 13 | class TaskController extends ApiController |
|||||||||||
| 14 | { |
|||||||||||
| 15 | protected $taskTranformer; |
|||||||||||
| 16 | ||||||||||||
| 17 | function __construct(TaskTransformer $taskTransformer) |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 18 | { |
|||||||||||
| 19 | $this->taskTransformer = $taskTransformer; |
|||||||||||
|
0 ignored issues
–
show
The property
taskTransformer does not seem to exist. Did you mean taskTranformer?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
||||||||||||
| 20 | ||||||||||||
| 21 | // TODO: Post test not working with auth middlerare |
|||||||||||
| 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 | } |
|||||||||||
| 24 | ||||||||||||
| 25 | /** |
|||||||||||
| 26 | * Display a listing of the resource. |
|||||||||||
| 27 | * |
|||||||||||
| 28 | * @return \Illuminate\Http\Response |
|||||||||||
| 29 | */ |
|||||||||||
| 30 | public function index() |
|||||||||||
| 31 | { |
|||||||||||
| 32 | $tasks = Task::all(); |
|||||||||||
| 33 | ||||||||||||
| 34 | return $this->respond($this->taskTransformer->transformCollection($tasks))->setStatusCode(200); |
|||||||||||
|
0 ignored issues
–
show
The property
taskTransformer does not seem to exist. Did you mean taskTranformer?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
||||||||||||
| 35 | } |
|||||||||||
| 36 | ||||||||||||
| 37 | /** |
|||||||||||
| 38 | * Show the form for creating a new resource. |
|||||||||||
| 39 | * |
|||||||||||
| 40 | * @return \Illuminate\Http\Response |
|||||||||||
| 41 | */ |
|||||||||||
| 42 | public function create() |
|||||||||||
| 43 | { |
|||||||||||
| 44 | // |
|||||||||||
| 45 | } |
|||||||||||
| 46 | ||||||||||||
| 47 | /** |
|||||||||||
| 48 | * Store a newly created resource in storage. |
|||||||||||
| 49 | * |
|||||||||||
| 50 | * @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...
|
||||||||||||
| 51 | * @return \Illuminate\Http\Response |
|||||||||||
| 52 | */ |
|||||||||||
| 53 | public function store() |
|||||||||||
| 54 | { |
|||||||||||
| 55 | if (!Input::get('name') or !Input::get('priority') or !Input::get('done')) |
|||||||||||
|
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...
|
||||||||||||
| 56 | { |
|||||||||||
| 57 | return $this->setStatusCode(422)->respondWithError('Parameters failed validation for a task'); |
|||||||||||
| 58 | } |
|||||||||||
| 59 | ||||||||||||
| 60 | Task::create(Input::all()); |
|||||||||||
| 61 | ||||||||||||
| 62 | return $this->respondCreated('Task successfully created.'); |
|||||||||||
| 63 | } |
|||||||||||
| 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
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 | $task = Task::find($id); |
|||||||||||
| 74 | ||||||||||||
| 75 | if (!$task) |
|||||||||||
| 76 | { |
|||||||||||
| 77 | return $this->respondNotFound('Task does not exist'); |
|||||||||||
|
0 ignored issues
–
show
The return type of
return $this->respondNot...'Task does not exist'); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\TaskController::show of type Illuminate\Http\Response.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
||||||||||||
| 78 | } |
|||||||||||
| 79 | ||||||||||||
| 80 | return $this->respond($this->taskTransformer->transform($task))->setStatusCode(200); |
|||||||||||
|
0 ignored issues
–
show
The property
taskTransformer does not seem to exist. Did you mean taskTranformer?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
||||||||||||
| 81 | } |
|||||||||||
| 82 | ||||||||||||
| 83 | /** |
|||||||||||
| 84 | * Show the form for editing the specified resource. |
|||||||||||
| 85 | * |
|||||||||||
| 86 | * @param int $id |
|||||||||||
| 87 | * @return \Illuminate\Http\Response |
|||||||||||
| 88 | */ |
|||||||||||
| 89 | public function edit($id) |
|||||||||||
|
0 ignored issues
–
show
|
||||||||||||
| 90 | { |
|||||||||||
| 91 | // |
|||||||||||
| 92 | } |
|||||||||||
| 93 | ||||||||||||
| 94 | /** |
|||||||||||
| 95 | * Update the specified resource in storage. |
|||||||||||
| 96 | * |
|||||||||||
| 97 | * @param \Illuminate\Http\Request $request |
|||||||||||
| 98 | * @param int $id |
|||||||||||
| 99 | * @return \Illuminate\Http\Response |
|||||||||||
| 100 | */ |
|||||||||||
| 101 | public function update(Request $request, $id) |
|||||||||||
| 102 | { |
|||||||||||
| 103 | $task = Task::find($id); |
|||||||||||
| 104 | ||||||||||||
| 105 | if (!$task) |
|||||||||||
| 106 | { |
|||||||||||
| 107 | return $this->respondNotFound('Task does not exist!!'); |
|||||||||||
| 108 | } |
|||||||||||
| 109 | ||||||||||||
| 110 | $task->name = $request->name; |
|||||||||||
| 111 | $task->priority = $request->priority; |
|||||||||||
| 112 | $task->done = $request->done; |
|||||||||||
| 113 | $task->save(); |
|||||||||||
| 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 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.