From 4b3fbaa309f9fd3c35bf55ebb364d4073dcb5a76 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 2 Sep 2022 17:00:22 +0900 Subject: [PATCH] Updates based on latest phpstan run --- phpstan-baseline.neon | 43 +++++----------------- phpstan.neon | 8 ++-- www/lib/CoreLibs/DB/IO.php | 6 +-- www/lib/CoreLibs/Debug/Logging.php | 2 +- www/lib/CoreLibs/Template/SmartyExtend.php | 2 +- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3a8baca9..c317b77b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,72 +1,47 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#1 \\$connection of function pg_connection_busy expects PgSql\\\\Connection, object\\|resource given\\.$#" - count: 3 - path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - - - message: "#^Parameter \\#1 \\$connection of function pg_connection_status expects PgSql\\\\Connection, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_escape_bytea expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$connection of function pg_get_result expects PgSql\\\\Connection, object\\|resource given\\.$#" - count: 2 - path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - - - message: "#^Parameter \\#1 \\$connection of function pg_meta_data expects PgSql\\\\Connection, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_escape_identifier expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$connection of function pg_send_query expects PgSql\\\\Connection, object\\|resource given\\.$#" - count: 2 - path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - - - message: "#^Parameter \\#1 \\$connection of function pg_socket expects PgSql\\\\Connection, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_escape_literal expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$connection of function pg_version expects PgSql\\\\Connection\\|null, object\\|resource given\\.$#" - count: 2 - path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - - - message: "#^Parameter \\#1 \\$result of function pg_affected_rows expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_escape_string expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$result of function pg_fetch_all expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_execute expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$result of function pg_fetch_array expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_parameter_status expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$result of function pg_field_name expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_prepare expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$result of function pg_num_fields expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_query expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - message: "#^Parameter \\#1 \\$result of function pg_num_rows expects PgSql\\\\Result, object\\|resource given\\.$#" - count: 1 - path: www/lib/CoreLibs/DB/SQL/PgSQL.php - - - - message: "#^Parameter \\#1 \\$result of function pg_result_error expects PgSql\\\\Result, object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$connection of function pg_query_params expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php diff --git a/phpstan.neon b/phpstan.neon index 16f0117f..1bfd96fb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -49,11 +49,11 @@ parameters: - www/vendor # ignore errores with ignoreErrors: - - # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower - message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#" - path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php + #- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower + # message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#" + # path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php - # this is for 8.1 or newer - message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|null)?), object\\|resource given\\.$#" + message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|string)?(\\|null)?), object\\|resource given\\.$#" path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php # this is ignored for now # - '#Expression in empty\(\) is always falsy.#' diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 83bc6b61..0144e691 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -2580,9 +2580,9 @@ class IO // loop through the write array and each field to build the query foreach ($write_array as $field) { if ( - (empty($primary_key['value']) || - (!empty($primary_key['value']) && - !in_array($field, $not_write_update_array)) + ( + empty($primary_key['value']) || + !in_array($field, $not_write_update_array) ) && !in_array($field, $not_write_array) ) { diff --git a/www/lib/CoreLibs/Debug/Logging.php b/www/lib/CoreLibs/Debug/Logging.php index f9e70327..b07ce0f7 100644 --- a/www/lib/CoreLibs/Debug/Logging.php +++ b/www/lib/CoreLibs/Debug/Logging.php @@ -173,7 +173,7 @@ class Logging // can be overridden with basicSetLogFileId later if (!empty($this->options['file_id'])) { - $this->setLogId($this->options['file_id'] ?? ''); + $this->setLogId($this->options['file_id']); } elseif (!empty($GLOBALS['LOG_FILE_ID'])) { // legacy flow, should be removed and only set via options $this->setLogId($GLOBALS['LOG_FILE_ID']); diff --git a/www/lib/CoreLibs/Template/SmartyExtend.php b/www/lib/CoreLibs/Template/SmartyExtend.php index 460a9c82..ee42ecf8 100644 --- a/www/lib/CoreLibs/Template/SmartyExtend.php +++ b/www/lib/CoreLibs/Template/SmartyExtend.php @@ -423,7 +423,7 @@ class SmartyExtend extends \Smarty $this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0; // top menu $this->DATA['nav_menu'] = $cms->adbTopMenu(); - $this->DATA['nav_menu_count'] = is_array($this->DATA['nav_menu']) ? count($this->DATA['nav_menu']) : 0; + $this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']); // messages = ['msg' =>, 'class' => 'error/warning/...'] $this->DATA['messages'] = $cms->messages; } else { /** @phpstan-ignore-line Because I assume object for phpstan */