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\Event; |
||
3 | |||
4 | use Cake\Cache\Cache; |
||
5 | use Cake\Event\Event; |
||
6 | use Cake\Event\EventListenerInterface; |
||
7 | use Cake\I18n\Number; |
||
8 | use Cake\ORM\TableRegistry; |
||
9 | |||
10 | class Statistics implements EventListenerInterface |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * ImplementedEvents method. |
||
15 | * |
||
16 | * @return array |
||
17 | */ |
||
18 | public function implementedEvents() |
||
19 | { |
||
20 | return [ |
||
21 | 'Model.Users.register' => 'newUserStats', |
||
22 | 'Model.Groups.update' => 'updateGroupStats', |
||
23 | 'Model.BlogArticles.new' => 'newArticleStats', |
||
24 | 'Model.BlogArticlesLikes.new' => 'newArticleLikeStats', |
||
25 | 'Model.BlogArticlesComments.new' => 'newArticleCommentStats' |
||
26 | ]; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Count the articles and write it in the Cache. |
||
31 | * |
||
32 | * @param \Cake\Event\Event $event The event that was fired. |
||
33 | * |
||
34 | * @return array|false |
||
35 | */ |
||
36 | View Code Duplication | public function newArticleStats(Event $event) |
|
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. ![]() |
|||
37 | { |
||
38 | $this->BlogArticles = TableRegistry::get('BlogArticles'); |
||
0 ignored issues
–
show
The property
BlogArticles 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;
![]() |
|||
39 | |||
40 | $articles = $this->BlogArticles->find()->count(); |
||
41 | $articles = Number::format($articles); |
||
42 | |||
43 | if ($this->_writeCache($articles, 'Articles')) { |
||
44 | return $articles; |
||
45 | } |
||
46 | |||
47 | return false; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Count the article's comments and write it in the Cache. |
||
52 | * |
||
53 | * @param \Cake\Event\Event $event The event that was fired. |
||
54 | * |
||
55 | * @return array|false |
||
56 | */ |
||
57 | View Code Duplication | public function newArticleCommentStats(Event $event) |
|
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. ![]() |
|||
58 | { |
||
59 | $this->BlogArticlesComments = TableRegistry::get('BlogArticlesComments'); |
||
0 ignored issues
–
show
The property
BlogArticlesComments does not seem to exist. Did you mean BlogArticles ?
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. ![]() |
|||
60 | |||
61 | $comments = $this->BlogArticlesComments->find()->count(); |
||
0 ignored issues
–
show
The property
BlogArticlesComments does not seem to exist. Did you mean BlogArticles ?
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. ![]() |
|||
62 | $comments = Number::format($comments); |
||
63 | |||
64 | if ($this->_writeCache($comments, 'ArticlesComments')) { |
||
65 | return $comments; |
||
66 | } |
||
67 | |||
68 | return false; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Count the article's likes and write it in the Cache. |
||
73 | * |
||
74 | * @param \Cake\Event\Event $event The event that was fired. |
||
75 | * |
||
76 | * @return array|false |
||
77 | */ |
||
78 | View Code Duplication | public function newArticleLikeStats(Event $event) |
|
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. ![]() |
|||
79 | { |
||
80 | $this->BlogArticlesLikes = TableRegistry::get('BlogArticlesLikes'); |
||
0 ignored issues
–
show
The property
BlogArticlesLikes does not seem to exist. Did you mean BlogArticles ?
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. ![]() |
|||
81 | |||
82 | $likes = $this->BlogArticlesLikes->find()->count(); |
||
0 ignored issues
–
show
The property
BlogArticlesLikes does not seem to exist. Did you mean BlogArticles ?
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. ![]() |
|||
83 | $likes = Number::format($likes); |
||
84 | |||
85 | if ($this->_writeCache($likes, 'ArticlesLikes')) { |
||
86 | return $likes; |
||
87 | } |
||
88 | |||
89 | return false; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Re-count the number of user and find the latest user and write it in the Cache. |
||
94 | * |
||
95 | * @param \Cake\Event\Event $event The event that was fired. |
||
96 | * |
||
97 | * @return array|false |
||
98 | */ |
||
99 | public function newUserStats(Event $event) |
||
0 ignored issues
–
show
|
|||
100 | { |
||
101 | $this->Users = TableRegistry::get('Users'); |
||
0 ignored issues
–
show
The property
Users 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;
![]() |
|||
102 | |||
103 | $totalUsers = $this->Users->find()->count(); |
||
104 | $totalUsers = Number::format($totalUsers); |
||
105 | |||
106 | $lastRegistered = $this->Users->find('short')->order(['Users.created' => 'DESC'])->first(); |
||
107 | |||
108 | $data = []; |
||
109 | $data['TotalUsers'] = $totalUsers; |
||
110 | $data['LastRegistered'] = $lastRegistered; |
||
111 | |||
112 | if ($this->_writeCache($data, 'Users')) { |
||
0 ignored issues
–
show
$data is of type array<string,*,{"LastRegistered":"*"}> , but the function expects a integer|object|string .
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);
![]() |
|||
113 | return $data; |
||
114 | } |
||
115 | |||
116 | return false; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Get the Groups and write it in the Cache. |
||
121 | * |
||
122 | * @param \Cake\Event\Event $event The event that was fired. |
||
123 | * |
||
124 | * @return array|false |
||
125 | */ |
||
126 | public function updateGroupStats(Event $event) |
||
0 ignored issues
–
show
|
|||
127 | { |
||
128 | $this->Groups = TableRegistry::get('Groups'); |
||
0 ignored issues
–
show
The property
Groups 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;
![]() |
|||
129 | |||
130 | $groups = $this->Groups->find('translations')->order(['Groups.id' => 'DESC'])->toArray(); |
||
131 | |||
132 | if ($this->_writeCache($groups, 'Groups')) { |
||
0 ignored issues
–
show
$groups is of type array , but the function expects a integer|object|string .
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);
![]() |
|||
133 | return $groups; |
||
134 | } |
||
135 | |||
136 | return false; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Write the data into the Cache with the passed key. |
||
141 | * |
||
142 | * @param int|object|string $data The data to save in the Cache. |
||
143 | * @param string $key The key to save the data. |
||
144 | * |
||
145 | * @return bool |
||
146 | */ |
||
147 | protected function _writeCache($data, $key) |
||
148 | { |
||
149 | if (empty($data) || empty($key)) { |
||
150 | return true; |
||
151 | } |
||
152 | |||
153 | $result = Cache::write($key, $data, 'statistics'); |
||
154 | if ($result) { |
||
155 | return true; |
||
156 | } |
||
157 | |||
158 | return false; |
||
159 | } |
||
160 | } |
||
161 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.