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 | namespace App\Controller; |
||
3 | |||
4 | use App\Event\Statistics; |
||
5 | use Cake\Cache\Cache; |
||
6 | use Cake\Core\Configure; |
||
7 | use Cake\Event\Event; |
||
8 | use Cake\Network\Exception\NotFoundException; |
||
9 | |||
10 | class PagesController extends AppController |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * Initialization hook method. |
||
15 | * |
||
16 | * @return void |
||
17 | */ |
||
18 | public function initialize() |
||
19 | { |
||
20 | parent::initialize(); |
||
21 | |||
22 | $this->loadComponent('RequestHandler'); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Beforefilter. |
||
27 | * |
||
28 | * @param Event $event The beforeFilter event that was fired. |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function beforeFilter(Event $event) |
||
33 | { |
||
34 | parent::beforeFilter($event); |
||
35 | |||
36 | $this->Auth->allow(['home', 'maintenance', 'acceptCookie', 'lang', 'terms']); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Home page. |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | public function home() |
||
45 | { |
||
46 | $this->loadModel('BlogArticles'); |
||
47 | $this->loadModel('BlogArticlesComments'); |
||
48 | |||
49 | $articles = $this->BlogArticles |
||
0 ignored issues
–
show
|
|||
50 | ->find() |
||
51 | ->contain([ |
||
52 | 'BlogCategories', |
||
53 | 'Users' |
||
54 | ]) |
||
55 | ->order([ |
||
56 | 'BlogArticles.created' => 'desc' |
||
57 | ]) |
||
58 | ->limit(Configure::read('Home.articles')) |
||
59 | ->where([ |
||
60 | 'BlogArticles.is_display' => 1 |
||
61 | ]); |
||
62 | |||
63 | $comments = $this->BlogArticlesComments |
||
0 ignored issues
–
show
The property
BlogArticlesComments does not exist on object<App\Controller\PagesController> . 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. ![]() |
|||
64 | ->find() |
||
65 | ->contain([ |
||
66 | 'BlogArticles' => function ($q) { |
||
67 | return $q |
||
68 | ->select([ |
||
69 | 'title' |
||
70 | ]); |
||
71 | }, |
||
72 | 'Users' => function ($q) { |
||
73 | return $q->find('medium'); |
||
74 | } |
||
75 | ]) |
||
76 | ->order([ |
||
77 | 'BlogArticlesComments.created' => 'desc' |
||
78 | ]) |
||
79 | ->limit(Configure::read('Home.comments')) |
||
80 | ->where([ |
||
81 | 'BlogArticles.is_display' => 1 |
||
82 | ]); |
||
83 | |||
84 | $statistics = $this->_buildStats([ |
||
85 | 'Users' => 'Model.Users.register', |
||
86 | 'Articles' => 'Model.BlogArticles.new', |
||
87 | 'ArticlesLikes' => 'Model.BlogArticlesLikes.new', |
||
88 | 'ArticlesComments' => 'Model.BlogArticlesComments.new' |
||
89 | ]); |
||
90 | |||
91 | $this->set(compact('articles', 'comments', 'statistics')); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Build the statistics for the home page. |
||
96 | * |
||
97 | * @param array $array The array of statistics to build. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | View Code Duplication | protected function _buildStats(array $array) |
|
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. ![]() |
|||
102 | { |
||
103 | $statistics = []; |
||
104 | |||
105 | foreach ($array as $type => $event) { |
||
106 | $statistics[$type] = Cache::remember($type, function () use ($event) { |
||
107 | $this->eventManager()->attach(new Statistics()); |
||
0 ignored issues
–
show
new \App\Event\Statistics() is of type object<App\Event\Statistics> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() The method
Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
108 | $event = new Event($event); |
||
0 ignored issues
–
show
Consider using a different name than the imported variable
$event , or did you forget to import by reference?
It seems like you are assigning to a variable which was imported through a For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope. Change not visible in outer-scope$x = 1;
$callable = function() use ($x) {
$x = 2; // Not visible in outer scope. If you would like this, how
// about using a different variable name than $x?
};
$callable();
var_dump($x); // integer(1)
Change visible in outer-scope$x = 1;
$callable = function() use (&$x) {
$x = 2;
};
$callable();
var_dump($x); // integer(2)
![]() |
|||
109 | $this->eventManager()->dispatch($event); |
||
110 | |||
111 | return $event->result; |
||
112 | }, 'statistics'); |
||
113 | } |
||
114 | |||
115 | return $statistics; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * The user accept the use of cookies. |
||
120 | * |
||
121 | * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request. |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | public function acceptCookie() |
||
126 | { |
||
127 | if (!$this->request->is('ajax')) { |
||
128 | throw new NotFoundException(); |
||
129 | } |
||
130 | |||
131 | $this->Cookie->configKey('allowCookies', [ |
||
132 | 'expires' => '+1 year', |
||
133 | 'httpOnly' => true |
||
134 | ]); |
||
135 | $this->Cookie->write('allowCookies', 'true'); |
||
136 | |||
137 | $json = []; |
||
138 | $json['message'] = __('Thanks for accepting to use the cookies !'); |
||
139 | $this->set(compact('json')); |
||
140 | |||
141 | $this->set('_serialize', 'json'); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Redirect to the referer. |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | public function lang() |
||
150 | { |
||
151 | $this->redirect($this->referer()); |
||
0 ignored issues
–
show
It seems like
$this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest> ; however, Cake\Controller\Controller::redirect() does only seem to accept string|array , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Display the maintenance page or a 404 if the site isn't in maintenance. |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | public function maintenance() |
||
160 | { |
||
161 | if (Configure::read('Site.maintenance') === false) { |
||
162 | throw new NotFoundException(); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Display the Terms page. |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | public function terms() |
||
172 | { |
||
173 | } |
||
174 | } |
||
175 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.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.