13
13
class DatabaseCommand
14
14
{
15
15
public const TABLE_SUM = 'statistics_sums ' ;
16
+
16
17
private const DEBUG_PREFIX = 'proxystatistics:DatabaseCommand - ' ;
17
18
18
19
private const TABLE_PER_USER = 'statistics_per_user ' ;
@@ -87,7 +88,7 @@ public function insertLogin($request, &$date)
87
88
$ ids [$ tableId ] = $ this ->getEntityDbIdFromEntityIdentifier ($ table , $ entities [$ side ], $ tableId );
88
89
}
89
90
90
- if (false === $ this ->writeLogin ($ date , $ ids , $ userId )) {
91
+ if ($ this ->writeLogin ($ date , $ ids , $ userId ) === false ) {
91
92
Logger::error (self ::DEBUG_PREFIX . 'login record has not been inserted (data \'' . json_encode ([
92
93
'user ' => $ userId ,
93
94
'ids ' => $ ids ,
@@ -171,7 +172,7 @@ public function aggregate()
171
172
'day '
172
173
) . '), EXTRACT(DAY FROM ' . $ this ->escape_col ('day ' ) . '), ' ;
173
174
foreach ($ ids as $ id ) {
174
- $ query .= (null === $ id ? '0 ' : $ id ) . ', ' ;
175
+ $ query .= ($ id === null ? '0 ' : $ id ) . ', ' ;
175
176
}
176
177
$ query .= 'SUM(logins), COUNT(DISTINCT ' . $ this ->escape_col ('user ' ) . ') '
177
178
. 'FROM ' . $ this ->tables [self ::TABLE_PER_USER ] . ' '
@@ -221,7 +222,7 @@ public function aggregate()
221
222
$ written = $ this ->conn ->write ($ query , $ params );
222
223
if (is_bool ($ written ) && !$ written ) {
223
224
Logger::warning (self ::DEBUG_PREFIX . $ msg . ' failed ' );
224
- } elseif (0 === $ written ) {
225
+ } elseif ($ written === 0 ) {
225
226
Logger::warning (self ::DEBUG_PREFIX . $ msg . ' completed, but updated 0 rows. ' );
226
227
} else {
227
228
Logger::info (self ::DEBUG_PREFIX . $ msg . ' completed and updated ' . $ written . ' rows. ' );
@@ -272,7 +273,7 @@ private function writeLogin($date, $ids, $user): bool
272
273
273
274
return false ;
274
275
}
275
- if (0 === $ written ) {
276
+ if ($ written === 0 ) {
276
277
Logger::debug (self ::DEBUG_PREFIX . 'login entry has been inserted, but has updated 0 rows. ' );
277
278
278
279
return false ;
@@ -287,23 +288,23 @@ private function prepareEntitiesData($request): array
287
288
Config::MODE_IDP => [],
288
289
Config::MODE_SP => [],
289
290
];
290
- if (Config:: MODE_IDP !== $ this ->mode && Config::MODE_MULTI_IDP !== $ this ->mode ) {
291
+ if ($ this ->mode !== Config::MODE_IDP && $ this ->mode !== Config:: MODE_MULTI_IDP ) {
291
292
$ entities [Config::MODE_IDP ][self ::KEY_ID ] = $ this ->getIdpIdentifier ($ request );
292
293
$ entities [Config::MODE_IDP ][self ::KEY_NAME ] = $ this ->getIdpName ($ request );
293
294
}
294
- if (Config:: MODE_SP !== $ this ->mode ) {
295
+ if ($ this ->mode !== Config:: MODE_SP ) {
295
296
$ entities [Config::MODE_SP ][self ::KEY_ID ] = $ this ->getSpIdentifier ($ request );
296
297
$ entities [Config::MODE_SP ][self ::KEY_NAME ] = $ this ->getSpName ($ request );
297
298
}
298
299
299
- if (Config:: MODE_PROXY !== $ this ->mode && Config::MODE_MULTI_IDP !== $ this ->mode ) {
300
+ if ($ this ->mode !== Config::MODE_PROXY && $ this ->mode !== Config:: MODE_MULTI_IDP ) {
300
301
$ entities [$ this ->mode ] = $ this ->config ->getSideInfo ($ this ->mode );
301
302
if (empty ($ entities [$ this ->mode ][self ::KEY_ID ]) || empty ($ entities [$ this ->mode ][self ::KEY_NAME ])) {
302
303
Logger::error (self ::DEBUG_PREFIX . 'Invalid configuration (id, name) for ' . $ this ->mode );
303
304
}
304
305
}
305
306
306
- if (Config:: MODE_MULTI_IDP === $ this ->mode ) {
307
+ if ($ this ->mode === Config:: MODE_MULTI_IDP ) {
307
308
$ entities [Config::MODE_IDP ] = $ this ->config ->getSideInfo (Config::MODE_IDP );
308
309
if (empty ($ entities [Config::MODE_IDP ][self ::KEY_ID ]) || empty ($ entities [Config::MODE_IDP ][self ::KEY_NAME ])) {
309
310
Logger::error (self ::DEBUG_PREFIX . 'Invalid configuration (id, name) for ' . $ this ->mode );
@@ -346,7 +347,7 @@ private function addWhereId($where, &$query, &$params)
346
347
$ table = self ::TABLE_SIDES [$ side ];
347
348
$ column = self ::TABLE_IDS [$ table ];
348
349
$ part = $ column ;
349
- if (null === $ value ) {
350
+ if ($ value === null ) {
350
351
$ part .= '=0 ' ;
351
352
} else {
352
353
$ part .= '=:id ' ;
@@ -363,8 +364,8 @@ private function addWhereId($where, &$query, &$params)
363
364
364
365
private function addDaysRange ($ days , &$ query , &$ params , $ not = false )
365
366
{
366
- if (0 !== $ days ) { // 0 = all time
367
- if (false === stripos ($ query , 'WHERE ' )) {
367
+ if ($ days !== 0 ) { // 0 = all time
368
+ if (stripos ($ query , 'WHERE ' ) === false ) {
368
369
$ query .= 'WHERE ' ;
369
370
} else {
370
371
$ query .= 'AND ' ;
@@ -408,7 +409,7 @@ private function getAggregateGroupBy($ids): string
408
409
{
409
410
$ columns = ['day ' ];
410
411
foreach ($ ids as $ id ) {
411
- if (null !== $ id ) {
412
+ if ($ id !== null ) {
412
413
$ columns [] = $ id ;
413
414
}
414
415
}
@@ -460,12 +461,12 @@ private function read($query, $params): PDOStatement
460
461
461
462
private function isPgsql (): bool
462
463
{
463
- return ' pgsql ' === $ this ->conn ->getDriver ();
464
+ return $ this ->conn ->getDriver () === ' pgsql ' ;
464
465
}
465
466
466
467
private function isMysql (): bool
467
468
{
468
- return ' mysql ' === $ this ->conn ->getDriver ();
469
+ return $ this ->conn ->getDriver () === ' mysql ' ;
469
470
}
470
471
471
472
private function unknownDriver ()
0 commit comments