From 4d307f278d73dc5754da8e75ba0df26b9af667a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Wed, 8 Mar 2023 10:05:42 +0100 Subject: [PATCH] [#431] Fix calling sizeof on non-countable. This warning has become an error in PHP 8. We also remove some unused code. --- model/dao/BelongsDAO/PostgreSQLBelongsDAO.php | 19 +++++++++---------- model/dao/UserDAO/PostgreSQLUserDAO.php | 6 ++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/model/dao/BelongsDAO/PostgreSQLBelongsDAO.php b/model/dao/BelongsDAO/PostgreSQLBelongsDAO.php index f8524dc62..94d1f1824 100644 --- a/model/dao/BelongsDAO/PostgreSQLBelongsDAO.php +++ b/model/dao/BelongsDAO/PostgreSQLBelongsDAO.php @@ -197,23 +197,22 @@ public function getByUserGroupName($userGroupName) { * @throws {@link SQLQueryErrorException} */ public function create($userId, $userGroupId) { - $affectedRows = 0; + $affectedRows = 0; - // Check for a belongs entry ID. + // Check for a belongs entry ID. $currBelongs = $this->getByIds($userId, $userGroupId); // If it doesn't exist, then create. - if(sizeof($currBelongs) == 0) { - $sql = "INSERT INTO belongs (usrid, user_groupid) VALUES (" . $userId . ", " . $userGroupId . ")"; + if(!isset($currBelongs) || sizeof($currBelongs) == 0) { + $sql = "INSERT INTO belongs (usrid, user_groupid) VALUES (" . $userId . ", " . $userGroupId . ")"; $res = pg_query($this->connect, $sql); - if ($res == NULL) throw new SQLQueryErrorException(pg_last_error()); - - $affectedRows = pg_affected_rows($res); - } + if ($res == NULL) throw new SQLQueryErrorException(pg_last_error()); - return $affectedRows; + $affectedRows = pg_affected_rows($res); + } + return $affectedRows; } /** Belongs relationship entry deleter by User id and User Group id for PostgreSQL. @@ -234,7 +233,7 @@ public function delete($userId, $userGroupId) { $currBelongs = $this->getByIds($userId, $userGroupId); // If it exists, then delete. - if(sizeof($currBelongs) > 0) { + if(isset($currBelongs) && sizeof($currBelongs) > 0) { $sql = "DELETE FROM belongs WHERE usrid=" . $userId . " AND user_groupid=" . $userGroupId; $res = pg_query($this->connect, $sql); diff --git a/model/dao/UserDAO/PostgreSQLUserDAO.php b/model/dao/UserDAO/PostgreSQLUserDAO.php index 4aed08681..879aba851 100644 --- a/model/dao/UserDAO/PostgreSQLUserDAO.php +++ b/model/dao/UserDAO/PostgreSQLUserDAO.php @@ -413,7 +413,7 @@ public function update(UserVO $userVO) { } // If the query returned a row then update - if(sizeof($currUserVO) > 0) { + if(isset($currUserVO)) { $sql = "UPDATE usr SET login=" . DBPostgres::checkStringNull($userVO->getLogin()); @@ -486,7 +486,7 @@ public function delete(UserVO $userVO) { } // Otherwise delete a user. - if(sizeof($currUserVO) > 0) { + if(isset($currUserVO)) { $sql = "DELETE FROM usr WHERE id=".$userVO->getId(); $res = pg_query($this->connect, $sql); @@ -497,8 +497,6 @@ public function delete(UserVO $userVO) { } return $affectedRows; - if (!is_numeric($userId)) - throw new SQLIncorrectTypeException($userId); } }