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 | * Posts controller |
||
5 | * |
||
6 | * @license http://opensource.org/licenses/MIT The MIT License (MIT) |
||
7 | * @author Omar El Gabry <[email protected]> |
||
8 | */ |
||
9 | |||
10 | class PostsController extends Controller{ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | |||
13 | public function beforeAction(){ |
||
14 | |||
15 | parent::beforeAction(); |
||
16 | |||
17 | Config::setJsConfig('curPage', "posts"); |
||
18 | |||
19 | $action = $this->request->param('action'); |
||
20 | $actions = ['create', 'update']; |
||
21 | $this->Security->requirePost($actions); |
||
0 ignored issues
–
show
The property
Security does not exist on object<PostsController> . 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. ![]() |
|||
22 | |||
23 | switch($action){ |
||
24 | case "create": |
||
25 | $this->Security->config("form", [ 'fields' => ['title', 'content']]); |
||
0 ignored issues
–
show
The property
Security does not exist on object<PostsController> . 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. ![]() |
|||
26 | break; |
||
27 | case "update": |
||
28 | $this->Security->config("form", [ 'fields' => ['post_id', 'title', 'content']]); |
||
0 ignored issues
–
show
The property
Security does not exist on object<PostsController> . 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 | $this->Security->config("validateCsrfToken", true); |
||
0 ignored issues
–
show
The property
Security does not exist on object<PostsController> . 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. ![]() |
|||
32 | $this->Security->config("form", [ 'fields' => ['post_id']]); |
||
0 ignored issues
–
show
The property
Security does not exist on object<PostsController> . 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. ![]() |
|||
33 | break; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * show posts page |
||
39 | * |
||
40 | */ |
||
41 | View Code Duplication | public function index(){ |
|
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. ![]() |
|||
42 | |||
43 | // clear all notifications |
||
44 | $this->user->clearNotifications(Session::getUserId(), $this->post->table); |
||
0 ignored issues
–
show
The property
user does not exist on object<PostsController> . 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. ![]() The property
post does not exist on object<PostsController> . 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. ![]() |
|||
45 | |||
46 | $pageNum = $this->request->query("page"); |
||
47 | |||
48 | $this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'posts/index.php', ['pageNum' => $pageNum]); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * view a post |
||
53 | * |
||
54 | * @param integer|string $postId |
||
55 | */ |
||
56 | public function view($postId = 0){ |
||
57 | |||
58 | $postId = Encryption::decryptId($postId); |
||
59 | |||
60 | if(!$this->post->exists($postId)){ |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
61 | return $this->error(404); |
||
62 | } |
||
63 | |||
64 | Config::setJsConfig('curPage', ["posts", "comments"]); |
||
65 | Config::setJsConfig('postId', Encryption::encryptId($postId)); |
||
66 | |||
67 | $action = $this->request->query('action'); |
||
68 | $this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'posts/viewPost.php', ["action"=> $action, "postId" => $postId]); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * show new post form |
||
73 | */ |
||
74 | public function newPost(){ |
||
75 | $this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'posts/newPost.php'); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * creates a new post |
||
80 | * |
||
81 | */ |
||
82 | 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. ![]() |
|||
83 | |||
84 | $title = $this->request->data("title"); |
||
85 | $content = $this->request->data("content"); |
||
86 | |||
87 | $result = $this->post->create(Session::getUserId(), $title, $content); |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
88 | |||
89 | if(!$result){ |
||
90 | Session::set('posts-errors', $this->post->errors()); |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
91 | }else{ |
||
92 | Session::set('posts-success', "Post has been created"); |
||
93 | } |
||
94 | |||
95 | return $this->redirector->root("Posts/newPost"); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * update a post |
||
100 | * |
||
101 | */ |
||
102 | public function update(){ |
||
103 | |||
104 | $postId = $this->request->data("post_id"); |
||
105 | $title = $this->request->data("title"); |
||
106 | $content = $this->request->data("content"); |
||
107 | |||
108 | $postId = Encryption::decryptId($postId); |
||
109 | |||
110 | if(!$this->post->exists($postId)){ |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
111 | return $this->error(404); |
||
112 | } |
||
113 | |||
114 | $post = $this->post->update($postId, $title, $content); |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
115 | |||
116 | if(!$post){ |
||
117 | |||
118 | Session::set('posts-errors', $this->post->errors()); |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
119 | return $this->redirector->root("Posts/View/" . urlencode(Encryption::encryptId($postId)) . "?action=update"); |
||
120 | |||
121 | }else{ |
||
122 | return $this->redirector->root("Posts/View/" . urlencode(Encryption::encryptId($postId))); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | public function delete($postId = 0){ |
||
127 | |||
128 | $postId = Encryption::decryptId($postId); |
||
129 | |||
130 | if(!$this->post->exists($postId)){ |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
131 | return $this->error(404); |
||
132 | } |
||
133 | |||
134 | $this->post->deleteById($postId); |
||
0 ignored issues
–
show
The property
post does not exist on object<PostsController> . 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. ![]() |
|||
135 | |||
136 | return $this->redirector->root("Posts"); |
||
137 | } |
||
138 | |||
139 | public function isAuthorized(){ |
||
140 | |||
141 | $action = $this->request->param('action'); |
||
142 | $role = Session::getUserRole(); |
||
143 | $resource = "posts"; |
||
144 | |||
145 | // only for admins |
||
146 | Permission::allow('admin', $resource, ['*']); |
||
147 | |||
148 | // only for normal users |
||
149 | Permission::allow('user', $resource, ['index', 'view', 'newPost', 'create']); |
||
150 | Permission::allow('user', $resource, ['update', 'delete'], 'owner'); |
||
151 | |||
152 | $postId = ($action === "delete")? $this->request->param("args")[0]: $this->request->data("post_id"); |
||
153 | if(!empty($postId)){ |
||
154 | $postId = Encryption::decryptId($postId); |
||
155 | } |
||
156 | |||
157 | $config = [ |
||
158 | "user_id" => Session::getUserId(), |
||
159 | "table" => "posts", |
||
160 | "id" => $postId |
||
161 | ]; |
||
162 | |||
163 | return Permission::check($role, $resource, $action, $config); |
||
164 | } |
||
165 | } |
||
166 |
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.