Refactor Data

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2024-02-06 16:00:04 +01:00
parent 7a2f6f0756
commit ec738218a1
3 changed files with 21 additions and 65 deletions

View File

@ -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

View File

@ -2899,7 +2899,6 @@
<code>$linkName</code>
<code>$linkUrl</code>
<code>$sectionLinks</code>
<code>$sectionName</code>
<code>$value</code>
</MixedAssignment>
<MixedOperand>
@ -10984,30 +10983,18 @@
</file>
<file src="src/Server/Status/Data.php">
<MixedArgumentTypeCoercion>
<code>$filter</code>
<code>$name</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess>
<code><![CDATA[$usedQueries['Com_admin_commands']]]></code>
</MixedArrayAccess>
<MixedArrayOffset>
<code>$sectionUsed[$section]</code>
</MixedArrayOffset>
<MixedAssignment>
<code>$allocationMap[$name]</code>
<code>$keyReadRequests</code>
<code>$keyReads</code>
<code>$keyWriteRequests</code>
<code>$keyWrites</code>
<code>$section</code>
<code><![CDATA[$serverStatus['Key_buffer_fraction_%']]]></code>
<code><![CDATA[$serverStatus['Key_buffer_fraction_%']]]></code>
<code><![CDATA[$serverStatus['Key_read_ratio_%']]]></code>
<code><![CDATA[$serverStatus['Key_write_ratio_%']]]></code>
<code><![CDATA[$serverStatus['Threads_cache_hitrate_%']]]></code>
<code><![CDATA[$this->allocationMap]]></code>
<code><![CDATA[$this->sectionUsed]]></code>
<code><![CDATA[$this->usedQueries]]></code>
<code>$usedQueries[$name]</code>
<code>$value</code>
</MixedAssignment>

View File

@ -31,7 +31,7 @@ class Data
/** @var mixed[] */
public array $status;
/** @var mixed[] */
/** @var array<string, string> */
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<string, string>
*/
private function getAllocations(): array
{
@ -128,7 +128,7 @@ class Data
/**
* Gets the sections for constructor
*
* @return mixed[]
* @return array<string, string>
*/
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<string, string> $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
{