Skip to content

Commit a7fb3ee

Browse files
committed
Fix multiple PHPStan issues level 2
1 parent 2ca8716 commit a7fb3ee

12 files changed

+81
-80
lines changed

core/ajax/cmd.ajax.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959
$info_cmd = array();
6060
$info_cmd['id'] = $cmd->getId();
61-
$info_cmd['html'] = $cmd->toHtml(init('version'), init('option'), init('cmdColor', null));
61+
$info_cmd['html'] = $cmd->toHtml(init('version'), init('option'));
6262
ajax::success($info_cmd);
6363
}
6464
}
@@ -385,8 +385,8 @@
385385
}
386386

387387
if ($dateStart == '' && init('dateRange') != 'all') {
388-
$now = date('Y-m-d');
389-
$dateStart = $now->modify('- ' . init('dateRange'));
388+
$now = new \DateTimeImmutable();
389+
$dateStart = $now->modify('- ' . init('dateRange'))->format('Y-m-d H:i:s');
390390
}
391391

392392
$return['maxValue'] = '';

core/ajax/eqLogic.ajax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
unset($used['cmd' . $cmd->getId()]);
417417
}
418418
$cmdData = array('node' => array(), 'link' => array());
419-
$cmdData = $cmd->getLinkData($cmdData, 0, 2, null, false);
419+
$cmdData = $cmd->getLinkData($cmdData, 0, 2, false);
420420
if (isset($cmdData['node']['eqLogic' . $eqLogic->getId()])) {
421421
unset($cmdData['node']['eqLogic' . $eqLogic->getId()]);
422422
}

core/class/DB.class.php

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ private static function initConnection() {
4242
PDO::ATTR_ERRMODE => (DEBUG ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT),
4343
];
4444
if (isset($CONFIG['db']['unix_socket'])) {
45-
static::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'],
45+
self::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'],
4646
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
4747
} else {
48-
static::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'],
48+
self::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'],
4949
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
5050
}
5151
}
@@ -55,21 +55,21 @@ public static function getLastInsertId() {
5555
}
5656

5757
public static function getConnection() {
58-
if (static::$connection == null) {
59-
static::initConnection();
60-
static::$lastConnection = strtotime('now');
61-
} elseif (static::$lastConnection + 120 < strtotime('now')) {
58+
if (self::$connection == null) {
59+
self::initConnection();
60+
self::$lastConnection = strtotime('now');
61+
} elseif (self::$lastConnection + 120 < strtotime('now')) {
6262
try {
63-
$result = @static::$connection->query('select 1;');
63+
$result = @self::$connection->query('select 1;');
6464
if (!$result) {
65-
static::initConnection();
65+
self::initConnection();
6666
}
6767
} catch (Exception $e) {
68-
static::initConnection();
68+
self::initConnection();
6969
}
70-
static::$lastConnection = strtotime('now');
70+
self::$lastConnection = strtotime('now');
7171
}
72-
return static::$connection;
72+
return self::$connection;
7373
}
7474

7575
public static function &CallStoredProc($_procName, $_params, $_fetch_type, $_className = NULL, $_fetch_opt = NULL) {
@@ -94,10 +94,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
9494
if(preg_match('/^update|^replace|^delete|^create|^drop|^alter|^truncate/i', $_query)){
9595
$errorInfo = $stmt->errorInfo();
9696
if ($errorInfo[0] != 0000) {
97-
static::$lastConnection = 0;
97+
self::$lastConnection = 0;
9898
throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query);
9999
}
100-
static::$lastConnection = strtotime('now');
100+
self::$lastConnection = strtotime('now');
101101
return $res;
102102
}
103103
if ($_fetchType == static::FETCH_TYPE_ROW) {
@@ -116,10 +116,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
116116
}
117117
$errorInfo = $stmt->errorInfo();
118118
if ($errorInfo[0] != 0000) {
119-
static::$lastConnection = 0;
119+
self::$lastConnection = 0;
120120
throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query);
121121
}
122-
static::$lastConnection = strtotime('now');
122+
self::$lastConnection = strtotime('now');
123123
if ($_fetch_param == PDO::FETCH_CLASS) {
124124
if (is_array($res) && count($res) > 0) {
125125
foreach ($res as &$obj) {
@@ -186,29 +186,29 @@ public static function save($object, $_direct = false, $_replace = false) {
186186
if (!$_direct && method_exists($object, 'preSave')) {
187187
$object->preSave();
188188
}
189-
if (!static::getField($object, 'id')) {
189+
if (!self::getField($object, 'id')) {
190190
//New object to save.
191-
$fields = static::getFields($object);
191+
$fields = self::getFields($object);
192192
if (in_array('id', $fields)) {
193-
static::setField($object, 'id', null);
193+
self::setField($object, 'id', null);
194194
}
195195
if (!$_direct && method_exists($object, 'preInsert')) {
196196
$object->preInsert();
197197
}
198198
if (method_exists($object, 'encrypt')) {
199199
$object->encrypt();
200200
}
201-
list($sql, $parameters) = static::buildQuery($object);
201+
list($sql, $parameters) = self::buildQuery($object);
202202
if ($_replace) {
203-
$sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
203+
$sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
204204
} else {
205-
$sql = 'INSERT INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
205+
$sql = 'INSERT INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
206206
}
207207
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
208-
$reflection = static::getReflectionClass($object);
208+
$reflection = self::getReflectionClass($object);
209209
if ($reflection->hasProperty('id')) {
210210
try {
211-
static::setField($object, 'id', static::getLastInsertId());
211+
self::setField($object, 'id', static::getLastInsertId());
212212
} catch (Exception $exc) {
213213
trigger_error($exc->getMessage(), E_USER_NOTICE);
214214
} catch (InvalidArgumentException $ex) {
@@ -234,14 +234,14 @@ public static function save($object, $_direct = false, $_replace = false) {
234234
if (method_exists($object, 'encrypt')) {
235235
$object->encrypt();
236236
}
237-
list($sql, $parameters) = static::buildQuery($object);
237+
list($sql, $parameters) = self::buildQuery($object);
238238
if (!$_direct && method_exists($object, 'getId')) {
239239
$parameters['id'] = $object->getId(); //override if necessary
240240
}
241241
if ($_replace) {
242-
$sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
242+
$sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
243243
} else {
244-
$sql = 'UPDATE `' . static::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id';
244+
$sql = 'UPDATE `' . self::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id';
245245
}
246246
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
247247
} else {
@@ -264,12 +264,12 @@ public static function save($object, $_direct = false, $_replace = false) {
264264
}
265265

266266
public static function refresh($object) {
267-
if (!static::getField($object, 'id')) {
267+
if (!self::getField($object, 'id')) {
268268
throw new Exception('Can\'t refresh DB object without its ID');
269269
}
270-
$parameters = array('id' => static::getField($object, 'id'));
270+
$parameters = array('id' => self::getField($object, 'id'));
271271
$sql = 'SELECT ' . static::buildField(get_class($object)) .
272-
' FROM `' . static::getTableName($object) . '` ' .
272+
' FROM `' . self::getTableName($object) . '` ' .
273273
' WHERE ';
274274
foreach ($parameters as $field => $value) {
275275
if ($value != '') {
@@ -283,14 +283,14 @@ public static function refresh($object) {
283283
if (!is_object($newObject)) {
284284
return false;
285285
}
286-
foreach (static::getFields($object) as $field) {
287-
$reflection = static::getReflectionClass($object);
286+
foreach (self::getFields($object) as $field) {
287+
$reflection = self::getReflectionClass($object);
288288
$property = $reflection->getProperty($field);
289289
if (!$reflection->hasProperty($field)) {
290290
throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field);
291291
}
292292
$property->setAccessible(true);
293-
$property->setValue($object, static::getField($newObject, $field));
293+
$property->setValue($object, self::getField($newObject, $field));
294294
$property->setAccessible(false);
295295
}
296296
return true;
@@ -300,13 +300,13 @@ public static function refresh($object) {
300300
* Retourne une liste d'objets ou un objet en fonction de filtres
301301
* @param $_filters Filtres à appliquer
302302
* @param $_object Objet sur lequel appliquer les filtres
303-
* @return Objet ou liste d'objets correspondant à la requête
303+
* @return array<mixed>|null Objet ou liste d'objets correspondant à la requête
304304
*/
305305
public static function getWithFilter(array $_filters, $_object) {
306306
// operators have to remain in this order. If you put '<' before '<=', algorithm won't make the difference & will think a '<=' is a '<'
307307
$operators = array('!=', '<=', '>=', '<', '>', 'NOT LIKE', 'LIKE', '=');
308-
$fields = static::getFields($_object);
309-
$class = static::getReflectionClass($_object)->getName();
308+
$fields = self::getFields($_object);
309+
$class = self::getReflectionClass($_object)->getName();
310310
// create query
311311
$query = 'SELECT ' . static::buildField($class) . ' FROM ' . $class . '';
312312
$values = array();
@@ -365,8 +365,8 @@ public static function remove($object) {
365365
return false;
366366
}
367367
}
368-
list($sql, $parameters) = static::buildQuery($object);
369-
$sql = 'DELETE FROM `' . static::getTableName($object) . '` WHERE ';
368+
list($sql, $parameters) = self::buildQuery($object);
369+
$sql = 'DELETE FROM `' . self::getTableName($object) . '` WHERE ';
370370
if (isset($parameters['id'])) {
371371
$sql .= '`id`=:id AND ';
372372
$parameters = array('id' => $parameters['id']);
@@ -381,9 +381,9 @@ public static function remove($object) {
381381
}
382382
$sql .= '1';
383383
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
384-
$reflection = static::getReflectionClass($object);
384+
$reflection = self::getReflectionClass($object);
385385
if ($reflection->hasProperty('id')) {
386-
static::setField($object, 'id', null);
386+
self::setField($object, 'id', null);
387387
}
388388
if (method_exists($object, 'postRemove')) {
389389
$object->postRemove();
@@ -409,8 +409,8 @@ public static function lock($object) {
409409
return false;
410410
}
411411
}
412-
list($sql, $parameters) = static::buildQuery($object);
413-
$sql = 'SELECT * FROM ' . static::getTableName($object) . ' WHERE ';
412+
list($sql, $parameters) = self::buildQuery($object);
413+
$sql = 'SELECT * FROM ' . self::getTableName($object) . ' WHERE ';
414414
foreach ($parameters as $field => $value) {
415415
if ($value != '') {
416416
$sql .= '`' . $field . '`=:' . $field . ' AND ';
@@ -445,23 +445,23 @@ private static function getTableName($object) {
445445
* @throws RuntimeException
446446
*/
447447
private static function getFields($object) {
448-
$table = is_string($object) ? $object : static::getTableName($object);
449-
if (isset(static::$fields[$table])) {
450-
return static::$fields[$table];
448+
$table = is_string($object) ? $object : self::getTableName($object);
449+
if (isset(self::$fields[$table])) {
450+
return self::$fields[$table];
451451
}
452-
$reflection = is_object($object) ? static::getReflectionClass($object) : new ReflectionClass($object);
452+
$reflection = is_object($object) ? self::getReflectionClass($object) : new ReflectionClass($object);
453453
$properties = $reflection->getProperties();
454-
static::$fields[$table] = array();
454+
self::$fields[$table] = array();
455455
foreach ($properties as $property) {
456456
$name = $property->getName();
457457
if ('_' !== $name[0]) {
458-
static::$fields[$table][] = $name;
458+
self::$fields[$table][] = $name;
459459
}
460460
}
461-
if (empty(static::$fields[$table])) {
461+
if (empty(self::$fields[$table])) {
462462
throw new RuntimeException('No fields found for class ' . get_class($object));
463463
}
464-
return static::$fields[$table];
464+
return self::$fields[$table];
465465
}
466466

467467
/**
@@ -477,7 +477,7 @@ private static function setField($object, $field, $value) {
477477
if (method_exists($object, $method)) {
478478
$object->$method($value);
479479
} else {
480-
$reflection = static::getReflectionClass($object);
480+
$reflection = self::getReflectionClass($object);
481481
if (!$reflection->hasProperty($field)) {
482482
throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field);
483483
}
@@ -499,9 +499,9 @@ private static function setField($object, $field, $value) {
499499
private static function buildQuery($object) {
500500
$parameters = array();
501501
$sql = array();
502-
foreach (static::getFields($object) as $field) {
502+
foreach (self::getFields($object) as $field) {
503503
$sql[] = '`' . $field . '` = :' . $field;
504-
$parameters[$field] = static::getField($object, $field);
504+
$parameters[$field] = self::getField($object, $field);
505505
}
506506
return array($sql, $parameters);
507507
}
@@ -521,7 +521,7 @@ private static function getField($object, $field) {
521521
if (method_exists($object, $method)) {
522522
$retval = $object->$method();
523523
} else {
524-
$reflection = static::getReflectionClass($object);
524+
$reflection = self::getReflectionClass($object);
525525
if ($reflection->hasProperty($field)) {
526526
$property = $reflection->getProperty($field);
527527
$property->setAccessible(true);
@@ -552,7 +552,7 @@ private static function getReflectionClass($object) {
552552

553553
public static function buildField($_class, $_prefix = '') {
554554
$fields = array();
555-
foreach (static::getFields($_class) as $field) {
555+
foreach (self::getFields($_class) as $field) {
556556
if ('_' !== $field[0]) {
557557
if ($_prefix != '') {
558558
$fields[] = '`' . $_prefix . '`.' . '`' . $field . '`';

core/class/cache.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ public static function isOk(){
275275
}
276276

277277
public static function getConnection(){
278-
if(static::$connection !== null){
279-
return static::$connection;
278+
if(self::$connection !== null){
279+
return self::$connection;
280280
}
281281
$redis = new Redis();
282282
$redis->connect(config::byKey('cache::redisaddr'), config::byKey('cache::redisport'));
283-
static::$connection = $redis;
284-
return static::$connection;
283+
self::$connection = $redis;
284+
return self::$connection;
285285
}
286286

287287
public static function all(){

core/class/config.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static function remove(string $_key, string $_plugin = 'core') {
144144
/**
145145
* Get config by key
146146
* @param string $_key nom de la clef dont on veut la valeur
147-
* @return string valeur de la clef
147+
* @return mixed valeur de la clef
148148
*/
149149
public static function byKey($_key, $_plugin = 'core', $_default = '', $_forceFresh = false) {
150150
if (!$_forceFresh && isset(self::$cache[$_plugin . '::' . $_key]) && !in_array($_key, self::$nocache)) {

core/class/event.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function changes($_datetime, $_longPolling = null, $_filter = null
112112
$max_cycle = $_longPolling / $waitTime;
113113
while (count($return) == 0 && $i < $max_cycle) {
114114
if ($waitTime < 1) {
115-
usleep(1000000 * $waitTime);
115+
usleep(1000000 * ((float) $waitTime));
116116
} else {
117117
sleep(round($waitTime));
118118
}

core/class/history.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ public static function archive() {
237237
config::save('historyArchiveTime', 2);
238238
}
239239
if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) {
240-
config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1);
240+
config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1);
241241
}
242242
if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) {
243-
config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1);
243+
config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1);
244244
}
245245
$archiveDatetime = (config::byKey('historyArchiveTime') < 1) ? date('Y-m-d H:i:s', strtotime('- 1 hours')) : date('Y-m-d H:i:s', strtotime('- ' . config::byKey('historyArchiveTime', 'core', 1) . ' hours'));
246246
if (config::byKey('historyArchivePackage') < 1) {
247-
$archivePackage = '00:' . config::byKey('historyArchivePackage') * 60 . ':00';
247+
$archivePackage = '00:' . (int) config::byKey('historyArchivePackage') * 60 . ':00';
248248
} else {
249249
$archivePackage = config::byKey('historyArchivePackage') . ':00:00';
250250
if (strlen($archivePackage) < 8) {
@@ -328,7 +328,7 @@ public static function archive() {
328328
$mode = $cmd->getConfiguration('historizeMode', 'avg');
329329
$values = array(
330330
'cmd_id' => $sensors['cmd_id'],
331-
'archivePackage' => config::byKey('historyArchivePackage') * 3600,
331+
'archivePackage' => (int) config::byKey('historyArchivePackage') * 3600,
332332
'archiveTime' => $archiveDatetime
333333
);
334334
$round = (is_numeric($cmd->getConfiguration('historizeRound'))) ? $cmd->getConfiguration('historizeRound') : 2;

core/class/jeedom.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ public static function isDateOk() {
10441044
self::forceSyncHour();
10451045
sleep(3);
10461046
if (strtotime('now') < $mindate || strtotime('now') > $maxdate) {
1047-
log::add('core', 'error', __('La date du système est incorrecte (avant ' . $minDateValue . ' ou après ' . $maxDateValue . ') :', __FILE__) . ' ' . (new \DateTime())->format('Y-m-d H:i:s'), 'dateCheckFailed');
1047+
log::add('core', 'error', __('La date du système est incorrecte (avant ' . $minDateValue->format('Y-m-d H:i:s') . ' ou après ' . $maxDateValue . ') :', __FILE__) . ' ' . (new \DateTime())->format('Y-m-d H:i:s'), 'dateCheckFailed');
10481048
return false;
10491049
}
10501050
}

0 commit comments

Comments
 (0)