From f85b88d1e1c0d52687ed112173a9232efbb44500 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:08:31 +0000 Subject: [PATCH 1/6] Enable checkAlwaysTrue* Signed-off-by: Kamil Tekiela --- phpstan.neon.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 70c09c2b38..bc8ba87917 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -30,3 +30,5 @@ parameters: # Allow dynamic calls to static methods. strictCalls: false checkBenevolentUnionTypes: true + checkAlwaysTrueCheckTypeFunctionCall: true + checkAlwaysTrueStrictComparison: true From e41cfea7e561b3199ffff54f69e71f071883ddc8 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:09:37 +0000 Subject: [PATCH 2/6] Enable checkUninitializedProperties Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 +++++ phpstan.neon.dist | 1 + 2 files changed, 6 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 33c53b8514..69cd689e9b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7955,6 +7955,11 @@ parameters: count: 1 path: libraries/classes/Server/Privileges.php + - + message: "#^Access to an uninitialized property PhpMyAdmin\\\\Server\\\\Status\\\\Data\\:\\:\\$replicationInfo\\.$#" + count: 2 + path: libraries/classes/Server/Status/Data.php + - message: "#^Method PhpMyAdmin\\\\Server\\\\Status\\\\Data\\:\\:calculateValues\\(\\) has parameter \\$server_status with no value type specified in iterable type array\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bc8ba87917..5a9d1392ef 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -32,3 +32,4 @@ parameters: checkBenevolentUnionTypes: true checkAlwaysTrueCheckTypeFunctionCall: true checkAlwaysTrueStrictComparison: true + checkUninitializedProperties: true From f944f7dcd2ea1c08845f68f668292706053950e6 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:13:19 +0000 Subject: [PATCH 3/6] Enable polluteScopeWithAlwaysIterableForeach Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 40 ++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 1 + 2 files changed, 41 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 69cd689e9b..faa5425b36 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -895,6 +895,21 @@ parameters: count: 1 path: libraries/classes/ConfigStorage/Relation.php + - + message: "#^Foreach overwrites \\$feature with its value variable\\.$#" + count: 1 + path: libraries/classes/ConfigStorage/Relation.php + + - + message: "#^Foreach overwrites \\$table with its key variable\\.$#" + count: 1 + path: libraries/classes/ConfigStorage/Relation.php + + - + message: "#^Foreach overwrites \\$work with its key variable\\.$#" + count: 1 + path: libraries/classes/ConfigStorage/Relation.php + - message: "#^Method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:buildForeignDropdown\\(\\) has parameter \\$foreign with no value type specified in iterable type array\\.$#" count: 1 @@ -4550,6 +4565,11 @@ parameters: count: 1 path: libraries/classes/Gis/GisMultiPolygon.php + - + message: "#^Variable \\$label_point in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: libraries/classes/Gis/GisMultiPolygon.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPoint\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -5020,6 +5040,11 @@ parameters: count: 2 path: libraries/classes/Import.php + - + message: "#^Parameter \\#1 \\$sql of method PhpMyAdmin\\\\Import\\:\\:executeQuery\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: libraries/classes/Import.php + - message: "#^Parameter \\#1 \\$sql of method PhpMyAdmin\\\\Import\\:\\:runQuery\\(\\) expects string, \\(array\\\\|string\\|null\\) given\\.$#" count: 1 @@ -6495,6 +6520,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Export/ExportYaml.php + - + message: "#^Foreach overwrites \\$width with its value variable\\.$#" + count: 2 + path: libraries/classes/Plugins/Export/Helpers/Pdf.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\Helpers\\\\Pdf\\:\\:getTableDef\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#" count: 1 @@ -8550,6 +8580,11 @@ parameters: count: 5 path: libraries/classes/Table.php + - + message: "#^Foreach overwrites \\$trigger with its value variable\\.$#" + count: 1 + path: libraries/classes/Table.php + - message: "#^Method PhpMyAdmin\\\\Table\\:\\:duplicateInfo\\(\\) has parameter \\$getFields with no value type specified in iterable type array\\.$#" count: 1 @@ -8920,6 +8955,11 @@ parameters: count: 1 path: libraries/classes/Tracker.php + - + message: "#^Foreach overwrites \\$logEntry with its value variable\\.$#" + count: 1 + path: libraries/classes/Tracker.php + - message: "#^Method PhpMyAdmin\\\\Tracker\\:\\:changeTrackingData\\(\\) has parameter \\$newData with no value type specified in iterable type array\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5a9d1392ef..081eb947db 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -33,3 +33,4 @@ parameters: checkAlwaysTrueCheckTypeFunctionCall: true checkAlwaysTrueStrictComparison: true checkUninitializedProperties: true + polluteScopeWithAlwaysIterableForeach: true From 51a855a5cc75f6de5792981d2f0132b72894e44a Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:17:15 +0000 Subject: [PATCH 4/6] Enable checkDynamicProperties Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 55 +++++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 1 + 2 files changed, 56 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index faa5425b36..37900adbab 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3585,6 +3585,36 @@ parameters: count: 1 path: libraries/classes/Dbal/MysqliResult.php + - + message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$expr\\.$#" + count: 1 + path: libraries/classes/Display/Results.php + + - + message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$from\\.$#" + count: 2 + path: libraries/classes/Display/Results.php + + - + message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$limit\\.$#" + count: 1 + path: libraries/classes/Display/Results.php + + - + message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$where\\.$#" + count: 1 + path: libraries/classes/Display/Results.php + + - + message: "#^Access to an undefined property object\\:\\:\\$column\\.$#" + count: 1 + path: libraries/classes/Display/Results.php + + - + message: "#^Access to an undefined property object\\:\\:\\$database\\.$#" + count: 1 + path: libraries/classes/Display/Results.php + - message: "#^Cannot access offset int\\<0, max\\> on mixed\\.$#" count: 2 @@ -5655,6 +5685,11 @@ parameters: count: 1 path: libraries/classes/Navigation/Navigation.php + - + message: "#^Access to an undefined property PhpMyAdmin\\\\Navigation\\\\Nodes\\\\Node\\:\\:\\$secondIcon\\.$#" + count: 2 + path: libraries/classes/Navigation/NavigationTree.php + - message: "#^Cannot access property \\$pos2 on PhpMyAdmin\\\\Navigation\\\\Nodes\\\\Node\\|null\\.$#" count: 1 @@ -8340,6 +8375,11 @@ parameters: count: 1 path: libraries/classes/Sql.php + - + message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$where\\.$#" + count: 1 + path: libraries/classes/Sql.php + - message: "#^Method PhpMyAdmin\\\\Sql\\:\\:countQueryResults\\(\\) should return int\\|numeric\\-string but returns mixed\\.$#" count: 1 @@ -9545,6 +9585,21 @@ parameters: count: 1 path: libraries/classes/Utils/HttpRequest.php + - + message: "#^Access to an undefined property object\\:\\:\\$date\\.$#" + count: 1 + path: libraries/classes/VersionInformation.php + + - + message: "#^Access to an undefined property object\\:\\:\\$releases\\.$#" + count: 1 + path: libraries/classes/VersionInformation.php + + - + message: "#^Access to an undefined property object\\:\\:\\$version\\.$#" + count: 1 + path: libraries/classes/VersionInformation.php + - message: "#^Comparison operation \"\\>\\=\" between int\\<1, max\\> and 1 is always true\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 081eb947db..0af0ffeeea 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -34,3 +34,4 @@ parameters: checkAlwaysTrueStrictComparison: true checkUninitializedProperties: true polluteScopeWithAlwaysIterableForeach: true + checkDynamicProperties: true From affd2b9d7f62a6438bda2c64a5c1200d93ebc94f Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:18:29 +0000 Subject: [PATCH 5/6] Enable checkTooWideReturnTypesInProtectedAndPublicMethods Signed-off-by: Kamil Tekiela --- libraries/classes/Dbal/MysqliResult.php | 7 ++++++- phpstan-baseline.neon | 10 ++++++++++ phpstan.neon.dist | 1 + test/classes/Stubs/DummyResult.php | 7 ++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Dbal/MysqliResult.php b/libraries/classes/Dbal/MysqliResult.php index 8ef1deb00d..69aec39d18 100644 --- a/libraries/classes/Dbal/MysqliResult.php +++ b/libraries/classes/Dbal/MysqliResult.php @@ -13,6 +13,7 @@ use PhpMyAdmin\FieldMetadata; use Webmozart\Assert\Assert; use function array_column; +use function array_key_exists; use function is_array; use function is_bool; use function is_string; @@ -104,7 +105,11 @@ final class MysqliResult implements ResultInterface $row = $this->fetchRow(); } - return $row[$field] ?? false; + if (! array_key_exists($field, $row)) { + return false; + } + + return $row[$field]; } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 37900adbab..a1d5d4a5a1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6910,6 +6910,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Import/ImportXml.php + - + message: "#^Method PhpMyAdmin\\\\Plugins\\\\Import\\\\ShapeFileImport\\:\\:readSHP\\(\\) never returns false so it can be removed from the return type\\.$#" + count: 1 + path: libraries/classes/Plugins/Import/ShapeFileImport.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Import\\\\Upload\\\\UploadNoplugin\\:\\:getUploadStatus\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -11805,6 +11810,11 @@ parameters: count: 1 path: test/classes/StorageEngineTest.php + - + message: "#^Method PhpMyAdmin\\\\Tests\\\\Stubs\\\\DbiDummy\\:\\:connect\\(\\) never returns null so it can be removed from the return type\\.$#" + count: 1 + path: test/classes/Stubs/DbiDummy.php + - message: "#^Method PhpMyAdmin\\\\Tests\\\\Stubs\\\\DbiDummy\\:\\:fetchAny\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0af0ffeeea..f6e4df5439 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -35,3 +35,4 @@ parameters: checkUninitializedProperties: true polluteScopeWithAlwaysIterableForeach: true checkDynamicProperties: true + checkTooWideReturnTypesInProtectedAndPublicMethods: true diff --git a/test/classes/Stubs/DummyResult.php b/test/classes/Stubs/DummyResult.php index e062db7b69..cf24c74cf4 100644 --- a/test/classes/Stubs/DummyResult.php +++ b/test/classes/Stubs/DummyResult.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Dbal\ResultInterface; use PhpMyAdmin\FieldMetadata; use function array_column; +use function array_key_exists; use function is_string; /** @@ -103,7 +104,11 @@ class DummyResult implements ResultInterface $row = $this->fetchRow(); } - return $row[$field] ?? false; + if (! array_key_exists($field, $row)) { + return false; + } + + return $row[$field]; } /** From c9f29281a9441c6f4c0cd475080b47a0ee5c8c9e Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 14 Feb 2023 21:23:30 +0000 Subject: [PATCH 6/6] Enable polluteScopeWithLoopInitialAssignments Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 75 +++++++++++++++++++++++++++++++++++++------ phpstan.neon.dist | 1 + 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a1d5d4a5a1..dbc5e33848 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2405,6 +2405,11 @@ parameters: count: 1 path: libraries/classes/Controllers/Table/Structure/SaveController.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 2 + path: libraries/classes/Controllers/Table/Structure/SaveController.php + - message: "#^Method PhpMyAdmin\\\\Controllers\\\\Table\\\\Structure\\\\SaveController\\:\\:adjustColumnPrivileges\\(\\) has parameter \\$adjust_privileges with no value type specified in iterable type array\\.$#" count: 1 @@ -2885,6 +2890,11 @@ parameters: count: 1 path: libraries/classes/Database/Qbe.php + - + message: "#^For loop initial assignment overwrites variable \\$columnIndex\\.$#" + count: 1 + path: libraries/classes/Database/Qbe.php + - message: "#^Method PhpMyAdmin\\\\Database\\\\Qbe\\:\\:__construct\\(\\) has parameter \\$savedSearchList with no value type specified in iterable type array\\.$#" count: 1 @@ -3185,6 +3195,11 @@ parameters: count: 1 path: libraries/classes/Database/Routines.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 2 + path: libraries/classes/Database/Routines.php + - message: "#^Method PhpMyAdmin\\\\Database\\\\Routines\\:\\:backupPrivileges\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -4895,11 +4910,6 @@ parameters: count: 2 path: libraries/classes/Git.php - - - message: "#^Variable \\$position might not be defined\\.$#" - count: 1 - path: libraries/classes/Git.php - - message: "#^Method PhpMyAdmin\\\\Header\\:\\:getJsParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -5000,6 +5010,11 @@ parameters: count: 2 path: libraries/classes/Import.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 5 + path: libraries/classes/Import.php + - message: "#^Foreach overwrites \\$sqlQuery with its value variable\\.$#" count: 1 @@ -6300,6 +6315,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Export/ExportLatex.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 3 + path: libraries/classes/Plugins/Export/ExportMediawiki.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportMediawiki\\:\\:exportData\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#" count: 1 @@ -6410,6 +6430,11 @@ parameters: count: 2 path: libraries/classes/Plugins/Export/ExportSql.php + - + message: "#^Foreach overwrites \\$j with its key variable\\.$#" + count: 1 + path: libraries/classes/Plugins/Export/ExportSql.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportData\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#" count: 1 @@ -6555,6 +6580,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Export/ExportYaml.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 1 + path: libraries/classes/Plugins/Export/Helpers/Pdf.php + - message: "#^Foreach overwrites \\$width with its value variable\\.$#" count: 2 @@ -6635,11 +6665,6 @@ parameters: count: 1 path: libraries/classes/Plugins/Export/Helpers/Pdf.php - - - message: "#^Variable \\$columns_cnt might not be defined\\.$#" - count: 6 - path: libraries/classes/Plugins/Export/Helpers/Pdf.php - - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\Helpers\\\\TableProperty\\:\\:__construct\\(\\) has parameter \\$row with no value type specified in iterable type array\\.$#" count: 1 @@ -6775,6 +6800,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Import/ImportMediawiki.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 2 + path: libraries/classes/Plugins/Import/ImportOds.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportOds\\:\\:iterateOverColumns\\(\\) has parameter \\$col_names with no value type specified in iterable type array\\.$#" count: 1 @@ -6875,6 +6905,11 @@ parameters: count: 1 path: libraries/classes/Plugins/Import/ImportXml.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 1 + path: libraries/classes/Plugins/Import/ImportXml.php + - message: "#^Offset 'charset' does not exist on SimpleXMLElement\\|null\\.$#" count: 1 @@ -7000,6 +7035,11 @@ parameters: count: 2 path: libraries/classes/Plugins/Schema/Eps/TableStatsEps.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 1 + path: libraries/classes/Plugins/Schema/Pdf/Pdf.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\Pdf\\:\\:row\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -7035,6 +7075,11 @@ parameters: count: 2 path: libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php + - + message: "#^For loop initial assignment overwrites variable \\$size\\.$#" + count: 1 + path: libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php + - message: "#^Method PhpMyAdmin\\\\Plugins\\\\Schema\\\\Pdf\\\\PdfRelationSchema\\:\\:dataDictionaryDoc\\(\\) has parameter \\$alltables with no value type specified in iterable type array\\.$#" count: 1 @@ -9285,6 +9330,11 @@ parameters: count: 1 path: libraries/classes/Tracking.php + - + message: "#^Foreach overwrites \\$file with its value variable\\.$#" + count: 1 + path: libraries/classes/Transformations.php + - message: "#^Method PhpMyAdmin\\\\Transformations\\:\\:getAvailableMimeTypes\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -9420,6 +9470,11 @@ parameters: count: 5 path: libraries/classes/Util.php + - + message: "#^For loop initial assignment overwrites variable \\$i\\.$#" + count: 1 + path: libraries/classes/Util.php + - message: "#^Foreach overwrites \\$quote with its value variable\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f6e4df5439..0168a9e63c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -36,3 +36,4 @@ parameters: polluteScopeWithAlwaysIterableForeach: true checkDynamicProperties: true checkTooWideReturnTypesInProtectedAndPublicMethods: true + polluteScopeWithLoopInitialAssignments: true