From 0f8a3c7e72c36d78baa5e3e6fc4770fb2604af61 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 14:54:01 +0000 Subject: [PATCH 1/8] Remove unnecessary nullability Signed-off-by: Kamil Tekiela --- src/Config/FormDisplay.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Config/FormDisplay.php b/src/Config/FormDisplay.php index 874b2aecb8..feafec89ff 100644 --- a/src/Config/FormDisplay.php +++ b/src/Config/FormDisplay.php @@ -204,17 +204,17 @@ class FormDisplay /** * Outputs HTML for forms * - * @param bool $showButtons whether show submit and reset button - * @param string|null $formAction action attribute for the form - * @param mixed[]|null $hiddenFields array of form hidden fields (key: field + * @param bool $showButtons whether show submit and reset button + * @param string $formAction action attribute for the form + * @param mixed[] $hiddenFields array of form hidden fields (key: field * name) * * @return string HTML for forms */ public function getDisplay( bool $showButtons = true, - string|null $formAction = null, - array|null $hiddenFields = null, + string $formAction = '', + array $hiddenFields = [], ): string { $fieldValidators = []; $defaultValues = []; @@ -293,7 +293,7 @@ class FormDisplay return $this->formDisplayTemplate->display([ 'action' => $formAction, 'has_check_page_refresh' => self::$hasCheckPageRefresh, - 'hidden_fields' => (array) $hiddenFields, + 'hidden_fields' => $hiddenFields, 'tabs' => $tabs, 'forms' => $forms, 'show_buttons' => $showButtons, From 2348ae8342c349b865e831846239dd37cce8c41c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 15:20:46 +0000 Subject: [PATCH 2/8] Refactor storeTheQueryAsBookmark Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 2 +- src/Controllers/Import/ImportController.php | 4 ---- src/Sql.php | 9 ++------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a98fdba9b4..68e310d301 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16039,7 +16039,7 @@ parameters: path: src/Sql.php - - message: '#^Parameter \#5 \$bookmarkLabel of method PhpMyAdmin\\Sql\:\:storeTheQueryAsBookmark\(\) expects string, mixed given\.$#' + message: '#^Parameter \#4 \$bookmarkLabel of method PhpMyAdmin\\Sql\:\:storeTheQueryAsBookmark\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Sql.php diff --git a/src/Controllers/Import/ImportController.php b/src/Controllers/Import/ImportController.php index 9252972603..aa196c117d 100644 --- a/src/Controllers/Import/ImportController.php +++ b/src/Controllers/Import/ImportController.php @@ -664,10 +664,7 @@ final class ImportController implements InvocableController // since only one bookmark has to be added for all the queries submitted through // the SQL tab if (! empty($request->getParsedBodyParam('bkm_label')) && ! empty($GLOBALS['import_text'])) { - $relation = new Relation($this->dbi); - $this->sql->storeTheQueryAsBookmark( - $relation->getRelationParameters()->bookmarkFeature, Current::$database, $config->selectedServer['user'], $request->getParsedBodyParamAsString('sql_query'), @@ -695,7 +692,6 @@ final class ImportController implements InvocableController $relation = new Relation($this->dbi); $this->sql->storeTheQueryAsBookmark( - $relation->getRelationParameters()->bookmarkFeature, Current::$database, $config->selectedServer['user'], $request->getParsedBodyParamAsString('sql_query'), diff --git a/src/Sql.php b/src/Sql.php index 34812390b4..8aa1120663 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace PhpMyAdmin; use PhpMyAdmin\Bookmarks\BookmarkRepository; -use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\ConfigStorage\RelationCleanup; use PhpMyAdmin\Dbal\DatabaseInterface; @@ -508,15 +507,13 @@ class Sql * @param bool $bookmarkReplace whether to replace existing bookmarks */ public function storeTheQueryAsBookmark( - BookmarkFeature|null $bookmarkFeature, string $db, string $bookmarkUser, string $sqlQueryForBookmark, string $bookmarkLabel, bool $bookmarkReplace, ): void { - // Should we replace bookmark? - if ($bookmarkReplace && $bookmarkFeature !== null) { + if ($bookmarkReplace) { $bookmarks = $this->bookmarkRepository->getList($this->config->selectedServer['user'], $db); foreach ($bookmarks as $bookmark) { if ($bookmark->getLabel() !== $bookmarkLabel) { @@ -759,11 +756,9 @@ class Sql // If there are no errors and bookmarklabel was given, // store the query as a bookmark if (! empty($_POST['bkm_label']) && $sqlQueryForBookmark) { - $bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature; $this->storeTheQueryAsBookmark( - $bookmarkFeature, $db, - $bookmarkFeature !== null ? $this->config->selectedServer['user'] : '', + $this->config->selectedServer['user'], $sqlQueryForBookmark, $_POST['bkm_label'], isset($_POST['bkm_replace']), From 29215850899fb0085790785a0a4227ec25f4e9d0 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 21:50:36 +0000 Subject: [PATCH 3/8] Remove unnecessary nullability Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 3 ++- src/Sql.php | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 68e310d301..3edc589e5d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16027,7 +16027,7 @@ parameters: path: src/Sql.php - - message: '#^Parameter \#3 \$column of method PhpMyAdmin\\Sql\:\:cleanupRelations\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#3 \$column of method PhpMyAdmin\\Sql\:\:cleanupRelations\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Sql.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7ce1f1f1f5..4ddc6ca68b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -9356,7 +9356,7 @@ - + @@ -9364,6 +9364,7 @@ + diff --git a/src/Sql.php b/src/Sql.php index 8aa1120663..d468f1fe62 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -584,19 +584,19 @@ class Sql /** * If a table, database or column gets dropped, clean comments. * - * @param string $db current database - * @param string $table current table - * @param string|null $column current column - * @param bool $purge whether purge set or not + * @param string $db current database + * @param string $table current table + * @param string $column current column + * @param bool $purge whether purge set or not */ - private function cleanupRelations(string $db, string $table, string|null $column, bool $purge): void + private function cleanupRelations(string $db, string $table, string $column, bool $purge): void { if (! $purge || $db === '') { return; } if ($table !== '') { - if ($column !== null && $column !== '') { + if ($column !== '') { $this->relationCleanup->column($db, $table, $column); } else { $this->relationCleanup->table($db, $table); @@ -776,7 +776,7 @@ class Sql $unlimNumRows = $this->countQueryResults($numRows, $justBrowsing, $db, $table ?? '', $statementInfo); - $this->cleanupRelations($db, $table ?? '', $_POST['dropped_column'] ?? null, ! empty($_POST['purge'])); + $this->cleanupRelations($db, $table ?? '', $_POST['dropped_column'] ?? '', ! empty($_POST['purge'])); return [$result, $numRows, $unlimNumRows, $profilingResults, $errorMessage]; } From de5c7b544b141a39e120c137804c7209decb81c6 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 22:01:53 +0000 Subject: [PATCH 4/8] Remove nullability in Sql Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 20 ++----- psalm-baseline.xml | 5 +- src/Controllers/Import/ImportController.php | 4 +- src/Controllers/Sql/SqlController.php | 4 +- .../Table/DeleteRowsController.php | 4 +- src/Controllers/Table/SearchController.php | 4 +- .../Table/Structure/BrowseController.php | 4 +- src/Database/MultiTableQuery.php | 6 +- src/Sql.php | 58 +++++++++---------- tests/unit/SqlTest.php | 4 +- 10 files changed, 49 insertions(+), 64 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3edc589e5d..8e8c94412e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3916,13 +3916,13 @@ parameters: path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#5 \$sqlQueryForBookmark of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#5 \$sqlQueryForBookmark of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#6 \$messageToShow of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#6 \$messageToShow of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php @@ -15945,19 +15945,13 @@ parameters: - message: '#^Only booleans are allowed in &&, string given on the right side\.$#' identifier: booleanAnd.rightNotBoolean - count: 2 - path: src/Sql.php - - - - message: '#^Only booleans are allowed in &&, string\|null given on the left side\.$#' - identifier: booleanAnd.leftNotBoolean - count: 1 + count: 3 path: src/Sql.php - message: '#^Only booleans are allowed in &&, string\|null given on the right side\.$#' identifier: booleanAnd.rightNotBoolean - count: 2 + count: 1 path: src/Sql.php - @@ -16020,12 +16014,6 @@ parameters: count: 2 path: src/Sql.php - - - message: '#^Parameter \#2 \$table of method PhpMyAdmin\\Sql\:\:handleSortOrder\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/Sql.php - - message: '#^Parameter \#3 \$column of method PhpMyAdmin\\Sql\:\:cleanupRelations\(\) expects string, mixed given\.$#' identifier: argument.type diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4ddc6ca68b..523de786be 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2378,7 +2378,7 @@ - + getQueryParam('sql_signature')]]> @@ -9378,7 +9378,6 @@ parser->list]]> parser->list]]> parser->list]]> - @@ -9391,8 +9390,6 @@ isUnique()]]> - - diff --git a/src/Controllers/Import/ImportController.php b/src/Controllers/Import/ImportController.php index aa196c117d..6af3738581 100644 --- a/src/Controllers/Import/ImportController.php +++ b/src/Controllers/Import/ImportController.php @@ -649,8 +649,8 @@ final class ImportController implements InvocableController false, // is_gotofile Current::$database, // db Current::$table, // table - null, // sql_query_for_bookmark - see below - null, // message_to_show + '', // sql_query_for_bookmark - see below + '', // message_to_show null, // sql_data UrlParams::$goto, // goto null, // disp_query diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index d2a576102b..9ba9d0dd30 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -191,8 +191,8 @@ class SqlController implements InvocableController $isGotofile, Current::$database, Current::$table, - $GLOBALS['import_text'] ?? null, - $GLOBALS['message_to_show'] ?? null, + $GLOBALS['import_text'] ?? '', + $GLOBALS['message_to_show'] ?? '', null, UrlParams::$goto, isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null, diff --git a/src/Controllers/Table/DeleteRowsController.php b/src/Controllers/Table/DeleteRowsController.php index 2c19c118ec..f01cdb24a8 100644 --- a/src/Controllers/Table/DeleteRowsController.php +++ b/src/Controllers/Table/DeleteRowsController.php @@ -87,8 +87,8 @@ final class DeleteRowsController implements InvocableController false, Current::$database, Current::$table, - null, - null, + '', + '', null, UrlParams::$goto, $GLOBALS['disp_query'] ?? null, diff --git a/src/Controllers/Table/SearchController.php b/src/Controllers/Table/SearchController.php index 29363913ef..ba7004709f 100644 --- a/src/Controllers/Table/SearchController.php +++ b/src/Controllers/Table/SearchController.php @@ -250,8 +250,8 @@ final class SearchController implements InvocableController false, // is_gotofile Current::$database, // db Current::$table, // table - null, // sql_query_for_bookmark - null, // message_to_show + '', // sql_query_for_bookmark + '', // message_to_show null, // sql_data UrlParams::$goto, // goto null, // disp_query diff --git a/src/Controllers/Table/Structure/BrowseController.php b/src/Controllers/Table/Structure/BrowseController.php index e117b8a63d..3ee7354bb4 100644 --- a/src/Controllers/Table/Structure/BrowseController.php +++ b/src/Controllers/Table/Structure/BrowseController.php @@ -66,8 +66,8 @@ final class BrowseController implements InvocableController false, // is_gotofile Current::$database, // db Current::$table, // table - null, // sql_query_for_bookmark - null, // message_to_show + '', // sql_query_for_bookmark + '', // message_to_show null, // sql_data $goto, // goto null, // disp_query diff --git a/src/Database/MultiTableQuery.php b/src/Database/MultiTableQuery.php index 727c5f88f1..0041594cf8 100644 --- a/src/Database/MultiTableQuery.php +++ b/src/Database/MultiTableQuery.php @@ -90,9 +90,9 @@ class MultiTableQuery null, false, // is_gotofile $db, // db - null, // table - null, // sql_query_for_bookmark - see below - null, // message_to_show + '', // table + '', // sql_query_for_bookmark - see below + '', // message_to_show null, // sql_data $goto, // goto null, // disp_query diff --git a/src/Sql.php b/src/Sql.php index d468f1fe62..489f4713f5 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -703,11 +703,11 @@ class Sql /** * Function to handle all aspects relating to executing the query * - * @param string $fullSqlQuery full sql query - * @param bool $isGotoFile whether to go to a file - * @param string $db current database - * @param string|null $table current table - * @param string|null $sqlQueryForBookmark sql query to be stored as bookmark + * @param string $fullSqlQuery full sql query + * @param bool $isGotoFile whether to go to a file + * @param string $db current database + * @param string $table current table + * @param string $sqlQueryForBookmark sql query to be stored as bookmark * * @psalm-return array{ * ResultInterface|false, @@ -722,11 +722,11 @@ class Sql string $fullSqlQuery, bool $isGotoFile, string $db, - string|null $table, - string|null $sqlQueryForBookmark, + string $table, + string $sqlQueryForBookmark, ): array { $response = ResponseRenderer::getInstance(); - $response->getHeader()->getMenu()->setTable($table ?? ''); + $response->getHeader()->getMenu()->setTable($table); Profiling::enable($this->dbi); @@ -774,9 +774,9 @@ class Sql $justBrowsing = self::isJustBrowsing($statementInfo); - $unlimNumRows = $this->countQueryResults($numRows, $justBrowsing, $db, $table ?? '', $statementInfo); + $unlimNumRows = $this->countQueryResults($numRows, $justBrowsing, $db, $table, $statementInfo); - $this->cleanupRelations($db, $table ?? '', $_POST['dropped_column'] ?? '', ! empty($_POST['purge'])); + $this->cleanupRelations($db, $table, $_POST['dropped_column'] ?? '', ! empty($_POST['purge'])); return [$result, $numRows, $unlimNumRows, $profilingResults, $errorMessage]; } @@ -810,11 +810,11 @@ class Sql /** * Function to get the message for the no rows returned case * - * @param string|null $messageToShow message to show - * @param int|string $numRows number of rows + * @param string $messageToShow message to show + * @param int|string $numRows number of rows */ private function getMessageForNoRowsReturned( - string|null $messageToShow, + string $messageToShow, StatementInfo $statementInfo, int|string $numRows, ): Message { @@ -851,7 +851,7 @@ class Sql // fact that $message_to_show is sent for every case. // The $message_to_show containing a success message and sent with // the form should not have priority over errors - } elseif ($messageToShow && $statementInfo->flags->queryType !== StatementType::Select) { + } elseif ($messageToShow !== '' && $statementInfo->flags->queryType !== StatementType::Select) { $message = Message::rawSuccess(htmlspecialchars($messageToShow)); } elseif (! empty($GLOBALS['show_as_php'])) { $message = Message::success(__('Showing as PHP code')); @@ -893,7 +893,7 @@ class Sql * * @param string $db current database * @param string|null $table current table - * @param string|null $messageToShow message to show + * @param string $messageToShow message to show * @param int|string $numRows number of rows * @param DisplayResults $displayResultsObject DisplayResult instance * @param string $errorMessage error message from tryQuery @@ -909,7 +909,7 @@ class Sql StatementInfo $statementInfo, string $db, string|null $table, - string|null $messageToShow, + string $messageToShow, int|string $numRows, DisplayResults $displayResultsObject, string $errorMessage, @@ -1432,9 +1432,9 @@ class Sql * * @param bool $isGotoFile whether goto file or not * @param string $db current database - * @param string|null $table current table - * @param string|null $sqlQueryForBookmark the sql query to be stored as bookmark - * @param string|null $messageToShow message to show + * @param string $table current table + * @param string $sqlQueryForBookmark the sql query to be stored as bookmark + * @param string $messageToShow message to show * @param mixed[]|null $sqlData sql data * @param string $goto goto page url * @param string|null $dispQuery display query @@ -1446,9 +1446,9 @@ class Sql StatementInfo|null $statementInfo, bool $isGotoFile, string $db, - string|null $table, - string|null $sqlQueryForBookmark, - string|null $messageToShow, + string $table, + string $sqlQueryForBookmark, + string $messageToShow, array|null $sqlData, string $goto, string|null $dispQuery, @@ -1484,9 +1484,9 @@ class Sql * * @param bool $isGotoFile whether goto file or not * @param string $db current database - * @param string|null $table current table - * @param string|null $sqlQueryForBookmark the sql query to be stored as bookmark - * @param string|null $messageToShow message to show + * @param string $table current table + * @param string $sqlQueryForBookmark the sql query to be stored as bookmark + * @param string $messageToShow message to show * @param mixed[]|null $sqlData sql data * @param string $goto goto page url * @param string|null $dispQuery display query @@ -1500,9 +1500,9 @@ class Sql StatementInfo $statementInfo, bool $isGotoFile, string $db, - string|null $table, - string|null $sqlQueryForBookmark, - string|null $messageToShow, + string $table, + string $sqlQueryForBookmark, + string $messageToShow, array|null $sqlData, string $goto, string|null $dispQuery, @@ -1554,7 +1554,7 @@ class Sql // The following was copied from getQueryResponseForNoResultsReturned() // Delete if it's not needed in this context if ($this->isDeleteTransformationInfo($statementInfo)) { - $this->deleteTransformationInfo($db, $table ?? '', $statementInfo); + $this->deleteTransformationInfo($db, $table, $statementInfo); } $message = $this->getMessageForNoRowsReturned($messageToShow, $statementInfo, 0); diff --git a/tests/unit/SqlTest.php b/tests/unit/SqlTest.php index fd61c96f7e..9ece07dd53 100644 --- a/tests/unit/SqlTest.php +++ b/tests/unit/SqlTest.php @@ -607,8 +607,8 @@ class SqlTest extends AbstractTestCase false, 'sakila', 'different_table', - null, - null, + '', + '', null, 'index.php?route=/sql', null, From df463502b367e58a7adebe5b617d99b01f799b69 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 22:25:24 +0000 Subject: [PATCH 5/8] Remove dead param $sqlData Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 30 +++++++++---------- src/Controllers/Import/ImportController.php | 1 - src/Controllers/Sql/SqlController.php | 1 - .../Table/DeleteRowsController.php | 1 - src/Controllers/Table/SearchController.php | 1 - .../Table/Structure/BrowseController.php | 1 - src/Database/MultiTableQuery.php | 1 - src/Sql.php | 13 +------- tests/unit/SqlTest.php | 1 - 9 files changed, 16 insertions(+), 34 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8e8c94412e..cb33624c5f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3898,13 +3898,7 @@ parameters: path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#10 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Sql/SqlController.php - - - - message: '#^Parameter \#12 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#11 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php @@ -3928,7 +3922,13 @@ parameters: path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#9 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#8 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Controllers/Sql/SqlController.php + + - + message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php @@ -4185,12 +4185,6 @@ parameters: count: 1 path: src/Controllers/Table/DeleteRowsController.php - - - message: '#^Parameter \#10 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/DeleteRowsController.php - - message: '#^Parameter \#3 \$pos of method PhpMyAdmin\\Sql\:\:calculatePosForLastPage\(\) expects int\|null, mixed given\.$#' identifier: argument.type @@ -4204,7 +4198,13 @@ parameters: path: src/Controllers/Table/DeleteRowsController.php - - message: '#^Parameter \#9 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#8 \$dispQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Controllers/Table/DeleteRowsController.php + + - + message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Table/DeleteRowsController.php diff --git a/src/Controllers/Import/ImportController.php b/src/Controllers/Import/ImportController.php index 6af3738581..0d6df99032 100644 --- a/src/Controllers/Import/ImportController.php +++ b/src/Controllers/Import/ImportController.php @@ -651,7 +651,6 @@ final class ImportController implements InvocableController Current::$table, // table '', // sql_query_for_bookmark - see below '', // message_to_show - null, // sql_data UrlParams::$goto, // goto null, // disp_query null, // disp_message diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index 9ba9d0dd30..aa4c979bda 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -193,7 +193,6 @@ class SqlController implements InvocableController Current::$table, $GLOBALS['import_text'] ?? '', $GLOBALS['message_to_show'] ?? '', - null, UrlParams::$goto, isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null, $GLOBALS['disp_message'] ?? null, diff --git a/src/Controllers/Table/DeleteRowsController.php b/src/Controllers/Table/DeleteRowsController.php index f01cdb24a8..482ba6d44f 100644 --- a/src/Controllers/Table/DeleteRowsController.php +++ b/src/Controllers/Table/DeleteRowsController.php @@ -89,7 +89,6 @@ final class DeleteRowsController implements InvocableController Current::$table, '', '', - null, UrlParams::$goto, $GLOBALS['disp_query'] ?? null, $GLOBALS['disp_message'] ?? null, diff --git a/src/Controllers/Table/SearchController.php b/src/Controllers/Table/SearchController.php index ba7004709f..2597d1e6b7 100644 --- a/src/Controllers/Table/SearchController.php +++ b/src/Controllers/Table/SearchController.php @@ -252,7 +252,6 @@ final class SearchController implements InvocableController Current::$table, // table '', // sql_query_for_bookmark '', // message_to_show - null, // sql_data UrlParams::$goto, // goto null, // disp_query null, // disp_message diff --git a/src/Controllers/Table/Structure/BrowseController.php b/src/Controllers/Table/Structure/BrowseController.php index 3ee7354bb4..1f939a5af4 100644 --- a/src/Controllers/Table/Structure/BrowseController.php +++ b/src/Controllers/Table/Structure/BrowseController.php @@ -68,7 +68,6 @@ final class BrowseController implements InvocableController Current::$table, // table '', // sql_query_for_bookmark '', // message_to_show - null, // sql_data $goto, // goto null, // disp_query null, // disp_message diff --git a/src/Database/MultiTableQuery.php b/src/Database/MultiTableQuery.php index 0041594cf8..6d2e4cf565 100644 --- a/src/Database/MultiTableQuery.php +++ b/src/Database/MultiTableQuery.php @@ -93,7 +93,6 @@ class MultiTableQuery '', // table '', // sql_query_for_bookmark - see below '', // message_to_show - null, // sql_data $goto, // goto null, // disp_query null, // disp_message diff --git a/src/Sql.php b/src/Sql.php index 489f4713f5..534b0ed1c9 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -1177,16 +1177,14 @@ class Sql * * @param string|null $displayQuery display query * @param bool $showSql whether to show sql - * @param mixed[] $sqlData sql data * @param Message|string $displayMessage display message */ private function getHtmlForPreviousUpdateQuery( string|null $displayQuery, bool $showSql, - array $sqlData, Message|string $displayMessage, ): string { - if ($displayQuery !== null && $showSql && $sqlData === []) { + if ($displayQuery !== null && $showSql) { return Generator::getMessage($displayMessage, $displayQuery, MessageType::Success); } @@ -1251,7 +1249,6 @@ class Sql * @param ResultInterface $result executed query results * @param string $db current database * @param string|null $table current table - * @param mixed[]|null $sqlData sql data * @param DisplayResults $displayResultsObject Instance of DisplayResults * @param int|string $unlimNumRows unlimited number of rows * @param int|string $numRows number of rows @@ -1270,7 +1267,6 @@ class Sql StatementInfo $statementInfo, string $db, string|null $table, - array|null $sqlData, DisplayResults $displayResultsObject, int|string $unlimNumRows, int|string $numRows, @@ -1376,7 +1372,6 @@ class Sql $previousUpdateQueryHtml = $this->getHtmlForPreviousUpdateQuery( $dispQuery, $this->config->settings['ShowSQL'], - $sqlData ?? [], $dispMessage ?? '', ); @@ -1435,7 +1430,6 @@ class Sql * @param string $table current table * @param string $sqlQueryForBookmark the sql query to be stored as bookmark * @param string $messageToShow message to show - * @param mixed[]|null $sqlData sql data * @param string $goto goto page url * @param string|null $dispQuery display query * @param Message|string|null $dispMessage display message @@ -1449,7 +1443,6 @@ class Sql string $table, string $sqlQueryForBookmark, string $messageToShow, - array|null $sqlData, string $goto, string|null $dispQuery, Message|string|null $dispMessage, @@ -1470,7 +1463,6 @@ class Sql $table, // table $sqlQueryForBookmark, // sql_query_for_bookmark $messageToShow, // message_to_show - $sqlData, // sql_data $goto, // goto $dispQuery, // disp_query $dispMessage, // disp_message @@ -1487,7 +1479,6 @@ class Sql * @param string $table current table * @param string $sqlQueryForBookmark the sql query to be stored as bookmark * @param string $messageToShow message to show - * @param mixed[]|null $sqlData sql data * @param string $goto goto page url * @param string|null $dispQuery display query * @param Message|string|null $dispMessage display message @@ -1503,7 +1494,6 @@ class Sql string $table, string $sqlQueryForBookmark, string $messageToShow, - array|null $sqlData, string $goto, string|null $dispQuery, Message|string|null $dispMessage, @@ -1598,7 +1588,6 @@ class Sql $statementInfo, $db, $table, - $sqlData, $displayResultsObject, $unlimNumRows, $numRows, diff --git a/tests/unit/SqlTest.php b/tests/unit/SqlTest.php index 9ece07dd53..ef25e13e24 100644 --- a/tests/unit/SqlTest.php +++ b/tests/unit/SqlTest.php @@ -609,7 +609,6 @@ class SqlTest extends AbstractTestCase 'different_table', '', '', - null, 'index.php?route=/sql', null, null, From 30868c4e607de25b355e3d0f4434f58591a8407f Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 22:30:33 +0000 Subject: [PATCH 6/8] Remove nullability in Sql Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 6 +- psalm-baseline.xml | 4 +- src/Controllers/Import/ImportController.php | 4 +- src/Controllers/Sql/SqlController.php | 4 +- .../Table/DeleteRowsController.php | 4 +- src/Controllers/Table/SearchController.php | 4 +- .../Table/Structure/BrowseController.php | 4 +- src/Database/MultiTableQuery.php | 4 +- src/Sql.php | 82 +++++++++---------- tests/unit/SqlTest.php | 4 +- 10 files changed, 60 insertions(+), 60 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cb33624c5f..56dd30851e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3898,7 +3898,7 @@ parameters: path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#11 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#11 \$completeQuery of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php @@ -3928,7 +3928,7 @@ parameters: path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' + message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Sql/SqlController.php @@ -4204,7 +4204,7 @@ parameters: path: src/Controllers/Table/DeleteRowsController.php - - message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string\|null, mixed given\.$#' + message: '#^Parameter \#9 \$dispMessage of method PhpMyAdmin\\Sql\:\:executeQueryAndSendQueryResponse\(\) expects PhpMyAdmin\\Message\|string, mixed given\.$#' identifier: argument.type count: 1 path: src/Controllers/Table/DeleteRowsController.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 523de786be..0b5522fbef 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2377,7 +2377,7 @@ - + getQueryParam('sql_signature')]]> @@ -2572,7 +2572,7 @@ - + diff --git a/src/Controllers/Import/ImportController.php b/src/Controllers/Import/ImportController.php index 0d6df99032..6a38fe9441 100644 --- a/src/Controllers/Import/ImportController.php +++ b/src/Controllers/Import/ImportController.php @@ -653,9 +653,9 @@ final class ImportController implements InvocableController '', // message_to_show UrlParams::$goto, // goto null, // disp_query - null, // disp_message + '', // disp_message Current::$sqlQuery, - null, // complete_query + Current::$sqlQuery, // complete_query ); } diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index aa4c979bda..3806b6bcb6 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -195,9 +195,9 @@ class SqlController implements InvocableController $GLOBALS['message_to_show'] ?? '', UrlParams::$goto, isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null, - $GLOBALS['disp_message'] ?? null, + $GLOBALS['disp_message'] ?? '', Current::$sqlQuery, - $GLOBALS['complete_query'] ?? null, + $GLOBALS['complete_query'] ?? Current::$sqlQuery, )); return $this->response->response(); diff --git a/src/Controllers/Table/DeleteRowsController.php b/src/Controllers/Table/DeleteRowsController.php index 482ba6d44f..fb9fd9c064 100644 --- a/src/Controllers/Table/DeleteRowsController.php +++ b/src/Controllers/Table/DeleteRowsController.php @@ -91,9 +91,9 @@ final class DeleteRowsController implements InvocableController '', UrlParams::$goto, $GLOBALS['disp_query'] ?? null, - $GLOBALS['disp_message'] ?? null, + $GLOBALS['disp_message'] ?? '', + Current::$sqlQuery, Current::$sqlQuery, - null, )); return $this->response->response(); diff --git a/src/Controllers/Table/SearchController.php b/src/Controllers/Table/SearchController.php index 2597d1e6b7..0e29162129 100644 --- a/src/Controllers/Table/SearchController.php +++ b/src/Controllers/Table/SearchController.php @@ -254,9 +254,9 @@ final class SearchController implements InvocableController '', // message_to_show UrlParams::$goto, // goto null, // disp_query - null, // disp_message + '', // disp_message $sqlQuery, // sql_query - null, // complete_query + $sqlQuery, // complete_query )); } diff --git a/src/Controllers/Table/Structure/BrowseController.php b/src/Controllers/Table/Structure/BrowseController.php index 1f939a5af4..252fe37133 100644 --- a/src/Controllers/Table/Structure/BrowseController.php +++ b/src/Controllers/Table/Structure/BrowseController.php @@ -70,9 +70,9 @@ final class BrowseController implements InvocableController '', // message_to_show $goto, // goto null, // disp_query - null, // disp_message + '', // disp_message $sqlQuery, // sql_query - null, // complete_query + $sqlQuery, // complete_query ), ); } diff --git a/src/Database/MultiTableQuery.php b/src/Database/MultiTableQuery.php index 6d2e4cf565..92c622fd72 100644 --- a/src/Database/MultiTableQuery.php +++ b/src/Database/MultiTableQuery.php @@ -95,9 +95,9 @@ class MultiTableQuery '', // message_to_show $goto, // goto null, // disp_query - null, // disp_message + '', // disp_message $sqlQuery, // sql_query - null, // complete_query + $sqlQuery, // complete_query ); } } diff --git a/src/Sql.php b/src/Sql.php index 534b0ed1c9..ea98275055 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -899,7 +899,7 @@ class Sql * @param string $errorMessage error message from tryQuery * @param ResultInterface|false $result executed query results * @param string $sqlQuery sql query - * @param string|null $completeQuery complete sql query + * @param string $completeQuery complete sql query * @psalm-param int|numeric-string $numRows * @psalm-param list $profilingResults * @@ -916,7 +916,7 @@ class Sql array $profilingResults, ResultInterface|false $result, string $sqlQuery, - string|null $completeQuery, + string $completeQuery, ): string { if ($this->isDeleteTransformationInfo($statementInfo)) { $this->deleteTransformationInfo($db, $table ?? '', $statementInfo); @@ -1006,7 +1006,7 @@ class Sql 'id_bookmark' => 1, ]), 'user' => $this->config->selectedServer['user'], - 'sql_query' => $completeQuery ?? $sqlQuery, + 'sql_query' => $completeQuery, 'allow_shared_bookmarks' => $this->config->settings['AllowSharedBookmarks'], ]); } @@ -1246,16 +1246,16 @@ class Sql /** * Function to display results when the executed query returns non empty results * - * @param ResultInterface $result executed query results - * @param string $db current database - * @param string|null $table current table - * @param DisplayResults $displayResultsObject Instance of DisplayResults - * @param int|string $unlimNumRows unlimited number of rows - * @param int|string $numRows number of rows - * @param string|null $dispQuery display query - * @param Message|string|null $dispMessage display message - * @param string $sqlQuery sql query - * @param string|null $completeQuery complete sql query + * @param ResultInterface $result executed query results + * @param string $db current database + * @param string|null $table current table + * @param DisplayResults $displayResultsObject Instance of DisplayResults + * @param int|string $unlimNumRows unlimited number of rows + * @param int|string $numRows number of rows + * @param string|null $dispQuery display query + * @param Message|string $dispMessage display message + * @param string $sqlQuery sql query + * @param string $completeQuery complete sql query * @psalm-param int|numeric-string $unlimNumRows * @psalm-param int|numeric-string $numRows * @psalm-param list $profilingResults @@ -1271,10 +1271,10 @@ class Sql int|string $unlimNumRows, int|string $numRows, string|null $dispQuery, - Message|string|null $dispMessage, + Message|string $dispMessage, array $profilingResults, string $sqlQuery, - string|null $completeQuery, + string $completeQuery, ): string { // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here @@ -1372,7 +1372,7 @@ class Sql $previousUpdateQueryHtml = $this->getHtmlForPreviousUpdateQuery( $dispQuery, $this->config->settings['ShowSQL'], - $dispMessage ?? '', + $dispMessage, ); $profilingChartHtml = $this->getProfilingChart($profilingResults); @@ -1408,7 +1408,7 @@ class Sql 'id_bookmark' => 1, ]), 'user' => $this->config->selectedServer['user'], - 'sql_query' => $completeQuery ?? $sqlQuery, + 'sql_query' => $completeQuery, ]); } @@ -1425,16 +1425,16 @@ class Sql /** * Function to execute the query and send the response * - * @param bool $isGotoFile whether goto file or not - * @param string $db current database - * @param string $table current table - * @param string $sqlQueryForBookmark the sql query to be stored as bookmark - * @param string $messageToShow message to show - * @param string $goto goto page url - * @param string|null $dispQuery display query - * @param Message|string|null $dispMessage display message - * @param string $sqlQuery sql query - * @param string|null $completeQuery complete query + * @param bool $isGotoFile whether goto file or not + * @param string $db current database + * @param string $table current table + * @param string $sqlQueryForBookmark the sql query to be stored as bookmark + * @param string $messageToShow message to show + * @param string $goto goto page url + * @param string|null $dispQuery display query + * @param Message|string $dispMessage display message + * @param string $sqlQuery sql query + * @param string $completeQuery complete query */ public function executeQueryAndSendQueryResponse( StatementInfo|null $statementInfo, @@ -1445,9 +1445,9 @@ class Sql string $messageToShow, string $goto, string|null $dispQuery, - Message|string|null $dispMessage, + Message|string $dispMessage, string $sqlQuery, - string|null $completeQuery, + string $completeQuery, ): string { if ($statementInfo === null) { // Parse and analyze the query @@ -1474,16 +1474,16 @@ class Sql /** * Function to execute the query and send the response * - * @param bool $isGotoFile whether goto file or not - * @param string $db current database - * @param string $table current table - * @param string $sqlQueryForBookmark the sql query to be stored as bookmark - * @param string $messageToShow message to show - * @param string $goto goto page url - * @param string|null $dispQuery display query - * @param Message|string|null $dispMessage display message - * @param string $sqlQuery sql query - * @param string|null $completeQuery complete query + * @param bool $isGotoFile whether goto file or not + * @param string $db current database + * @param string $table current table + * @param string $sqlQueryForBookmark the sql query to be stored as bookmark + * @param string $messageToShow message to show + * @param string $goto goto page url + * @param string|null $dispQuery display query + * @param Message|string $dispMessage display message + * @param string $sqlQuery sql query + * @param string $completeQuery complete query * * @return string html */ @@ -1496,9 +1496,9 @@ class Sql string $messageToShow, string $goto, string|null $dispQuery, - Message|string|null $dispMessage, + Message|string $dispMessage, string $sqlQuery, - string|null $completeQuery, + string $completeQuery, ): string { // Handle remembered sorting order, only for single table query. // Handling is not required when it's a union query diff --git a/tests/unit/SqlTest.php b/tests/unit/SqlTest.php index ef25e13e24..9a80c899f5 100644 --- a/tests/unit/SqlTest.php +++ b/tests/unit/SqlTest.php @@ -611,9 +611,9 @@ class SqlTest extends AbstractTestCase '', 'index.php?route=/sql', null, - null, + '', + 'SELECT * FROM `sakila`.`country` LIMIT 0, 3;', 'SELECT * FROM `sakila`.`country` LIMIT 0, 3;', - null, ); self::assertStringContainsString('Showing rows 0 - 2 (3 total', $actual); self::assertStringContainsString('SELECT * FROM `sakila`.`country` LIMIT 0, 3;', $actual); From f0f84295cca78522e70046a09d006fc1b9f809d4 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 22:58:19 +0000 Subject: [PATCH 7/8] Undo change to $table Signed-off-by: Kamil Tekiela --- src/Database/MultiTableQuery.php | 2 +- src/Sql.php | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Database/MultiTableQuery.php b/src/Database/MultiTableQuery.php index 92c622fd72..88a2e53024 100644 --- a/src/Database/MultiTableQuery.php +++ b/src/Database/MultiTableQuery.php @@ -90,7 +90,7 @@ class MultiTableQuery null, false, // is_gotofile $db, // db - '', // table + null, // table '', // sql_query_for_bookmark - see below '', // message_to_show $goto, // goto diff --git a/src/Sql.php b/src/Sql.php index ea98275055..aa66409881 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -1194,21 +1194,15 @@ class Sql /** * To get the message if a column index is missing. If not will return null * - * @param string|null $table current table - * @param string $database current database - * @param bool $editable whether the results table can be editable or not - * @param bool $hasUniqueKey whether there is a unique key + * @param string $database current database + * @param bool $editable whether the results table can be editable or not + * @param bool $hasUniqueKey whether there is a unique key */ private function getMessageIfMissingColumnIndex( - string|null $table, string $database, bool $editable, bool $hasUniqueKey, ): string { - if ($table === null) { - return ''; - } - $output = ''; if (Utilities::isSystemSchema($database) || ! $editable) { $output = Message::notice( @@ -1377,7 +1371,9 @@ class Sql $profilingChartHtml = $this->getProfilingChart($profilingResults); - $missingUniqueColumnMessage = $this->getMessageIfMissingColumnIndex($table, $db, $editable, $hasUnique); + $missingUniqueColumnMessage = $table !== null + ? $this->getMessageIfMissingColumnIndex($db, $editable, $hasUnique) + : ''; $bookmarkCreatedMessage = $this->getBookmarkCreatedMessage(); @@ -1427,7 +1423,7 @@ class Sql * * @param bool $isGotoFile whether goto file or not * @param string $db current database - * @param string $table current table + * @param string|null $table current table * @param string $sqlQueryForBookmark the sql query to be stored as bookmark * @param string $messageToShow message to show * @param string $goto goto page url @@ -1440,7 +1436,7 @@ class Sql StatementInfo|null $statementInfo, bool $isGotoFile, string $db, - string $table, + string|null $table, string $sqlQueryForBookmark, string $messageToShow, string $goto, @@ -1476,7 +1472,7 @@ class Sql * * @param bool $isGotoFile whether goto file or not * @param string $db current database - * @param string $table current table + * @param string|null $table current table * @param string $sqlQueryForBookmark the sql query to be stored as bookmark * @param string $messageToShow message to show * @param string $goto goto page url @@ -1491,7 +1487,7 @@ class Sql StatementInfo $statementInfo, bool $isGotoFile, string $db, - string $table, + string|null $table, string $sqlQueryForBookmark, string $messageToShow, string $goto, @@ -1511,7 +1507,7 @@ class Sql && ! isset($_POST['sort_by_key']) ) { if (! isset($_SESSION['sql_from_query_box'])) { - $statementInfo = $this->handleSortOrder($db, $table, $statementInfo, $sqlQuery); + $statementInfo = $this->handleSortOrder($db, $table ?? '', $statementInfo, $sqlQuery); } else { unset($_SESSION['sql_from_query_box']); } @@ -1544,7 +1540,7 @@ class Sql // The following was copied from getQueryResponseForNoResultsReturned() // Delete if it's not needed in this context if ($this->isDeleteTransformationInfo($statementInfo)) { - $this->deleteTransformationInfo($db, $table, $statementInfo); + $this->deleteTransformationInfo($db, $table ?? '', $statementInfo); } $message = $this->getMessageForNoRowsReturned($messageToShow, $statementInfo, 0); @@ -1560,7 +1556,7 @@ class Sql $fullSqlQuery, $isGotoFile, $db, - $table, + $table ?? '', $sqlQueryForBookmark, ); From 4e9866f7970f434a4a0ac3ca6c872949a8a24adb Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 29 Dec 2024 23:03:21 +0000 Subject: [PATCH 8/8] Remove unnecessary nullability Signed-off-by: Kamil Tekiela --- src/Config/Form.php | 6 +++--- src/Config/FormDisplay.php | 2 +- src/ConfigStorage/Relation.php | 8 ++++---- .../Database/CentralColumnsController.php | 12 ++++++------ tests/unit/Config/FormTest.php | 3 ++- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Config/Form.php b/src/Config/Form.php index f306d4fd27..f22fd3db29 100644 --- a/src/Config/Form.php +++ b/src/Config/Form.php @@ -84,9 +84,9 @@ class Form * * @param string $optionName path or field name * - * @return string|null one of: boolean, integer, double, string, select, array + * @return string one of: boolean, integer, double, string, select, array */ - public function getOptionType(string $optionName): string|null + public function getOptionType(string $optionName): string { $key = ltrim( mb_substr( @@ -96,7 +96,7 @@ class Form '/', ); - return $this->fieldsTypes[$key] ?? null; + return $this->fieldsTypes[$key] ?? ''; } /** diff --git a/src/Config/FormDisplay.php b/src/Config/FormDisplay.php index feafec89ff..326a695857 100644 --- a/src/Config/FormDisplay.php +++ b/src/Config/FormDisplay.php @@ -566,7 +566,7 @@ class FormDisplay foreach ($form->fields as $field => $systemPath) { $workPath = array_search($systemPath, $this->systemPaths); $key = $this->translatedPaths[$workPath]; - $type = (string) $form->getOptionType($field); + $type = $form->getOptionType($field); // skip groups if ($type === 'group') { diff --git a/src/ConfigStorage/Relation.php b/src/ConfigStorage/Relation.php index 1b4898e535..c7200ac646 100644 --- a/src/ConfigStorage/Relation.php +++ b/src/ConfigStorage/Relation.php @@ -1235,10 +1235,10 @@ class Relation /** * Create a PDF page * - * @param string|null $newpage name of the new PDF page - * @param string $db database name + * @param string $newpage name of the new PDF page + * @param string $db database name */ - public function createPage(string|null $newpage, PdfFeature $pdfFeature, string $db): int + public function createPage(string $newpage, PdfFeature $pdfFeature, string $db): int { $insQuery = 'INSERT INTO ' . Util::backquote($pdfFeature->database) . '.' @@ -1247,7 +1247,7 @@ class Relation . ' VALUES (' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ', ' . $this->dbi->quoteString( - $newpage !== null && $newpage !== '' ? $newpage : __('no description'), + $newpage !== '' ? $newpage : __('no description'), ConnectionType::ControlUser, ) . ')'; $this->dbi->tryQueryAsControlUser($insQuery); diff --git a/src/Controllers/Database/CentralColumnsController.php b/src/Controllers/Database/CentralColumnsController.php index a0b5325238..98d59a9146 100644 --- a/src/Controllers/Database/CentralColumnsController.php +++ b/src/Controllers/Database/CentralColumnsController.php @@ -42,7 +42,7 @@ final class CentralColumnsController implements InvocableController $request->getParsedBodyParamAsString('orig_col_name'), $request->getParsedBodyParamAsString('col_default'), $request->getParsedBodyParamAsString('col_default_sel'), - $request->getParsedBodyParamAsStringOrNull('col_extra'), + $request->getParsedBodyParamAsString('col_extra', ''), $request->getParsedBodyParamAsStringOrNull('col_isNull'), $request->getParsedBodyParamAsString('col_length'), $request->getParsedBodyParamAsString('col_attribute'), @@ -60,7 +60,7 @@ final class CentralColumnsController implements InvocableController $request->getParsedBodyParamAsString('col_name'), $request->getParsedBodyParamAsString('col_default'), $request->getParsedBodyParamAsString('col_default_sel'), - $request->getParsedBodyParamAsStringOrNull('col_extra'), + $request->getParsedBodyParamAsString('col_extra', ''), $request->getParsedBodyParamAsStringOrNull('col_isNull'), $request->getParsedBodyParamAsString('col_length'), $request->getParsedBodyParamAsString('col_attribute'), @@ -176,7 +176,7 @@ final class CentralColumnsController implements InvocableController string $origColName, string $colDefault, string $colDefaultSel, - string|null $colExtra, + string $colExtra, string|null $colIsNull, string $colLength, string $colAttribute, @@ -198,7 +198,7 @@ final class CentralColumnsController implements InvocableController $colLength, $colIsNull !== null, $collation, - $colExtra ?? '', + $colExtra, $columnDefault, ); } @@ -207,7 +207,7 @@ final class CentralColumnsController implements InvocableController string $colName, string $colDefault, string $colDefaultSel, - string|null $colExtra, + string $colExtra, string|null $colIsNull, string $colLength, string $colAttribute, @@ -224,7 +224,7 @@ final class CentralColumnsController implements InvocableController $colLength, $colIsNull !== null, $collation, - $colExtra ?? '', + $colExtra, $colDefault === 'NONE' && $colDefaultSel !== 'USER_DEFINED' ? '' : $colDefault, ); } diff --git a/tests/unit/Config/FormTest.php b/tests/unit/Config/FormTest.php index 593ea98bbc..586d9a24e4 100644 --- a/tests/unit/Config/FormTest.php +++ b/tests/unit/Config/FormTest.php @@ -68,7 +68,8 @@ class FormTest extends AbstractTestCase ['7' => 'Seven'], ); - self::assertNull( + self::assertSame( + '', $this->object->getOptionType('123/4/5/6'), );