diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4cd114270c..2d4a321fb2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2901,7 +2901,7 @@ parameters: - message: '#^Cannot access offset ''reload'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 5 + count: 4 path: src/Controllers/Import/ImportController.php - @@ -2925,7 +2925,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 7 + count: 4 path: src/Controllers/Import/ImportController.php - @@ -2970,12 +2970,6 @@ parameters: count: 1 path: src/Controllers/Import/ImportController.php - - - message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Import/ImportController.php - - message: '#^Parameter \#4 \$backUrl of static method PhpMyAdmin\\Html\\Generator\:\:mysqlDie\(\) expects string, mixed given\.$#' identifier: argument.type @@ -3795,12 +3789,6 @@ parameters: count: 1 path: src/Controllers/Sql/SqlController.php - - - 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, mixed given\.$#' identifier: argument.type @@ -9219,12 +9207,6 @@ parameters: count: 2 path: src/Import/Import.php - - - message: '#^Method PhpMyAdmin\\Import\\Import\:\:getNextChunk\(\) should return bool\|string but returns mixed\.$#' - identifier: return.type - count: 1 - path: src/Import/Import.php - - message: '#^Only booleans are allowed in &&, PhpMyAdmin\\Dbal\\ResultInterface\|false given on the left side\.$#' identifier: booleanAnd.leftNotBoolean @@ -9255,18 +9237,6 @@ parameters: count: 1 path: src/Import/Import.php - - - message: '#^Parameter \#1 \$string of function mb_strlen expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Import/Import.php - - - - message: '#^Parameter \#1 \$string of function mb_substr expects string, mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Import/Import.php - - message: '#^Property PhpMyAdmin\\Import\\ImportTable\:\:\$rows \(list\\>\) does not accept array\, list\\>\.$#' identifier: assign.propertyType diff --git a/psalm.xml b/psalm.xml index c3b3fb2f62..0f2672e35b 100644 --- a/psalm.xml +++ b/psalm.xml @@ -49,7 +49,6 @@ errno: int, file_handle: resource|null, from_cookie: bool, - import_text: string, knjenc: string, maxsize: string, memory_limit: int, diff --git a/src/Controllers/Import/ImportController.php b/src/Controllers/Import/ImportController.php index 080a336672..e7df6287c8 100644 --- a/src/Controllers/Import/ImportController.php +++ b/src/Controllers/Import/ImportController.php @@ -63,7 +63,6 @@ final class ImportController implements InvocableController { $GLOBALS['display_query'] ??= null; $GLOBALS['ajax_reload'] ??= null; - $GLOBALS['import_text'] ??= null; $GLOBALS['result'] ??= null; ImportSettings::$charsetOfFile = $request->getParsedBodyParamAsString('charset_of_file', ''); @@ -83,7 +82,7 @@ final class ImportController implements InvocableController ResponseRenderer::$reload = false; $GLOBALS['ajax_reload'] = []; - $GLOBALS['import_text'] = ''; + Import::$importText = ''; // Are we just executing plain query or sql file? // (eg. non import, but query box/window run) if (Current::$sqlQuery !== '') { @@ -113,14 +112,14 @@ final class ImportController implements InvocableController } // run SQL query - $GLOBALS['import_text'] = Current::$sqlQuery; + Import::$importText = Current::$sqlQuery; ImportSettings::$importType = 'query'; $format = 'sql'; $_SESSION['sql_from_query_box'] = true; // If there is a request to ROLLBACK when finished. if ($request->hasBodyParam('rollback_query')) { - $this->import->handleRollbackRequest($GLOBALS['import_text']); + $this->import->handleRollbackRequest(Import::$importText); } // refresh navigation and main panels @@ -271,23 +270,20 @@ final class ImportController implements InvocableController $bookmarkVariables = $request->getParsedBodyParam('bookmark_variable'); if (is_array($bookmarkVariables)) { - $GLOBALS['import_text'] = $bookmark->applyVariables($bookmarkVariables); + Import::$importText = $bookmark->applyVariables($bookmarkVariables); } else { - $GLOBALS['import_text'] = $bookmark->getQuery(); + Import::$importText = $bookmark->getQuery(); } // refresh navigation and main panels - if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $GLOBALS['import_text']) === 1) { + if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', Import::$importText) === 1) { ResponseRenderer::$reload = true; $GLOBALS['ajax_reload']['reload'] = true; } // refresh navigation panel only if ( - preg_match( - '/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', - $GLOBALS['import_text'], - ) === 1 + preg_match('/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', Import::$importText) === 1 ) { $GLOBALS['ajax_reload']['reload'] = true; } @@ -299,12 +295,12 @@ final class ImportController implements InvocableController break; } - $GLOBALS['import_text'] = $bookmark->getQuery(); + Import::$importText = $bookmark->getQuery(); if ($request->isAjax()) { Current::$message = Message::success(__('Showing bookmark')); $this->response->setRequestStatus(Current::$message->isSuccess()); $this->response->addJSON('message', Current::$message); - $this->response->addJSON('sql_query', $GLOBALS['import_text']); + $this->response->addJSON('sql_query', Import::$importText); $this->response->addJSON('action_bookmark', $actionBookmark); return $this->response->response(); @@ -430,7 +426,7 @@ final class ImportController implements InvocableController return $this->response->response(); } - } elseif (! Import::$hasError && empty($GLOBALS['import_text'])) { + } elseif (! Import::$hasError && Import::$importText === '') { Current::$message = Message::error( __( 'No data was received to import. Either no file name was ' . @@ -511,7 +507,7 @@ final class ImportController implements InvocableController // Show correct message if ($idBookmark !== 0 && $actionBookmark === 2) { Current::$message = Message::success(__('The bookmark has been deleted.')); - $GLOBALS['display_query'] = $GLOBALS['import_text']; + $GLOBALS['display_query'] = Import::$importText; Import::$hasError = false; // unset error marker, it was used just to skip processing } elseif ($idBookmark !== 0 && $actionBookmark === 1) { Current::$message = Message::notice(__('Showing bookmark')); @@ -661,7 +657,7 @@ final class ImportController implements InvocableController // sql_query_for_bookmark is not included in Sql::executeQueryAndGetQueryResponse // 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'])) { + if (! empty($request->getParsedBodyParam('bkm_label')) && Import::$importText !== '') { $this->sql->storeTheQueryAsBookmark( Current::$database, $config->selectedServer['user'], @@ -686,7 +682,7 @@ final class ImportController implements InvocableController if ($GLOBALS['result']) { // Save a Bookmark with more than one queries (if Bookmark label given). - if (! empty($request->getParsedBodyParam('bkm_label')) && ! empty($GLOBALS['import_text'])) { + if (! empty($request->getParsedBodyParam('bkm_label')) && Import::$importText !== '') { $relation = new Relation($this->dbi); $this->sql->storeTheQueryAsBookmark( diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index 3806b6bcb6..8329f09b85 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -14,6 +14,7 @@ use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Import\Import; use PhpMyAdmin\Message; use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\ResponseRenderer; @@ -44,7 +45,6 @@ class SqlController implements InvocableController $GLOBALS['display_query'] ??= null; $GLOBALS['ajax_reload'] ??= null; $GLOBALS['unlim_num_rows'] ??= null; - $GLOBALS['import_text'] ??= null; $GLOBALS['disp_query'] ??= null; $GLOBALS['message_to_show'] ??= null; $GLOBALS['disp_message'] ??= null; @@ -191,7 +191,7 @@ class SqlController implements InvocableController $isGotofile, Current::$database, Current::$table, - $GLOBALS['import_text'] ?? '', + Import::$importText, $GLOBALS['message_to_show'] ?? '', UrlParams::$goto, isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null, diff --git a/src/Import/Import.php b/src/Import/Import.php index 1608e33e22..f52715914f 100644 --- a/src/Import/Import.php +++ b/src/Import/Import.php @@ -62,6 +62,7 @@ class Import { private string|null $importRunBuffer = null; public static bool $hasError = false; + public static string $importText = ''; public function __construct() { @@ -300,15 +301,15 @@ class Import if (ImportSettings::$importFile === 'none') { // Well this is not yet supported and tested, // but should return content of textarea - if (mb_strlen($GLOBALS['import_text']) < $size) { + if (mb_strlen(self::$importText) < $size) { ImportSettings::$finished = true; - return $GLOBALS['import_text']; + return self::$importText; } - $r = mb_substr($GLOBALS['import_text'], 0, $size); + $r = mb_substr(self::$importText, 0, $size); ImportSettings::$offset += $size; - $GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size); + self::$importText = mb_substr(self::$importText, $size); return $r; } diff --git a/tests/unit/Plugins/Import/ImportCsvTest.php b/tests/unit/Plugins/Import/ImportCsvTest.php index af6e32b7de..14b669073c 100644 --- a/tests/unit/Plugins/Import/ImportCsvTest.php +++ b/tests/unit/Plugins/Import/ImportCsvTest.php @@ -66,7 +66,7 @@ class ImportCsvTest extends AbstractTestCase ]); $this->object->setImportOptions($request); - $GLOBALS['import_text'] = 'ImportCsv_Test'; + Import::$importText = 'ImportCsv_Test'; } /** @@ -215,7 +215,7 @@ class ImportCsvTest extends AbstractTestCase public function testDoImportNormal(): void { ImportSettings::$importFile = 'none'; - $GLOBALS['import_text'] = '"Row 1","Row 2"' . "\n" . '"123","456"'; + Import::$importText = '"Row 1","Row 2"' . "\n" . '"123","456"'; $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/') ->withParsedBody([ @@ -262,7 +262,7 @@ class ImportCsvTest extends AbstractTestCase public function testDoImportSkipHeaders(): void { ImportSettings::$importFile = 'none'; - $GLOBALS['import_text'] = '"Row 1","Row 2"' . "\n" . '"123","456"'; + Import::$importText = '"Row 1","Row 2"' . "\n" . '"123","456"'; $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/') ->withParsedBody([ diff --git a/tests/unit/Plugins/Import/ImportLdiTest.php b/tests/unit/Plugins/Import/ImportLdiTest.php index 5b9c1743a7..59a8f50692 100644 --- a/tests/unit/Plugins/Import/ImportLdiTest.php +++ b/tests/unit/Plugins/Import/ImportLdiTest.php @@ -47,7 +47,7 @@ class ImportLdiTest extends AbstractTestCase $config = Config::getInstance(); ImportSettings::$importFile = 'tests/test_data/db_test_ldi.csv'; - $GLOBALS['import_text'] = 'ImportLdi_Test'; + Import::$importText = 'ImportLdi_Test'; ImportSettings::$readMultiply = 10; $config->settings['Import']['ldi_replace'] = false; diff --git a/tests/unit/Plugins/Import/ImportMediawikiTest.php b/tests/unit/Plugins/Import/ImportMediawikiTest.php index 5f52a83a85..6a151d503b 100644 --- a/tests/unit/Plugins/Import/ImportMediawikiTest.php +++ b/tests/unit/Plugins/Import/ImportMediawikiTest.php @@ -47,7 +47,7 @@ class ImportMediawikiTest extends AbstractTestCase ImportSettings::$readLimit = 100000000; ImportSettings::$offset = 0; ImportSettings::$importFile = 'tests/test_data/phpmyadmin.mediawiki'; - $GLOBALS['import_text'] = 'ImportMediawiki_Test'; + Import::$importText = 'ImportMediawiki_Test'; ImportSettings::$readMultiply = 10; $this->object = new ImportMediawiki(); diff --git a/tests/unit/Plugins/Import/ImportSqlTest.php b/tests/unit/Plugins/Import/ImportSqlTest.php index 0d4c7928c3..29de345a6c 100644 --- a/tests/unit/Plugins/Import/ImportSqlTest.php +++ b/tests/unit/Plugins/Import/ImportSqlTest.php @@ -42,7 +42,7 @@ class ImportSqlTest extends AbstractTestCase ImportSettings::$readLimit = 100000000; ImportSettings::$offset = 0; ImportSettings::$importFile = 'tests/test_data/pma_bookmark.sql'; - $GLOBALS['import_text'] = 'ImportSql_Test'; + Import::$importText = 'ImportSql_Test'; ImportSettings::$readMultiply = 10; $this->object = new ImportSql(); diff --git a/tests/unit/Plugins/Import/ImportXmlTest.php b/tests/unit/Plugins/Import/ImportXmlTest.php index 61d9eafa85..358e943ffd 100644 --- a/tests/unit/Plugins/Import/ImportXmlTest.php +++ b/tests/unit/Plugins/Import/ImportXmlTest.php @@ -49,7 +49,7 @@ class ImportXmlTest extends AbstractTestCase ImportSettings::$readLimit = 100000000; ImportSettings::$offset = 0; ImportSettings::$importFile = 'tests/test_data/phpmyadmin_importXML_For_Testing.xml'; - $GLOBALS['import_text'] = 'ImportXml_Test'; + Import::$importText = 'ImportXml_Test'; ImportSettings::$readMultiply = 10; $this->object = new ImportXml();