From 51e700cd10f21e9452b5fafd1278d2d992571001 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 28 Apr 2022 14:17:30 +0900 Subject: [PATCH] Fixes from phan/phpstan tests --- phpstan-baseline.neon | 67 ++++++++++++++++++++++++++++++- phpstan.neon | 9 ++++- www/admin/class_test.system.php | 1 - www/lib/CoreLibs/ACL/Login.php | 5 ++- www/lib/CoreLibs/DB/SQL/PgSQL.php | 2 +- 5 files changed, 78 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9e809591..3a8baca9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,72 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#1 \\$result of function pg_result_error expects resource, object\\|resource\\|true given\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" + 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\\.$#" count: 1 path: www/lib/CoreLibs/DB/SQL/PgSQL.php diff --git a/phpstan.neon b/phpstan.neon index b5976e7c..16f0117f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,7 +24,9 @@ parameters: # do not check old qq file uploader tests - www/admin/qq_file_upload_*.php # ignore all test files - - www/admin/class_test*php + - www/admin/class_test*.php + # extra in sub folder + - www/admin/subfolder/class_test*.php - www/admin/error_test.php # admin synlink files - www/admin/edit_*.php @@ -47,9 +49,12 @@ parameters: - www/vendor # ignore errores with ignoreErrors: - - # this error is ignore because of the PHP 8.0 to 8.1 change for pg_* + - # 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\\.$#" + path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php # this is ignored for now # - '#Expression in empty\(\) is always falsy.#' # - diff --git a/www/admin/class_test.system.php b/www/admin/class_test.system.php index bed402f5..dfd1f25b 100644 --- a/www/admin/class_test.system.php +++ b/www/admin/class_test.system.php @@ -42,7 +42,6 @@ $log = new CoreLibs\Debug\Logging([ 'echo_all' => $ECHO_ALL ?? false, 'print_all' => $PRINT_ALL ?? false, ]); -$basic = new CoreLibs\Basic($log); print ""; print "TEST CLASS: SYSTEM"; diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index c51fd0fb..57de99ea 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -818,6 +818,7 @@ class Login } // set the default edit access $this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'] ?? null; + $this->acl['min'] = []; // integrate the type acl list, but only for the keyword -> level foreach ($this->default_acl_list as $level => $data) { $this->acl['min'][$data['type']] = $level; @@ -846,6 +847,8 @@ class Login ) { return false; } + // phan claims $this->acl['min'] can be null, but above should skip + /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */ if ($this->acl[$source] >= $this->acl['min'][$min_access]) { return true; } @@ -1492,7 +1495,7 @@ EOM; /** * Return ACL array as is * - * @return array + * @return array */ public function loginGetAcl(): array { diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.php b/www/lib/CoreLibs/DB/SQL/PgSQL.php index 9a3dee7f..9f8e07ac 100644 --- a/www/lib/CoreLibs/DB/SQL/PgSQL.php +++ b/www/lib/CoreLibs/DB/SQL/PgSQL.php @@ -604,7 +604,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions return ''; } // extract element - $return_string = pg_version($this->dbh)[$parameter] ?? ''; + $return_string = (string)(pg_version($this->dbh)[$parameter] ?? ''); // for version, strip if requested if ( in_array($parameter, ['server']) &&