diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 69172b86bf..644993af8d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12372,18 +12372,6 @@ parameters: count: 2 path: src/Plugins/Export/ExportLatex.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportLatex.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportLatex.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12426,12 +12414,6 @@ parameters: count: 1 path: src/Plugins/Export/ExportLatex.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportLatex.php - - message: '#^Parameter \#1 \$string of static method PhpMyAdmin\\Plugins\\Export\\ExportLatex\:\:texEscape\(\) expects string, mixed given\.$#' identifier: argument.type @@ -12651,18 +12633,6 @@ parameters: count: 4 path: src/Plugins/Export/ExportOdt.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportOdt.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12693,12 +12663,6 @@ parameters: count: 1 path: src/Plugins/Export/ExportOdt.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Only booleans are allowed in an if condition, array\|false given\.$#' identifier: if.condNotBoolean @@ -12873,18 +12837,6 @@ parameters: count: 8 path: src/Plugins/Export/ExportSql.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Plugins/Export/ExportSql.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportSql.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12993,12 +12945,6 @@ parameters: count: 6 path: src/Plugins/Export/ExportSql.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportSql.php - - message: '#^Only booleans are allowed in an if condition, bool\|null given\.$#' identifier: if.condNotBoolean @@ -22176,18 +22122,6 @@ parameters: count: 3 path: tests/unit/Plugins/Export/ExportLatexTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportLatexTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportLatexTest.php - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: 80, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' identifier: assign.propertyType @@ -22203,18 +22137,6 @@ parameters: count: 1 path: tests/unit/Plugins/Export/ExportOdtTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportOdtTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportOdtTest.php - - message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#' identifier: argument.type @@ -22230,18 +22152,6 @@ parameters: count: 9 path: tests/unit/Plugins/Export/ExportSqlTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportSqlTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportSqlTest.php - - message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#' identifier: argument.type @@ -22263,12 +22173,6 @@ parameters: count: 1 path: tests/unit/Plugins/Export/ExportTexytextTest.php - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: tests/unit/Plugins/Export/ExportTexytextTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: @@ -22278,12 +22182,6 @@ parameters: count: 2 path: tests/unit/Plugins/Export/ExportXmlTest.php - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: tests/unit/Plugins/Export/ExportXmlTest.php - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: 80, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' identifier: assign.propertyType diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f7a7ee03f8..9cfc02a849 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7330,10 +7330,6 @@ - - - - @@ -7454,10 +7450,6 @@ - - - - @@ -7606,11 +7598,6 @@ - - - - - diff --git a/src/Plugins.php b/src/Plugins.php index 0c131969a4..668f45fa49 100644 --- a/src/Plugins.php +++ b/src/Plugins.php @@ -58,7 +58,8 @@ class Plugins */ public static function getPlugin(string $type, string $format, array|string|null $param = null): object|null { - $GLOBALS['plugin_param'] = $param; + ExportPlugin::$exportType = $param['export_type'] ?? ''; + ExportPlugin::$singleTable = $param['single_table'] ?? false; $pluginType = mb_strtoupper($type[0]) . mb_strtolower(mb_substr($type, 1)); $pluginFormat = mb_strtoupper($format[0]) . mb_strtolower(mb_substr($format, 1)); $class = sprintf('PhpMyAdmin\\Plugins\\%s\\%s%s', $pluginType, $pluginType, $pluginFormat); @@ -89,7 +90,8 @@ class Plugins */ public static function getExport(string $type, bool $singleTable): array { - $GLOBALS['plugin_param'] = ['export_type' => $type, 'single_table' => $singleTable]; + ExportPlugin::$exportType = $type; + ExportPlugin::$singleTable = $singleTable; return self::getPlugins('Export'); } diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php index 6546e06663..5f7b4df3bd 100644 --- a/src/Plugins/Export/ExportLatex.php +++ b/src/Plugins/Export/ExportLatex.php @@ -55,10 +55,8 @@ class ExportLatex extends ExportPlugin protected function setProperties(): ExportPluginProperties { - $GLOBALS['plugin_param'] ??= null; - $hideStructure = false; - if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) { + if (ExportPlugin::$exportType === 'table' && ! ExportPlugin::$singleTable) { $hideStructure = true; } diff --git a/src/Plugins/Export/ExportOdt.php b/src/Plugins/Export/ExportOdt.php index 6aaa0646ce..af3e7665a1 100644 --- a/src/Plugins/Export/ExportOdt.php +++ b/src/Plugins/Export/ExportOdt.php @@ -45,10 +45,8 @@ class ExportOdt extends ExportPlugin protected function setProperties(): ExportPluginProperties { - $GLOBALS['plugin_param'] ??= null; - $hideStructure = false; - if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) { + if (ExportPlugin::$exportType === 'table' && ! ExportPlugin::$singleTable) { $hideStructure = true; } diff --git a/src/Plugins/Export/ExportSql.php b/src/Plugins/Export/ExportSql.php index a5469efe69..8be8896f30 100644 --- a/src/Plugins/Export/ExportSql.php +++ b/src/Plugins/Export/ExportSql.php @@ -94,11 +94,9 @@ class ExportSql extends ExportPlugin protected function setProperties(): ExportPluginProperties { - $GLOBALS['plugin_param'] ??= null; - $hideSql = false; $hideStructure = false; - if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) { + if (ExportPlugin::$exportType === 'table' && ! ExportPlugin::$singleTable) { $hideStructure = true; $hideSql = true; } @@ -243,7 +241,7 @@ class ExportSql extends ExportPlugin $subgroup->setSubgroupHeader($leaf); // server export options - if ($GLOBALS['plugin_param']['export_type'] === 'server') { + if (ExportPlugin::$exportType === 'server') { $leaf = new BoolPropertyItem( 'drop_database', sprintf(__('Add %s statement'), 'DROP DATABASE IF EXISTS'), @@ -251,7 +249,7 @@ class ExportSql extends ExportPlugin $subgroup->addProperty($leaf); } - if ($GLOBALS['plugin_param']['export_type'] === 'database') { + if (ExportPlugin::$exportType === 'database') { $createClause = 'CREATE DATABASE / USE'; $leaf = new BoolPropertyItem( 'create_database', @@ -260,7 +258,7 @@ class ExportSql extends ExportPlugin $subgroup->addProperty($leaf); } - if ($GLOBALS['plugin_param']['export_type'] === 'table') { + if (ExportPlugin::$exportType === 'table') { $dropClause = $dbi->getTable(Current::$database, Current::$table)->isView() ? 'DROP VIEW' : 'DROP TABLE'; diff --git a/src/Plugins/ExportPlugin.php b/src/Plugins/ExportPlugin.php index 630f9e926b..094eea28a3 100644 --- a/src/Plugins/ExportPlugin.php +++ b/src/Plugins/ExportPlugin.php @@ -28,6 +28,9 @@ abstract class ExportPlugin implements Plugin */ protected ExportPluginProperties $properties; + public static string $exportType = ''; + public static bool $singleTable = false; + final public function __construct( public Relation $relation, protected Export $export, diff --git a/tests/unit/Export/ExportTest.php b/tests/unit/Export/ExportTest.php index 54c7156fc0..d9c54ce7fb 100644 --- a/tests/unit/Export/ExportTest.php +++ b/tests/unit/Export/ExportTest.php @@ -96,7 +96,6 @@ class ExportTest extends AbstractTestCase public function testExportDatabase(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'database', 'single_table' => false]; $GLOBALS['sql_create_view'] = 'something'; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; @@ -163,7 +162,6 @@ SQL; public function testExportServer(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'server', 'single_table' => false]; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; diff --git a/tests/unit/Plugins/Export/ExportLatexTest.php b/tests/unit/Plugins/Export/ExportLatexTest.php index 877a1e050b..42b8589de3 100644 --- a/tests/unit/Plugins/Export/ExportLatexTest.php +++ b/tests/unit/Plugins/Export/ExportLatexTest.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Current; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportLatex; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -50,9 +51,8 @@ class ExportLatexTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; Current::$database = 'db'; Current::$table = 'table'; $this->object = new ExportLatex( @@ -75,8 +75,8 @@ class ExportLatexTest extends AbstractTestCase public function testSetProperties(): void { - $GLOBALS['plugin_param']['export_type'] = ''; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ''; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', @@ -419,8 +419,8 @@ class ExportLatexTest extends AbstractTestCase ); // case 2 - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; $method->invoke($this->object, null); diff --git a/tests/unit/Plugins/Export/ExportOdtTest.php b/tests/unit/Plugins/Export/ExportOdtTest.php index 1868a63943..b148421b30 100644 --- a/tests/unit/Plugins/Export/ExportOdtTest.php +++ b/tests/unit/Plugins/Export/ExportOdtTest.php @@ -14,6 +14,7 @@ use PhpMyAdmin\Export\Export; use PhpMyAdmin\Identifiers\TableName; use PhpMyAdmin\Identifiers\TriggerName; use PhpMyAdmin\Plugins\Export\ExportOdt; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -69,9 +70,8 @@ class ExportOdtTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new ExportOdt( new Relation($this->dbi), @@ -93,8 +93,8 @@ class ExportOdtTest extends AbstractTestCase public function testSetProperties(): void { - $GLOBALS['plugin_param']['export_type'] = ''; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ''; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', @@ -294,8 +294,8 @@ class ExportOdtTest extends AbstractTestCase ); // case 2 - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; $method->invoke($this->object, null); diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index d9a74d7736..55e148bc5b 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -13,6 +13,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertySubgroup; @@ -67,9 +68,8 @@ class ExportSqlTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; $this->object = new ExportSql( new Relation($dbi), @@ -93,8 +93,8 @@ class ExportSqlTest extends AbstractTestCase public function testSetPropertiesWithHideSql(): void { // test with hide structure and hide sql as true - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; $method = new ReflectionMethod(ExportSql::class, 'setProperties'); $properties = $method->invoke($this->object, null); @@ -116,8 +116,8 @@ class ExportSqlTest extends AbstractTestCase ->willReturn(['v1', 'v2']); DatabaseInterface::$instance = $dbi; - $GLOBALS['plugin_param']['export_type'] = 'server'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'server'; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', diff --git a/tests/unit/Plugins/Export/ExportTexytextTest.php b/tests/unit/Plugins/Export/ExportTexytextTest.php index eb45bbd83f..7869858238 100644 --- a/tests/unit/Plugins/Export/ExportTexytextTest.php +++ b/tests/unit/Plugins/Export/ExportTexytextTest.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Export\Export; use PhpMyAdmin\Identifiers\TableName; use PhpMyAdmin\Identifiers\TriggerName; use PhpMyAdmin\Plugins\Export\ExportTexytext; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -60,9 +61,8 @@ class ExportTexytextTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; Current::$database = ''; Current::$table = ''; $GLOBALS['lang'] = 'en'; diff --git a/tests/unit/Plugins/Export/ExportXmlTest.php b/tests/unit/Plugins/Export/ExportXmlTest.php index 3ab87ac212..b233dd3218 100644 --- a/tests/unit/Plugins/Export/ExportXmlTest.php +++ b/tests/unit/Plugins/Export/ExportXmlTest.php @@ -10,6 +10,7 @@ use PhpMyAdmin\Current; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportXml; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -45,9 +46,8 @@ class ExportXmlTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = 'table'; + ExportPlugin::$singleTable = false; Current::$database = 'db'; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new ExportXml( diff --git a/tests/unit/PluginsTest.php b/tests/unit/PluginsTest.php index 1c39529877..0fbd5b11e4 100644 --- a/tests/unit/PluginsTest.php +++ b/tests/unit/PluginsTest.php @@ -10,6 +10,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Import\ImportSettings; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Transformations; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -27,7 +28,8 @@ class PluginsTest extends AbstractTestCase public function testGetExport(): void { $plugins = Plugins::getExport('database', false); - self::assertSame(['export_type' => 'database', 'single_table' => false], $GLOBALS['plugin_param']); + self::assertSame('database', ExportPlugin::$exportType); + self::assertFalse(ExportPlugin::$singleTable); self::assertCount(14, $plugins); self::assertContainsOnlyInstancesOf(Plugins\ExportPlugin::class, $plugins); } @@ -98,7 +100,6 @@ class PluginsTest extends AbstractTestCase public function testGetChoice(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'database', 'single_table' => false]; $dbi = DatabaseInterface::getInstance(); $exportList = [ new Plugins\Export\ExportJson(