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 | /** |
||
4 | * Todo Controller |
||
5 | * |
||
6 | * @license http://opensource.org/licenses/MIT The MIT License (MIT) |
||
7 | * @author Omar El Gabry <[email protected]> |
||
8 | */ |
||
9 | |||
10 | class TodoController extends Controller{ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | // override this method to perform any logic before calling action method as explained above |
||
13 | public function beforeAction(){ |
||
14 | |||
15 | parent::beforeAction(); |
||
16 | |||
17 | // define the actions in this Controller |
||
18 | $action = $this->request->param('action'); |
||
19 | |||
20 | // restrict the request to action methods |
||
21 | // $this->Security->requireAjax(['create', 'delete']); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
74% 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. ![]() |
|||
22 | $this->Security->requirePost(['create', 'delete']); |
||
0 ignored issues
–
show
The property
Security does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
23 | |||
24 | // define the expected form fields for every action if exist |
||
25 | View Code Duplication | switch($action){ |
|
0 ignored issues
–
show
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. ![]() |
|||
26 | case "create": |
||
27 | // you can exclude form fields if you don't care if they were sent with form fields or not |
||
28 | $this->Security->config("form", [ 'fields' => ['content']]); |
||
0 ignored issues
–
show
The property
Security does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
29 | break; |
||
30 | case "delete": |
||
31 | // If you want to disable validation for form tampering |
||
32 | // $this->Security->config("validateForm", false); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
70% 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. ![]() |
|||
33 | $this->Security->config("form", [ 'fields' => ['todo_id']]); |
||
0 ignored issues
–
show
The property
Security does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
34 | break; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | public function index(){ |
||
39 | |||
40 | // display todo list |
||
41 | $this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/todo/", Config::get('VIEWS_PATH') . 'todo/index.php'); |
||
42 | } |
||
43 | |||
44 | View Code Duplication | public function create(){ |
|
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. ![]() |
|||
45 | |||
46 | $content = $this->request->data("content"); |
||
47 | $todo = $this->todo->create(Session::getUserId(), $content); |
||
0 ignored issues
–
show
The property
todo does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
48 | |||
49 | if(!$todo){ |
||
50 | |||
51 | // in case of normal post request |
||
52 | Session::set('errors', $this->todo->errors()); |
||
0 ignored issues
–
show
The property
todo does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
53 | return $this->redirector->root("Todo"); |
||
54 | |||
55 | // in case of ajax |
||
56 | // $this->view->renderErrors($this->todo->errors()); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
69% 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. ![]() |
|||
57 | |||
58 | }else{ |
||
59 | |||
60 | // in case of normal post request |
||
61 | Session::set('success', "Todo has been created"); |
||
62 | return $this->redirector->root("Todo"); |
||
63 | |||
64 | // in case of ajax |
||
65 | // $this->view->renderJson(array("success" => "Todo has been created")); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
71% 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. ![]() |
|||
66 | } |
||
67 | } |
||
68 | |||
69 | public function delete(){ |
||
70 | |||
71 | $todoId = Encryption::decryptIdWithDash($this->request->data("todo_id")); |
||
72 | $this->todo->delete($todoId); |
||
0 ignored issues
–
show
The property
todo does not exist on object<TodoController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
73 | |||
74 | // in case of normal post request |
||
75 | Session::set('success', "Todo has been deleted"); |
||
76 | return $this->redirector->root("Todo"); |
||
77 | |||
78 | // in case of ajax |
||
79 | // $this->view->renderJson(array("success" => "Todo has been deleted")); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
71% 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. ![]() |
|||
80 | } |
||
81 | |||
82 | public function isAuthorized(){ |
||
83 | |||
84 | $action = $this->request->param('action'); |
||
85 | $role = Session::getUserRole(); |
||
86 | $resource = "todo"; |
||
87 | |||
88 | // only for admins |
||
89 | Permission::allow('admin', $resource, ['*']); |
||
90 | |||
91 | // only for normal users |
||
92 | Permission::allow('user', $resource, ['delete'], 'owner'); |
||
93 | |||
94 | $todoId = $this->request->data("todo_id"); |
||
95 | |||
96 | if(!empty($todoId)){ |
||
97 | $todoId = Encryption::decryptIdWithDash($todoId); |
||
98 | } |
||
99 | |||
100 | $config = [ |
||
101 | "user_id" => Session::getUserId(), |
||
102 | "table" => "todo", |
||
103 | "id" => $todoId]; |
||
104 | |||
105 | return Permission::check($role, $resource, $action, $config); |
||
106 | } |
||
107 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.