From ec738218a10e807c8dda873494ab87fd174dafbc Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 6 Feb 2024 16:00:04 +0100 Subject: [PATCH] Refactor Data Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 25 -------------------- psalm-baseline.xml | 13 ----------- src/Server/Status/Data.php | 48 +++++++++++++++++--------------------- 3 files changed, 21 insertions(+), 65 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3f450848f6..bcb8135c50 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -13745,11 +13745,6 @@ parameters: count: 1 path: src/Server/Select.php - - - message: "#^Cannot access offset 'Com_admin_commands' on mixed\\.$#" - count: 1 - path: src/Server/Status/Data.php - - message: "#^Cannot access offset 'doc' on mixed\\.$#" count: 4 @@ -13775,26 +13770,6 @@ parameters: count: 1 path: src/Server/Status/Data.php - - - message: "#^Parameter \\#2 \\$needle of function str_contains expects string, \\(int\\|string\\) given\\.$#" - count: 1 - path: src/Server/Status/Data.php - - - - message: "#^Property PhpMyAdmin\\\\Server\\\\Status\\\\Data\\:\\:\\$allocationMap \\(array\\) does not accept mixed\\.$#" - count: 1 - path: src/Server/Status/Data.php - - - - message: "#^Property PhpMyAdmin\\\\Server\\\\Status\\\\Data\\:\\:\\$sectionUsed \\(array\\) does not accept mixed\\.$#" - count: 1 - path: src/Server/Status/Data.php - - - - message: "#^Property PhpMyAdmin\\\\Server\\\\Status\\\\Data\\:\\:\\$usedQueries \\(array\\) does not accept mixed\\.$#" - count: 1 - path: src/Server/Status/Data.php - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" count: 4 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e57f9dfbd1..5bdd5b9944 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2899,7 +2899,6 @@ $linkName $linkUrl $sectionLinks - $sectionName $value @@ -10984,30 +10983,18 @@ - $filter $name - - - - - $sectionUsed[$section] - - $allocationMap[$name] $keyReadRequests $keyReads $keyWriteRequests $keyWrites - $section - allocationMap]]> - sectionUsed]]> - usedQueries]]> $usedQueries[$name] $value diff --git a/src/Server/Status/Data.php b/src/Server/Status/Data.php index 6adb58fb83..17560b86fe 100644 --- a/src/Server/Status/Data.php +++ b/src/Server/Status/Data.php @@ -31,7 +31,7 @@ class Data /** @var mixed[] */ public array $status; - /** @var mixed[] */ + /** @var array */ public array $sections; /** @var mixed[] */ @@ -40,7 +40,7 @@ class Data /** @var mixed[] */ public array $usedQueries; - /** @var mixed[] */ + /** @var string[] */ public array $allocationMap; /** @var mixed[] */ @@ -48,7 +48,7 @@ class Data public bool $dbIsLocal; - /** @var mixed[] */ + /** @var true[] */ public array $sectionUsed; public bool $dataLoaded; @@ -74,7 +74,7 @@ class Data /** * Gets the allocations for constructor * - * @return mixed[] + * @return array */ private function getAllocations(): array { @@ -128,7 +128,7 @@ class Data /** * Gets the sections for constructor * - * @return mixed[] + * @return array */ private function getSections(): array { @@ -284,21 +284,25 @@ class Data /** * Sort variables into arrays * - * @param mixed[] $serverStatus contains results of SHOW GLOBAL STATUS - * @param mixed[] $allocations allocations for sections - * @param mixed[] $allocationMap map variables to their section - * @param mixed[] $sectionUsed is a section used? - * @param mixed[] $usedQueries used queries + * @param mixed[] $serverStatus contains results of SHOW GLOBAL STATUS + * @param array $allocations allocations for sections * - * @return mixed[] ($allocationMap, $sectionUsed, $used_queries) + * @return array{string[], true[], mixed[]} */ private function sortVariables( array $serverStatus, array $allocations, - array $allocationMap, - array $sectionUsed, - array $usedQueries, ): array { + // Variable to contain all com_ variables (query statistics) + $usedQueries = []; + + // Variable to map variable names to their respective section name + // (used for js category filtering) + $allocationMap = []; + + // Variable to mark used sections + $sectionUsed = []; + foreach ($serverStatus as $name => $value) { $sectionFound = false; foreach ($allocations as $filter => $section) { @@ -360,22 +364,12 @@ class Data // define some needful links/commands $links = $this->getLinks(); - // Variable to contain all com_ variables (query statistics) - $usedQueries = []; - - // Variable to map variable names to their respective section name - // (used for js category filtering) - $allocationMap = []; - - // Variable to mark used sections - $sectionUsed = []; - // sort vars into arrays [ $allocationMap, $sectionUsed, $usedQueries, - ] = $this->sortVariables($serverStatus, $allocations, $allocationMap, $sectionUsed, $usedQueries); + ] = $this->sortVariables($serverStatus, $allocations); // admin commands are not queries (e.g. they include COM_PING, // which is excluded from $server_status['Questions']) @@ -405,9 +399,9 @@ class Data /** * cleanup of some deprecated values * - * @param mixed[] $serverStatus status array to process + * @param (string|null)[] $serverStatus status array to process * - * @return mixed[] + * @return (string|null)[] */ public static function cleanDeprecated(array $serverStatus): array {