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\Admin; |
||
3 | |||
4 | use App\Controller\AppController; |
||
5 | use App\Event\Statistics; |
||
6 | use Cake\Cache\Cache; |
||
7 | use Cake\Core\Configure; |
||
8 | use Cake\Event\Event; |
||
9 | use Cake\I18n\Number; |
||
10 | use Mexitek\PHPColors\Color; |
||
11 | use Widop\GoogleAnalytics\Client; |
||
12 | use Widop\GoogleAnalytics\Query; |
||
13 | use Widop\GoogleAnalytics\Service; |
||
14 | use Widop\HttpAdapter\CurlHttpAdapter; |
||
15 | |||
16 | class AdminController extends AppController |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Index page. |
||
21 | * |
||
22 | * @return void |
||
23 | */ |
||
24 | public function home() |
||
25 | { |
||
26 | if (Configure::read('Analytics.enabled') === true) { |
||
27 | $httpAdapter = new CurlHttpAdapter(); |
||
28 | $client = new Client(Configure::read('Analytics.client_id'), Configure::read('Analytics.private_key'), $httpAdapter); |
||
29 | $service = new Service($client); |
||
30 | |||
31 | $statistics = Cache::remember('statistics', function () use ($service) { |
||
32 | $statistics = new Query(Configure::read('Analytics.profile_id')); |
||
33 | $statistics |
||
34 | ->setStartDate(new \DateTime(Configure::read('Analytics.start_date'))) |
||
35 | ->setEndDate(new \DateTime()) |
||
36 | ->setMetrics([ |
||
37 | 'ga:visits', 'ga:visitors', 'ga:pageviews', 'ga:pageviewsPerVisit', |
||
38 | 'ga:avgtimeOnSite', 'ga:visitBounceRate', 'ga:percentNewVisits' |
||
39 | ]); |
||
40 | |||
41 | return $service->query($statistics); |
||
42 | }, 'analytics'); |
||
43 | |||
44 | View Code Duplication | $browsers = Cache::remember('browsers', function () use ($service) { |
|
0 ignored issues
–
show
|
|||
45 | $browsers = new Query(Configure::read('Analytics.profile_id')); |
||
46 | $browsers |
||
47 | ->setStartDate(new \DateTime(Configure::read('Analytics.start_date'))) |
||
48 | ->setEndDate(new \DateTime()) |
||
49 | ->setDimensions(['ga:browser']) |
||
50 | ->setMetrics(['ga:pageviews']) |
||
51 | ->setSorts(['ga:pageviews']) |
||
52 | ->setFilters(['ga:browser==Chrome,ga:browser==Firefox,ga:browser==Internet Explorer,ga:browser==Safari,ga:browser==Opera']); |
||
53 | |||
54 | return $service->query($browsers); |
||
55 | }, 'analytics'); |
||
56 | |||
57 | $continents = Cache::remember('continents', function () use ($service) { |
||
58 | $continentsRows = new Query(Configure::read('Analytics.profile_id')); |
||
59 | $continentsRows |
||
60 | ->setStartDate(new \DateTime(Configure::read('Analytics.start_date'))) |
||
61 | ->setEndDate(new \DateTime()) |
||
62 | ->setDimensions(['ga:continent']) |
||
63 | ->setMetrics(['ga:visitors']) |
||
64 | ->setSorts(['ga:visitors']) |
||
65 | ->setFilters(['ga:continent==Africa,ga:continent==Americas,ga:continent==Asia,ga:continent==Europe,ga:continent==Oceania']); |
||
66 | |||
67 | $continentsRows = $service->query($continentsRows); |
||
68 | |||
69 | $color = new Color("1abc9c"); |
||
70 | $light = 1; |
||
71 | |||
72 | $continents = []; |
||
73 | |||
74 | foreach (array_reverse($continentsRows->getRows()) as $continentRow) { |
||
75 | $continent = []; |
||
76 | $continent['label'] = $continentRow[0]; |
||
77 | $continent['data'] = $continentRow[1]; |
||
78 | $continent['color'] = '#' . $color->lighten($light); |
||
79 | |||
80 | array_push($continents, $continent); |
||
81 | $light += 10; |
||
82 | } |
||
83 | |||
84 | return $continents; |
||
85 | }, 'analytics'); |
||
86 | |||
87 | View Code Duplication | $graphVisitors = Cache::remember('graphVisitors', function () use ($service) { |
|
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. ![]() |
|||
88 | $graphVisitors = new Query(Configure::read('Analytics.profile_id')); |
||
89 | $graphVisitors |
||
90 | ->setStartDate(new \DateTime('-7 days')) |
||
91 | ->setEndDate(new \DateTime()) |
||
92 | ->setDimensions(['ga:date']) |
||
93 | ->setMetrics(['ga:visits', 'ga:pageviews']) |
||
94 | ->setSorts(['ga:date']); |
||
95 | |||
96 | return $service->query($graphVisitors); |
||
97 | }, 'analytics'); |
||
98 | |||
99 | $this->set(compact('statistics', 'browsers', 'continents', 'graphVisitors')); |
||
100 | } |
||
101 | |||
102 | $this->loadModel('Users'); |
||
103 | //UsersGraph |
||
104 | $usersGraphCount = $this->Users |
||
0 ignored issues
–
show
The property
Users does not exist on object<App\Controller\Admin\AdminController> . 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. ![]() |
|||
105 | ->find('all') |
||
106 | ->select([ |
||
107 | 'date' => 'DATE_FORMAT(created,\'%d-%m-%Y\')', |
||
108 | 'count' => 'COUNT(id)' |
||
109 | ]) |
||
110 | ->group('DATE(created)') |
||
111 | ->order([ |
||
112 | 'date' => 'desc' |
||
113 | ]) |
||
114 | ->where([ |
||
115 | 'UNIX_TIMESTAMP(DATE(created)) >' => (new \DateTime('-8 days'))->getTimestamp() |
||
116 | ]) |
||
117 | ->toArray(); |
||
118 | |||
119 | $usersGraph = []; |
||
120 | |||
121 | //Fill the new array with the date of the 8 past days and give them the value 0. |
||
122 | for ($i = 0; $i < 8; $i++) { |
||
123 | $date = new \DateTime("$i days ago"); |
||
124 | |||
125 | $usersGraph[$date->format('d-m-Y')] = 0; |
||
126 | } |
||
127 | |||
128 | //Foreach value that we got in the database, parse the array by the key date, |
||
129 | //and if the key exist, attribute the new value. |
||
130 | foreach ($usersGraphCount as $user) { |
||
131 | $usersGraph[$user->date] = intval($user->count); |
||
132 | } |
||
133 | $usersGraph = array_reverse($usersGraph); |
||
134 | |||
135 | $stats = $this->_buildStats([ |
||
136 | 'Users' => 'Model.Users.register', |
||
137 | 'Articles' => 'Model.BlogArticles.new', |
||
138 | 'ArticlesLikes' => 'Model.BlogArticlesLikes.new', |
||
139 | 'ArticlesComments' => 'Model.BlogArticlesComments.new' |
||
140 | ]); |
||
141 | |||
142 | $this->set(compact('stats', 'usersGraph')); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Build the statistics for the home page. |
||
147 | * |
||
148 | * @param array $array The array of statistics to build. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | 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. ![]() |
|||
153 | { |
||
154 | $statistics = []; |
||
155 | |||
156 | foreach ($array as $type => $event) { |
||
157 | $statistics[$type] = Cache::remember($type, function () use ($event) { |
||
158 | $this->eventManager()->attach(new Statistics()); |
||
0 ignored issues
–
show
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. ![]() 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);
![]() |
|||
159 | $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)
![]() |
|||
160 | $this->eventManager()->dispatch($event); |
||
161 | |||
162 | return $event->result; |
||
163 | }, 'statistics'); |
||
164 | } |
||
165 | |||
166 | return $statistics; |
||
167 | } |
||
168 | } |
||
169 |
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.