diff --git a/libraries/classes/Config/FormDisplay.php b/libraries/classes/Config/FormDisplay.php index 174fd19f6694..8895356b5618 100644 --- a/libraries/classes/Config/FormDisplay.php +++ b/libraries/classes/Config/FormDisplay.php @@ -588,12 +588,12 @@ public function fixErrors() /** * Validates select field and casts $value to correct type * - * @param string $value Current value - * @param array $allowed List of allowed values + * @param string|bool $value Current value + * @param array $allowed List of allowed values * * @return bool */ - private function _validateSelect(&$value, array $allowed) + private function _validateSelect(&$value, array $allowed): bool { $valueCmp = is_bool($value) ? (int) $value diff --git a/libraries/classes/Config/ServerConfigChecks.php b/libraries/classes/Config/ServerConfigChecks.php index fe109ca15327..6f8015f180b9 100644 --- a/libraries/classes/Config/ServerConfigChecks.php +++ b/libraries/classes/Config/ServerConfigChecks.php @@ -237,9 +237,9 @@ protected function performConfigChecksServers( /** * Set blowfish secret * - * @param string $blowfishSecret Blowfish secret - * @param bool $cookieAuthServer Cookie auth is used - * @param bool $blowfishSecretSet Blowfish secret set + * @param string|null $blowfishSecret Blowfish secret + * @param bool $cookieAuthServer Cookie auth is used + * @param bool $blowfishSecretSet Blowfish secret set * * @return array */ @@ -247,7 +247,7 @@ protected function performConfigChecksServersSetBlowfishSecret( $blowfishSecret, $cookieAuthServer, $blowfishSecretSet - ) { + ): array { if ($cookieAuthServer && $blowfishSecret === null) { $blowfishSecretSet = true; $this->cfg->set('blowfish_secret', Util::generateRandom(32)); diff --git a/libraries/classes/Controllers/Server/VariablesController.php b/libraries/classes/Controllers/Server/VariablesController.php index c23e9b5414eb..35472047a278 100644 --- a/libraries/classes/Controllers/Server/VariablesController.php +++ b/libraries/classes/Controllers/Server/VariablesController.php @@ -215,12 +215,12 @@ public function setValue(array $vars): void /** * Format Variable * - * @param string $name variable name - * @param int $value variable value + * @param string $name variable name + * @param int|string $value variable value * * @return array formatted string and bool if string is HTML formatted */ - private function formatVariable($name, $value) + private function formatVariable($name, $value): array { $isHtmlFormatted = false; $formattedValue = $value; diff --git a/libraries/classes/Controllers/Table/StructureController.php b/libraries/classes/Controllers/Table/StructureController.php index 314b6facc3f6..c03868d26b63 100644 --- a/libraries/classes/Controllers/Table/StructureController.php +++ b/libraries/classes/Controllers/Table/StructureController.php @@ -658,15 +658,14 @@ public function moveColumns(): void $data = $columns[$column]; $extracted_columnspec = Util::extractColumnSpec($data['Type']); if (isset($data['Extra']) - && $data['Extra'] == 'on update CURRENT_TIMESTAMP' + && $data['Extra'] === 'on update CURRENT_TIMESTAMP' ) { $extracted_columnspec['attribute'] = $data['Extra']; unset($data['Extra']); } - $current_timestamp = ($data['Type'] == 'timestamp' - || $data['Type'] == 'datetime') - && ($data['Default'] == 'CURRENT_TIMESTAMP' - || $data['Default'] == 'current_timestamp()'); + $timeType = $data['Type'] === 'timestamp' || $data['Type'] === 'datetime'; + $timeDefault = $data['Default'] === 'CURRENT_TIMESTAMP' || $data['Default'] === 'current_timestamp()'; + $current_timestamp = $timeType && $timeDefault; // @see https://mariadb.com/kb/en/library/information-schema-columns-table/#examples if ($data['Null'] === 'YES' && in_array($data['Default'], [$defaultNullValue, null])) { diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 042f84a0a09a..4e955430f8ad 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -437,7 +437,7 @@ public function openFile(string $filename, bool $quick_export): array } else { $file_handle = @fopen($save_filename, 'w'); - if (! $file_handle) { + if ($file_handle === false) { $message = Message::error( __( 'The web server does not have permission ' diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 4710a1a271e1..75910ca05357 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -1351,7 +1351,7 @@ private function getQueryResponseForNoResultsReturned( true ); - if (is_array($profiling_results)) { + if ($profiling_results !== null) { $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('sql.js'); @@ -1424,18 +1424,18 @@ private function getBookmarkCreatedMessage(): string /** * Function to get html for the sql query results table * - * @param DisplayResults $displayResultsObject instance of DisplayResult - * @param string $pmaThemeImage theme image uri - * @param string $url_query url query - * @param array $displayParts the parts to display - * @param bool $editable whether the result table is - * editable or not - * @param int $unlim_num_rows unlimited number of rows - * @param int $num_rows number of rows - * @param bool $showtable whether to show table or not - * @param object|null $result result of the executed query - * @param array $analyzed_sql_results analyzed sql results - * @param bool $is_limited_display Show only limited operations or not + * @param DisplayResults $displayResultsObject instance of DisplayResult + * @param string $pmaThemeImage theme image uri + * @param string $url_query url query + * @param array $displayParts the parts to display + * @param bool $editable whether the result table is + * editable or not + * @param int $unlim_num_rows unlimited number of rows + * @param int $num_rows number of rows + * @param bool $showtable whether to show table or not + * @param object|null|bool $result result of the executed query + * @param array $analyzed_sql_results analyzed sql results + * @param bool $is_limited_display Show only limited operations or not * * @return string */ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2efcb325debd..e909cccf78c2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -205,11 +205,6 @@ parameters: count: 2 path: libraries/classes/Config/FormDisplay.php - - - message: "#^Call to function is_bool\\(\\) with string will always evaluate to false\\.$#" - count: 2 - path: libraries/classes/Config/FormDisplay.php - - message: "#^Parameter \\#2 \\$type of function settype expects string, string\\|null given\\.$#" count: 1 @@ -240,16 +235,6 @@ parameters: count: 1 path: libraries/classes/Config/Forms/BaseFormList.php - - - message: "#^Result of && is always false\\.$#" - count: 1 - path: libraries/classes/Config/ServerConfigChecks.php - - - - message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Config/ServerConfigChecks.php - - message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, string given\\.$#" count: 1 @@ -3860,16 +3845,6 @@ parameters: count: 1 path: libraries/classes/Sql.php - - - message: "#^Call to function is_bool\\(\\) with object will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Sql.php - - - - message: "#^Call to function is_bool\\(\\) with object\\|null will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Sql.php - - message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\Sql\\:\\:sendResponseForGridEdit\\(\\) expects object, object\\|null given\\.$#" count: 1 @@ -4560,11 +4535,6 @@ parameters: count: 1 path: test/classes/ErrorHandlerTest.php - - - message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\|bool given\\.$#" - count: 1 - path: test/classes/FileListingTest.php - - message: "#^Parameter \\#1 \\$data of function bin2hex expects string, string\\|false given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 251d46bc035f..f1f3cf2dd99b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -114,11 +114,10 @@ - + $workPath $workPath $_POST[$key] - $_POST[$key] $workPath @@ -2353,10 +2352,11 @@ - + $showtable $showtable $result + $result '' @@ -2367,10 +2367,12 @@ save save - + $cfgBookmark + $result $fields_meta $result + $result $fields_meta $cfgBookmark @@ -2379,7 +2381,7 @@ $cfgBookmark['user'] $cfgBookmark['user'] - + $db $table $db @@ -2391,7 +2393,6 @@ $printview $printview $result - $result $url_query $showtable $sql_data ?? null diff --git a/test/classes/FileListingTest.php b/test/classes/FileListingTest.php index dae8a6dc51b5..e2379fe04ae0 100644 --- a/test/classes/FileListingTest.php +++ b/test/classes/FileListingTest.php @@ -27,12 +27,16 @@ public function testGetDirContent(): void $fixturesDir = ROOT_PATH . 'test/classes/_data/file_listing'; + $dirContent = $this->fileListing->getDirContent($fixturesDir); + if (is_bool($dirContent)) { + $dirContent = []; + } $this->assertSame( array_values([ 'one.txt', 'two.md', ]), - array_values($this->fileListing->getDirContent($fixturesDir)) + array_values($dirContent) ); }