Merge pull request #19452 from kamil-tekiela/Status-Data-status

Refactor Status\Data class
This commit is contained in:
Maurício Meneghini Fauth 2024-12-17 14:00:52 -03:00 committed by GitHub
commit ff8d5e295d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 162 additions and 263 deletions

View File

@ -3781,151 +3781,121 @@ parameters:
path: src/Controllers/Server/Status/Processes/KillController.php
-
message: '#^Binary operation "\*" between mixed and \(float\|int\) results in an error\.$#'
message: '#^Binary operation "\*" between float\|int and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "\*" between mixed and 100 results in an error\.$#'
message: '#^Binary operation "\*" between float\|int\|string and 100 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "\+\=" between float\|int and mixed results in an error\.$#'
message: '#^Binary operation "\*" between float\|int\|string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "\+\=" between mixed and float\|int\|string results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "/" between \(float\|int\) and mixed results in an error\.$#'
message: '#^Binary operation "/" between 3600 and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "/" between float\|int and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "/" between 3600 and mixed results in an error\.$#'
message: '#^Binary operation "/" between mixed and float\|int results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Cannot cast mixed to int\.$#'
identifier: cast.int
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, \(int\|string\) given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Server/Status/QueriesController.php
-
message: '#^Binary operation "\*" between \(array\|float\|int\) and \(float\|int\) results in an error\.$#'
message: '#^Binary operation "\*" between float\|int\|string and 100 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "\*" between mixed and \(float\|int\) results in an error\.$#'
message: '#^Binary operation "\*" between float\|int\|string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 5
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "\*" between mixed and 100 results in an error\.$#'
message: '#^Binary operation "\*" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
count: 1
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "\+" between mixed and mixed results in an error\.$#'
message: '#^Binary operation "\+" between float\|int\|string and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 3
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "\." between ''SELECT UNIX…'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "/" between \(float\|int\) and mixed results in an error\.$#'
message: '#^Binary operation "/" between 3600 and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "/" between 3600 and mixed results in an error\.$#'
message: '#^Binary operation "/" between mixed and float\|int\<1, max\>\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Cannot cast mixed to int\.$#'
identifier: cast.int
count: 1
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Only numeric types are allowed in \*, \(array\|float\|int\) given on the left side\.$#'
identifier: mul.leftNonNumeric
count: 1
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatByteDown\(\) expects float\|int\|string\|null, \(array\|float\|int\) given\.$#'
identifier: argument.type
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatByteDown\(\) expects float\|int\|string\|null, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|string, mixed given\.$#'
identifier: argument.type
count: 4
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/Controllers/Server/Status/VariablesController.php
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|string, mixed given\.$#'
identifier: argument.type
count: 5
path: src/Controllers/Server/Status/StatusController.php
-
message: '#^Binary operation "\*" between 0\.01 and mixed results in an error\.$#'
message: '#^Binary operation "\*" between 0\.01 and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Binary operation "\*" between 0\.9 and mixed results in an error\.$#'
message: '#^Binary operation "\*" between 0\.9 and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Binary operation "\*" between 0\.95 and mixed results in an error\.$#'
message: '#^Binary operation "\*" between 0\.95 and string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Binary operation "/" between mixed and 5 results in an error\.$#'
message: '#^Binary operation "/" between float\|int\|string and 5 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controllers/Server/Status/VariablesController.php
@ -3942,18 +3912,6 @@ parameters:
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Parameter \#1 \$haystack of function str_contains expects string, \(int\|string\) given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Parameter \#1 \$name of static method PhpMyAdmin\\Html\\Generator\:\:linkToVarDocumentation\(\) expects string, \(int\|string\) given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Server/Status/VariablesController.php
-
message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#'
identifier: ternary.shortNotAllowed
@ -16225,13 +16183,19 @@ parameters:
path: src/Server/Status/Data.php
-
message: '#^Binary operation "\*" between mixed and 1024 results in an error\.$#'
message: '#^Binary operation "\*" between mixed and 100 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Server/Status/Data.php
-
message: '#^Binary operation "\*" between mixed and mixed results in an error\.$#'
message: '#^Binary operation "\*" between string and 1024 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Server/Status/Data.php
-
message: '#^Binary operation "\*" between string and string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Server/Status/Data.php
@ -16239,7 +16203,7 @@ parameters:
-
message: '#^Binary operation "/" between \(float\|int\) and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 4
count: 2
path: src/Server/Status/Data.php
-
@ -16248,6 +16212,12 @@ parameters:
count: 1
path: src/Server/Status/Data.php
-
message: '#^Binary operation "/" between mixed and string results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/Server/Status/Data.php
-
message: '#^Cannot access offset ''doc'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
@ -16266,6 +16236,12 @@ parameters:
count: 2
path: src/Server/Status/Data.php
-
message: '#^Method PhpMyAdmin\\Server\\Status\\Data\:\:calculateValues\(\) should return array\<string, float\|int\|string\> but returns array\<string, mixed\>\.$#'
identifier: return.type
count: 1
path: src/Server/Status/Data.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
@ -16278,12 +16254,6 @@ parameters:
count: 1
path: src/Server/Status/Data.php
-
message: '#^Parameter \#1 \$haystack of function str_contains expects string, \(int\|string\) given\.$#'
identifier: argument.type
count: 1
path: src/Server/Status/Data.php
-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
@ -20271,19 +20241,13 @@ parameters:
count: 1
path: tests/unit/Controllers/Server/ShowEngineControllerTest.php
-
message: '#^@readonly property PhpMyAdmin\\Server\\Status\\Data\:\:\$dataLoaded is assigned outside of its declaring class\.$#'
identifier: property.readOnlyByPhpDocAssignOutOfClass
count: 2
path: tests/unit/Controllers/Server/Status/AdvisorControllerTest.php
-
message: '''
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
count: 1
count: 2
path: tests/unit/Controllers/Server/Status/AdvisorControllerTest.php
-
@ -20467,25 +20431,19 @@ parameters:
path: tests/unit/Controllers/Server/Status/ProcessesControllerTest.php
-
message: '#^@readonly property PhpMyAdmin\\Server\\Status\\Data\:\:\$status is assigned outside of its declaring class\.$#'
identifier: property.readOnlyByPhpDocAssignOutOfClass
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '#^@readonly property PhpMyAdmin\\Server\\Status\\Data\:\:\$usedQueries is assigned outside of its declaring class\.$#'
identifier: property.readOnlyByPhpDocAssignOutOfClass
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '#^Binary operation "/" between \(float\|int\) and mixed results in an error\.$#'
message: '#^Binary operation "\*" between float\|int and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '#^Binary operation "/" between 3600 and mixed results in an error\.$#'
message: '#^Binary operation "/" between 3600 and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '#^Binary operation "/" between float\|int and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
@ -20509,10 +20467,10 @@ parameters:
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '#^@readonly property PhpMyAdmin\\Server\\Status\\Data\:\:\$status is assigned outside of its declaring class\.$#'
identifier: property.readOnlyByPhpDocAssignOutOfClass
count: 6
path: tests/unit/Controllers/Server/Status/StatusControllerTest.php
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: tests/unit/Controllers/Server/Status/QueriesControllerTest.php
-
message: '''
@ -20529,7 +20487,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
count: 3
count: 2
path: tests/unit/Controllers/Server/Status/StatusControllerTest.php
-

View File

@ -2290,58 +2290,20 @@
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Server/Status/QueriesController.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$key]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$chart[__('Other statements')]]]></code>
<code><![CDATA[$hourFactor]]></code>
<code><![CDATA[$otherSum]]></code>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$hourFactor]]></code>
<PossiblyInvalidOperand>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
</MixedOperand>
<PossiblyInvalidArgument>
<code><![CDATA[str_replace(['Com_', '_'], ['', ' '], $key)]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code><![CDATA[str_replace(['Com_', '_'], ['', ' '], $key)]]></code>
</PossiblyInvalidCast>
</PossiblyInvalidOperand>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Server/Status/StatusController.php">
<MixedArgument>
<code><![CDATA[$this->data->status['Aborted_clients']]]></code>
<code><![CDATA[$this->data->status['Aborted_clients'] * $hourFactor]]></code>
<code><![CDATA[$this->data->status['Aborted_clients'] * 100 / $this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Aborted_connects']]]></code>
<code><![CDATA[$this->data->status['Aborted_connects'] * $hourFactor]]></code>
<code><![CDATA[$this->data->status['Aborted_connects'] * 100 / $this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Bytes_received']]]></code>
<code><![CDATA[$this->data->status['Bytes_received'] * $hourFactor]]></code>
<code><![CDATA[$this->data->status['Bytes_received'] + $this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_received'] + $this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent'] * $hourFactor]]></code>
<code><![CDATA[$this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Connections'] * $hourFactor]]></code>
<code><![CDATA[$this->data->status['Max_used_connections']]]></code>
<code><![CDATA[($this->data->status['Bytes_received'] + $this->data->status['Bytes_sent']) * $hourFactor]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$hourFactor]]></code>
<code><![CDATA[$hourFactor]]></code>
</MixedAssignment>
<MixedOperand>
<PossiblyInvalidOperand>
<code><![CDATA[$this->data->status['Aborted_clients']]]></code>
<code><![CDATA[$this->data->status['Aborted_clients']]]></code>
<code><![CDATA[$this->data->status['Aborted_connects']]]></code>
@ -2351,40 +2313,38 @@
<code><![CDATA[$this->data->status['Bytes_received']]]></code>
<code><![CDATA[$this->data->status['Bytes_received']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Bytes_sent']]]></code>
<code><![CDATA[$this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Connections']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
</MixedOperand>
</PossiblyInvalidOperand>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Controllers/Server/Status/VariablesController.php">
<InvalidOperand>
<code><![CDATA[$this->data->variables['thread_cache_size']]]></code>
</InvalidOperand>
<MixedArgument>
<code><![CDATA[$flush]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$name]]></code>
<code><![CDATA[$name]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$dontFormat]]></code>
<code><![CDATA[$filterAlert]]></code>
<code><![CDATA[$filterCategory]]></code>
<code><![CDATA[$filterText]]></code>
<code><![CDATA[$flush]]></code>
<code><![CDATA[$linkName]]></code>
<code><![CDATA[$linkUrl]]></code>
<code><![CDATA[$sectionLinks]]></code>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedOperand>
<PossiblyInvalidOperand>
<code><![CDATA[$this->data->status['Key_read_requests']]]></code>
<code><![CDATA[$this->data->status['Key_write_requests']]]></code>
<code><![CDATA[$this->data->status['Qcache_total_blocks']]]></code>
<code><![CDATA[$this->data->variables['thread_cache_size']]]></code>
</MixedOperand>
</PossiblyInvalidOperand>
<PossiblyUnusedReturnValue>
<code><![CDATA[Response]]></code>
</PossiblyUnusedReturnValue>
@ -9441,40 +9401,23 @@
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Server/Status/Data.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$name]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<InvalidOperand>
<code><![CDATA[$serverStatus['Key_blocks_unused']]]></code>
<code><![CDATA[$serverStatus['Key_blocks_used']]]></code>
<code><![CDATA[$serverVariables['key_buffer_size']]]></code>
<code><![CDATA[$serverVariables['key_buffer_size']]]></code>
</InvalidOperand>
<PossiblyInvalidArgument>
<code><![CDATA[$_POST['primary_connection'] ?? null]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidOperand>
<code><![CDATA[$keyReadRequests]]></code>
<code><![CDATA[$keyReads]]></code>
<code><![CDATA[$keyWriteRequests]]></code>
<code><![CDATA[$keyWrites]]></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[$usedQueries[$name]]]></code>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$keyReads]]></code>
<code><![CDATA[$keyWrites]]></code>
<code><![CDATA[$serverStatus['Key_blocks_unused']]]></code>
<code><![CDATA[$serverStatus['Key_blocks_unused']
* $serverVariables['key_cache_block_size']
/ $serverVariables['key_buffer_size']
* 100]]></code>
<code><![CDATA[$serverStatus['Key_blocks_used']]]></code>
<code><![CDATA[$serverStatus['Connections']]]></code>
<code><![CDATA[$serverStatus['Threads_created']]]></code>
<code><![CDATA[$serverStatus['Threads_created']
/ $serverStatus['Connections'] * 100]]></code>
<code><![CDATA[100 * $keyReads]]></code>
<code><![CDATA[100 * $keyWrites]]></code>
</MixedOperand>
<PossiblyInvalidArgument>
<code><![CDATA[$_POST['primary_connection'] ?? null]]></code>
</PossiblyInvalidArgument>
</PossiblyInvalidOperand>
<UnusedProperty>
<code><![CDATA[$dbi]]></code>
</UnusedProperty>
@ -11839,14 +11782,11 @@
</file>
<file src="tests/unit/Controllers/Server/Status/AdvisorControllerTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$this->data->dataLoaded]]></code>
<code><![CDATA[$this->data->dataLoaded]]></code>
</InaccessibleProperty>
</file>
<file src="tests/unit/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php">
<DeprecatedMethod>
@ -11911,22 +11851,10 @@
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$this->data->status]]></code>
<code><![CDATA[$this->data->usedQueries]]></code>
</InaccessibleProperty>
<MixedArgument>
<code><![CDATA[$totalQueries * $hourFactor]]></code>
<code><![CDATA[$totalQueries * 60 / $this->data->status['Uptime']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$hourFactor]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$hourFactor]]></code>
<PossiblyInvalidOperand>
<code><![CDATA[$this->data->status['Uptime']]]></code>
<code><![CDATA[$this->data->status['Uptime']]]></code>
</MixedOperand>
</PossiblyInvalidOperand>
</file>
<file src="tests/unit/Controllers/Server/Status/StatusControllerTest.php">
<DeprecatedMethod>
@ -11934,16 +11862,7 @@
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InaccessibleProperty>
<code><![CDATA[$data->status]]></code>
<code><![CDATA[$data->status]]></code>
<code><![CDATA[$data->status]]></code>
<code><![CDATA[$data->status]]></code>
<code><![CDATA[$data->status]]></code>
<code><![CDATA[$data->status]]></code>
</InaccessibleProperty>
</file>
<file src="tests/unit/Controllers/Server/Status/VariablesControllerTest.php">
<DeprecatedMethod>

View File

@ -69,28 +69,22 @@ final class Data
'Opened_files' => 'files',
];
/**
* @var mixed[]
* @readonly
* */
public array $status;
/** @var array<string, string|int|float> */
public readonly array $status;
/** @var array<string, string> */
public readonly array $sections;
/** @var mixed[] */
/** @var array<string, string> */
public readonly array $variables;
/**
* @var mixed[]
* @readonly
*/
public array $usedQueries;
/** @var array<string, string|int|float> */
public readonly array $usedQueries;
/** @var string[] */
public readonly array $allocationMap;
/** @var mixed[] */
/** @var array<string, array<string, string|array{url: string, params: string}>> */
public readonly array $links;
public readonly bool $dbIsLocal;
@ -98,8 +92,7 @@ final class Data
/** @var true[] */
public readonly array $sectionUsed;
/** @readonly */
public bool $dataLoaded;
public readonly bool $dataLoaded;
private readonly ReplicationInfo $replicationInfo;
@ -141,7 +134,7 @@ final class Data
/**
* Gets the links for constructor
*
* @return mixed[]
* @return array<string, array<string, string|array{url: string, params: string}>>
*/
private function getLinks(): array
{
@ -203,10 +196,10 @@ final class Data
/**
* Calculate some values
*
* @param mixed[] $serverStatus contains results of SHOW GLOBAL STATUS
* @param mixed[] $serverVariables contains results of SHOW GLOBAL VARIABLES
* @param array<string, string> $serverStatus contains results of SHOW GLOBAL STATUS
* @param array<string, string> $serverVariables contains results of SHOW GLOBAL VARIABLES
*
* @return mixed[]
* @return array<string, string|int|float>
*/
private function calculateValues(array $serverStatus, array $serverVariables): array
{
@ -266,9 +259,9 @@ final class Data
/**
* Sort variables into arrays
*
* @param mixed[] $serverStatus contains results of SHOW GLOBAL STATUS
* @param array<string, string|int|float> $serverStatus contains results of SHOW GLOBAL STATUS
*
* @return array{string[], true[], mixed[]}
* @return array{string[], true[], array<string, string|int|float>}
*/
private function sortVariables(array $serverStatus): array
{
@ -314,19 +307,19 @@ final class Data
$this->dataLoaded = false;
} else {
$this->dataLoaded = true;
/** @var array<string, string> $serverStatus */
$serverStatus = $serverStatusResult->fetchAllKeyPair();
unset($serverStatusResult);
}
// for some calculations we require also some server settings
/** @var array<string, string> $serverVariables */
$serverVariables = $this->dbi->fetchResult('SHOW GLOBAL VARIABLES', 0, 1);
$serverStatus = self::cleanDeprecated($serverStatus);
$serverStatus = $this->calculateValues($serverStatus, $serverVariables);
$links = $this->getLinks();
[
$allocationMap,
$sectionUsed,
@ -337,8 +330,7 @@ final class Data
// which is excluded from $server_status['Questions'])
unset($usedQueries['Com_admin_commands']);
$serverHostToLower = mb_strtolower($config->selectedServer['host']);
$this->dbIsLocal = $serverHostToLower === 'localhost'
$this->dbIsLocal = mb_strtolower($config->selectedServer['host']) === 'localhost'
|| $config->selectedServer['host'] === '127.0.0.1'
|| $config->selectedServer['host'] === '::1';
@ -347,16 +339,16 @@ final class Data
$this->variables = $serverVariables;
$this->usedQueries = $usedQueries;
$this->allocationMap = $allocationMap;
$this->links = $links;
$this->links = $this->getLinks();
$this->sectionUsed = $sectionUsed;
}
/**
* cleanup of some deprecated values
*
* @param (string|null)[] $serverStatus status array to process
* @param array<string, string> $serverStatus status array to process
*
* @return (string|null)[]
* @return array<string, string>
*/
public static function cleanDeprecated(array $serverStatus): array
{

View File

@ -44,12 +44,15 @@ class AdvisorControllerTest extends AbstractTestCase
public function testIndexWithoutData(): void
{
$this->data->dataLoaded = false;
$dummyDbi = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dummyDbi);
$dummyDbi->addResult('SHOW GLOBAL STATUS', false);
$data = new Data($dbi, Config::getInstance());
$controller = new AdvisorController(
$this->response,
$this->template,
$this->data,
$data,
new Advisor(DatabaseInterface::getInstance(), new ExpressionLanguage()),
);
@ -91,8 +94,6 @@ class AdvisorControllerTest extends AbstractTestCase
$advisor = self::createMock(Advisor::class);
$advisor->method('run')->willReturn($advisorData);
$this->data->dataLoaded = true;
$controller = new AdvisorController($this->response, $this->template, $this->data, $advisor);
$controller(self::createStub(ServerRequest::class));

View File

@ -46,16 +46,36 @@ class QueriesControllerTest extends AbstractTestCase
$config->selectedServer['DisableIS'] = false;
$config->selectedServer['host'] = 'localhost';
$this->data = new Data($this->dbi, $config);
$this->data->status['Uptime'] = 36000;
$this->data->usedQueries = [
$dummyDbi = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dummyDbi);
$dummyDbi->addResult('SHOW GLOBAL STATUS', [
['Uptime' , '36000'],
['Aborted_connects' , '0'],
['Aborted_clients', '0'],
['Com_delete_multi', '0'],
['Com_create_function', '0'],
['Com_empty_query', '0'],
['Com_change_db' , '15'],
['Com_select' , '12'],
['Com_set_option' , '54'],
['Com_show_databases' , '16'],
['Com_show_status' , '14'],
['Com_show_tables' , '13'],
], ['Variable_name', 'Value']);
$this->data = new Data($dbi, $config);
}
public function testUsedQueries(): void
{
self::assertSame([
'Com_change_db' => '15',
'Com_select' => '12',
'Com_set_option' => '54',
'Com_show_databases' => '16',
'Com_show_status' => '14',
'Com_show_tables' => '13',
];
], $this->data->usedQueries);
}
public function testIndex(): void

View File

@ -44,19 +44,28 @@ class StatusControllerTest extends AbstractTestCase
public function testIndex(): void
{
$data = new Data(DatabaseInterface::getInstance(), Config::getInstance());
$bytesReceived = 100;
$bytesSent = 200;
$maxUsedConnections = 500;
$abortedConnections = 200;
$connections = 1000;
$data->status['Uptime'] = 36000;
$data->status['Bytes_received'] = $bytesReceived;
$data->status['Bytes_sent'] = $bytesSent;
$data->status['Max_used_connections'] = $maxUsedConnections;
$data->status['Aborted_connects'] = $abortedConnections;
$data->status['Connections'] = $connections;
$dummyDbi = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dummyDbi);
$dummyDbi->addResult('SHOW GLOBAL STATUS', [
['Uptime' , '36000'],
['Bytes_received' , $bytesReceived],
['Bytes_sent' , $bytesSent],
['Max_used_connections' ,$maxUsedConnections],
['Aborted_connects' , $abortedConnections],
['Connections' , $connections],
['Aborted_clients', '0'],
['Com_delete_multi', '0'],
['Com_create_function', '0'],
['Com_empty_query', '0'],
], ['Variable_name', 'Value']);
$data = new Data($dbi, Config::getInstance());
$response = new ResponseRenderer();
$template = new Template();