diff --git a/core/ajax/cmd.ajax.php b/core/ajax/cmd.ajax.php index 9b858a2dbc..c54586c390 100644 --- a/core/ajax/cmd.ajax.php +++ b/core/ajax/cmd.ajax.php @@ -58,7 +58,7 @@ } $info_cmd = array(); $info_cmd['id'] = $cmd->getId(); - $info_cmd['html'] = $cmd->toHtml(init('version'), init('option'), init('cmdColor', null)); + $info_cmd['html'] = $cmd->toHtml(init('version'), init('option')); ajax::success($info_cmd); } } @@ -385,8 +385,8 @@ } if ($dateStart == '' && init('dateRange') != 'all') { - $now = date('Y-m-d'); - $dateStart = $now->modify('- ' . init('dateRange')); + $now = new \DateTimeImmutable(); + $dateStart = $now->modify('- ' . init('dateRange'))->format('Y-m-d H:i:s'); } $return['maxValue'] = ''; diff --git a/core/ajax/eqLogic.ajax.php b/core/ajax/eqLogic.ajax.php index 99f30677e3..29a63becc3 100644 --- a/core/ajax/eqLogic.ajax.php +++ b/core/ajax/eqLogic.ajax.php @@ -416,7 +416,7 @@ unset($used['cmd' . $cmd->getId()]); } $cmdData = array('node' => array(), 'link' => array()); - $cmdData = $cmd->getLinkData($cmdData, 0, 2, null, false); + $cmdData = $cmd->getLinkData($cmdData, 0, 2, false); if (isset($cmdData['node']['eqLogic' . $eqLogic->getId()])) { unset($cmdData['node']['eqLogic' . $eqLogic->getId()]); } diff --git a/core/class/DB.class.php b/core/class/DB.class.php index 5e0879eed6..393816710d 100644 --- a/core/class/DB.class.php +++ b/core/class/DB.class.php @@ -42,10 +42,10 @@ private static function initConnection() { PDO::ATTR_ERRMODE => (DEBUG ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT), ]; if (isset($CONFIG['db']['unix_socket'])) { - static::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'], + self::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'], $CONFIG['db']['username'], $CONFIG['db']['password'], $_options); } else { - static::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'], + self::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'], $CONFIG['db']['username'], $CONFIG['db']['password'], $_options); } } @@ -55,21 +55,21 @@ public static function getLastInsertId() { } public static function getConnection() { - if (static::$connection == null) { - static::initConnection(); - static::$lastConnection = strtotime('now'); - } elseif (static::$lastConnection + 120 < strtotime('now')) { + if (self::$connection == null) { + self::initConnection(); + self::$lastConnection = strtotime('now'); + } elseif (self::$lastConnection + 120 < strtotime('now')) { try { - $result = @static::$connection->query('select 1;'); + $result = @self::$connection->query('select 1;'); if (!$result) { - static::initConnection(); + self::initConnection(); } } catch (Exception $e) { - static::initConnection(); + self::initConnection(); } - static::$lastConnection = strtotime('now'); + self::$lastConnection = strtotime('now'); } - return static::$connection; + return self::$connection; } 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 if(preg_match('/^update|^replace|^delete|^create|^drop|^alter|^truncate/i', $_query)){ $errorInfo = $stmt->errorInfo(); if ($errorInfo[0] != 0000) { - static::$lastConnection = 0; + self::$lastConnection = 0; throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query); } - static::$lastConnection = strtotime('now'); + self::$lastConnection = strtotime('now'); return $res; } if ($_fetchType == static::FETCH_TYPE_ROW) { @@ -116,10 +116,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP } $errorInfo = $stmt->errorInfo(); if ($errorInfo[0] != 0000) { - static::$lastConnection = 0; + self::$lastConnection = 0; throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query); } - static::$lastConnection = strtotime('now'); + self::$lastConnection = strtotime('now'); if ($_fetch_param == PDO::FETCH_CLASS) { if (is_array($res) && count($res) > 0) { foreach ($res as &$obj) { @@ -186,11 +186,11 @@ public static function save($object, $_direct = false, $_replace = false) { if (!$_direct && method_exists($object, 'preSave')) { $object->preSave(); } - if (!static::getField($object, 'id')) { + if (!self::getField($object, 'id')) { //New object to save. - $fields = static::getFields($object); + $fields = self::getFields($object); if (in_array('id', $fields)) { - static::setField($object, 'id', null); + self::setField($object, 'id', null); } if (!$_direct && method_exists($object, 'preInsert')) { $object->preInsert(); @@ -198,17 +198,17 @@ public static function save($object, $_direct = false, $_replace = false) { if (method_exists($object, 'encrypt')) { $object->encrypt(); } - list($sql, $parameters) = static::buildQuery($object); + list($sql, $parameters) = self::buildQuery($object); if ($_replace) { - $sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql); + $sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql); } else { - $sql = 'INSERT INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql); + $sql = 'INSERT INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql); } $res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW); - $reflection = static::getReflectionClass($object); + $reflection = self::getReflectionClass($object); if ($reflection->hasProperty('id')) { try { - static::setField($object, 'id', static::getLastInsertId()); + self::setField($object, 'id', static::getLastInsertId()); } catch (Exception $exc) { trigger_error($exc->getMessage(), E_USER_NOTICE); } catch (InvalidArgumentException $ex) { @@ -234,14 +234,14 @@ public static function save($object, $_direct = false, $_replace = false) { if (method_exists($object, 'encrypt')) { $object->encrypt(); } - list($sql, $parameters) = static::buildQuery($object); + list($sql, $parameters) = self::buildQuery($object); if (!$_direct && method_exists($object, 'getId')) { $parameters['id'] = $object->getId(); //override if necessary } if ($_replace) { - $sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql); + $sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql); } else { - $sql = 'UPDATE `' . static::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id'; + $sql = 'UPDATE `' . self::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id'; } $res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW); } else { @@ -264,12 +264,12 @@ public static function save($object, $_direct = false, $_replace = false) { } public static function refresh($object) { - if (!static::getField($object, 'id')) { + if (!self::getField($object, 'id')) { throw new Exception('Can\'t refresh DB object without its ID'); } - $parameters = array('id' => static::getField($object, 'id')); + $parameters = array('id' => self::getField($object, 'id')); $sql = 'SELECT ' . static::buildField(get_class($object)) . - ' FROM `' . static::getTableName($object) . '` ' . + ' FROM `' . self::getTableName($object) . '` ' . ' WHERE '; foreach ($parameters as $field => $value) { if ($value != '') { @@ -283,14 +283,14 @@ public static function refresh($object) { if (!is_object($newObject)) { return false; } - foreach (static::getFields($object) as $field) { - $reflection = static::getReflectionClass($object); + foreach (self::getFields($object) as $field) { + $reflection = self::getReflectionClass($object); $property = $reflection->getProperty($field); if (!$reflection->hasProperty($field)) { throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field); } $property->setAccessible(true); - $property->setValue($object, static::getField($newObject, $field)); + $property->setValue($object, self::getField($newObject, $field)); $property->setAccessible(false); } return true; @@ -300,13 +300,13 @@ public static function refresh($object) { * Retourne une liste d'objets ou un objet en fonction de filtres * @param $_filters Filtres à appliquer * @param $_object Objet sur lequel appliquer les filtres - * @return Objet ou liste d'objets correspondant à la requête + * @return array|null Objet ou liste d'objets correspondant à la requête */ public static function getWithFilter(array $_filters, $_object) { // operators have to remain in this order. If you put '<' before '<=', algorithm won't make the difference & will think a '<=' is a '<' $operators = array('!=', '<=', '>=', '<', '>', 'NOT LIKE', 'LIKE', '='); - $fields = static::getFields($_object); - $class = static::getReflectionClass($_object)->getName(); + $fields = self::getFields($_object); + $class = self::getReflectionClass($_object)->getName(); // create query $query = 'SELECT ' . static::buildField($class) . ' FROM ' . $class . ''; $values = array(); @@ -365,8 +365,8 @@ public static function remove($object) { return false; } } - list($sql, $parameters) = static::buildQuery($object); - $sql = 'DELETE FROM `' . static::getTableName($object) . '` WHERE '; + list($sql, $parameters) = self::buildQuery($object); + $sql = 'DELETE FROM `' . self::getTableName($object) . '` WHERE '; if (isset($parameters['id'])) { $sql .= '`id`=:id AND '; $parameters = array('id' => $parameters['id']); @@ -381,9 +381,9 @@ public static function remove($object) { } $sql .= '1'; $res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW); - $reflection = static::getReflectionClass($object); + $reflection = self::getReflectionClass($object); if ($reflection->hasProperty('id')) { - static::setField($object, 'id', null); + self::setField($object, 'id', null); } if (method_exists($object, 'postRemove')) { $object->postRemove(); @@ -409,8 +409,8 @@ public static function lock($object) { return false; } } - list($sql, $parameters) = static::buildQuery($object); - $sql = 'SELECT * FROM ' . static::getTableName($object) . ' WHERE '; + list($sql, $parameters) = self::buildQuery($object); + $sql = 'SELECT * FROM ' . self::getTableName($object) . ' WHERE '; foreach ($parameters as $field => $value) { if ($value != '') { $sql .= '`' . $field . '`=:' . $field . ' AND '; @@ -445,23 +445,23 @@ private static function getTableName($object) { * @throws RuntimeException */ private static function getFields($object) { - $table = is_string($object) ? $object : static::getTableName($object); - if (isset(static::$fields[$table])) { - return static::$fields[$table]; + $table = is_string($object) ? $object : self::getTableName($object); + if (isset(self::$fields[$table])) { + return self::$fields[$table]; } - $reflection = is_object($object) ? static::getReflectionClass($object) : new ReflectionClass($object); + $reflection = is_object($object) ? self::getReflectionClass($object) : new ReflectionClass($object); $properties = $reflection->getProperties(); - static::$fields[$table] = array(); + self::$fields[$table] = array(); foreach ($properties as $property) { $name = $property->getName(); if ('_' !== $name[0]) { - static::$fields[$table][] = $name; + self::$fields[$table][] = $name; } } - if (empty(static::$fields[$table])) { + if (empty(self::$fields[$table])) { throw new RuntimeException('No fields found for class ' . get_class($object)); } - return static::$fields[$table]; + return self::$fields[$table]; } /** @@ -477,7 +477,7 @@ private static function setField($object, $field, $value) { if (method_exists($object, $method)) { $object->$method($value); } else { - $reflection = static::getReflectionClass($object); + $reflection = self::getReflectionClass($object); if (!$reflection->hasProperty($field)) { throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field); } @@ -499,9 +499,9 @@ private static function setField($object, $field, $value) { private static function buildQuery($object) { $parameters = array(); $sql = array(); - foreach (static::getFields($object) as $field) { + foreach (self::getFields($object) as $field) { $sql[] = '`' . $field . '` = :' . $field; - $parameters[$field] = static::getField($object, $field); + $parameters[$field] = self::getField($object, $field); } return array($sql, $parameters); } @@ -521,7 +521,7 @@ private static function getField($object, $field) { if (method_exists($object, $method)) { $retval = $object->$method(); } else { - $reflection = static::getReflectionClass($object); + $reflection = self::getReflectionClass($object); if ($reflection->hasProperty($field)) { $property = $reflection->getProperty($field); $property->setAccessible(true); @@ -552,7 +552,7 @@ private static function getReflectionClass($object) { public static function buildField($_class, $_prefix = '') { $fields = array(); - foreach (static::getFields($_class) as $field) { + foreach (self::getFields($_class) as $field) { if ('_' !== $field[0]) { if ($_prefix != '') { $fields[] = '`' . $_prefix . '`.' . '`' . $field . '`'; diff --git a/core/class/cache.class.php b/core/class/cache.class.php index 277a5293a4..71d5d59cc6 100644 --- a/core/class/cache.class.php +++ b/core/class/cache.class.php @@ -275,13 +275,13 @@ public static function isOk(){ } public static function getConnection(){ - if(static::$connection !== null){ - return static::$connection; + if(self::$connection !== null){ + return self::$connection; } $redis = new Redis(); $redis->connect(config::byKey('cache::redisaddr'), config::byKey('cache::redisport')); - static::$connection = $redis; - return static::$connection; + self::$connection = $redis; + return self::$connection; } public static function all(){ diff --git a/core/class/config.class.php b/core/class/config.class.php index a33f7d2832..14a5f34cfc 100644 --- a/core/class/config.class.php +++ b/core/class/config.class.php @@ -144,7 +144,7 @@ public static function remove(string $_key, string $_plugin = 'core') { /** * Get config by key * @param string $_key nom de la clef dont on veut la valeur - * @return string valeur de la clef + * @return mixed valeur de la clef */ public static function byKey($_key, $_plugin = 'core', $_default = '', $_forceFresh = false) { if (!$_forceFresh && isset(self::$cache[$_plugin . '::' . $_key]) && !in_array($_key, self::$nocache)) { diff --git a/core/class/event.class.php b/core/class/event.class.php index c603a7487d..b9e8558b6c 100644 --- a/core/class/event.class.php +++ b/core/class/event.class.php @@ -112,7 +112,7 @@ public static function changes($_datetime, $_longPolling = null, $_filter = null $max_cycle = $_longPolling / $waitTime; while (count($return) == 0 && $i < $max_cycle) { if ($waitTime < 1) { - usleep(1000000 * $waitTime); + usleep(1000000 * ((float) $waitTime)); } else { sleep(round($waitTime)); } diff --git a/core/class/history.class.php b/core/class/history.class.php index 9c9e4dcd6b..d923de0be6 100644 --- a/core/class/history.class.php +++ b/core/class/history.class.php @@ -237,14 +237,14 @@ public static function archive() { config::save('historyArchiveTime', 2); } if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) { - config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1); + config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1); } if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) { - config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1); + config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1); } $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')); if (config::byKey('historyArchivePackage') < 1) { - $archivePackage = '00:' . config::byKey('historyArchivePackage') * 60 . ':00'; + $archivePackage = '00:' . (int) config::byKey('historyArchivePackage') * 60 . ':00'; } else { $archivePackage = config::byKey('historyArchivePackage') . ':00:00'; if (strlen($archivePackage) < 8) { @@ -328,7 +328,7 @@ public static function archive() { $mode = $cmd->getConfiguration('historizeMode', 'avg'); $values = array( 'cmd_id' => $sensors['cmd_id'], - 'archivePackage' => config::byKey('historyArchivePackage') * 3600, + 'archivePackage' => (int) config::byKey('historyArchivePackage') * 3600, 'archiveTime' => $archiveDatetime ); $round = (is_numeric($cmd->getConfiguration('historizeRound'))) ? $cmd->getConfiguration('historizeRound') : 2; diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index d090860d81..20bd8258df 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1044,7 +1044,7 @@ public static function isDateOk() { self::forceSyncHour(); sleep(3); if (strtotime('now') < $mindate || strtotime('now') > $maxdate) { - 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'); + 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'); return false; } } diff --git a/core/class/listener.class.php b/core/class/listener.class.php index f6a22534ef..75decc5139 100644 --- a/core/class/listener.class.php +++ b/core/class/listener.class.php @@ -105,7 +105,7 @@ public static function byClass($_class) { * * @param string $_class * @param string $_function - * @param array $_option + * @param mixed $_option * @return listener */ public static function byClassAndFunction($_class, $_function, $_option = '') { @@ -129,7 +129,7 @@ public static function byClassAndFunction($_class, $_function, $_option = '') { * * @param string $_class * @param string $_function - * @param array $_option + * @param string $_option * @return array */ public static function searchClassFunctionOption($_class, $_function, $_option = '') { diff --git a/core/class/plan.class.php b/core/class/plan.class.php index 3004c54946..448317b5d5 100644 --- a/core/class/plan.class.php +++ b/core/class/plan.class.php @@ -295,7 +295,7 @@ public function getHtml($_version = 'dashboard') { } else { $camera = eqLogic::byId(str_replace(array('#', 'eqLogic'), array('', ''), $this->getConfiguration('camera'))); if (is_object($camera)) { - $html .= $camera->toHtml($_version, true); + $html .= $camera->toHtml($_version); } } $html .= ''; diff --git a/core/class/scenario.class.php b/core/class/scenario.class.php index 2b96c67bec..8b007d1ead 100644 --- a/core/class/scenario.class.php +++ b/core/class/scenario.class.php @@ -370,10 +370,11 @@ public static function check($_event = null, $_forceSyncMode = false, $_generic foreach ($scenarios2 as $scenario) { if ($scenario->testTrigger($trigger)) { $trigger_message = $GLOBALS['JEEDOM_SCLOG_TEXT']['startAutoOnEvent']['txt']; + $eventName = is_object($_event) ? $_event->getHumanName() : $_event; if (is_object($_object)) { - $trigger_message .= ' genericType(' . $_generic . ',#[' . $_object->getName() . ']#) from ' . $_event->getHumanName(); + $trigger_message .= ' genericType(' . $_generic . ',#[' . $_object->getName() . ']#) from ' . $eventName; } else { - $trigger_message .= ' genericType(' . $_generic . ')' . ' from ' . $_event->getHumanName(); + $trigger_message .= ' genericType(' . $_generic . ')' . ' from ' . $eventName; } $scenario->addTag('trigger_message',$trigger_message); $scenario->addTag('trigger_value',$_value); @@ -1697,7 +1698,7 @@ public function getLastLaunch() { } /** * - * @param int $id + * @param int $_id * @return $this */ public function setId($_id) { @@ -1707,7 +1708,7 @@ public function setId($_id) { } /** * - * @param string $name + * @param string $_name * @return $this */ public function setName($_name) { @@ -1722,7 +1723,7 @@ public function setName($_name) { } /** * - * @param bool $isActive + * @param bool $_isActive * @return $this */ public function setIsActive($_isActive) { @@ -1735,7 +1736,7 @@ public function setIsActive($_isActive) { } /** * - * @param string $group + * @param string $_group * @return $this */ public function setGroup($_group) { diff --git a/core/php/utils.inc.php b/core/php/utils.inc.php index 08b0613c92..fbce8c62af 100644 --- a/core/php/utils.inc.php +++ b/core/php/utils.inc.php @@ -1084,7 +1084,7 @@ function netMatch($network, $ip) { } $network_long = ip2long($ip_arr[0]); $x = ip2long($ip_arr[1]); - $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1])); + $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - (int) $ip_arr[1])); $ip_long = ip2long($ip); return ($ip_long & $mask) == ($network_long & $mask); } else { @@ -1125,7 +1125,7 @@ function getNtpTime() { function cast($sourceObject, $destination) { $obj_in = serialize($sourceObject); - return unserialize('O:' . strlen($destination) . ':"' . $destination . '":' . substr($obj_in, $obj_in[2] + 7)); + return unserialize('O:' . strlen($destination) . ':"' . $destination . '":' . substr($obj_in, (int) $obj_in[2] + 7)); } function getIpFromString($_string) {