diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ce199dfe62..e7ec61ad7e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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, \(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\ but returns array\\.$#' + 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 - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7adcf759ca..0f12c8db83 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2290,58 +2290,20 @@ - - - - - - - - - - - + data->status['Uptime']]]> data->status['Uptime']]]> data->status['Uptime']]]> - - - - - - - + - - data->status['Aborted_clients']]]> - data->status['Aborted_clients'] * $hourFactor]]> - data->status['Aborted_clients'] * 100 / $this->data->status['Connections']]]> - data->status['Aborted_connects']]]> - data->status['Aborted_connects'] * $hourFactor]]> - data->status['Aborted_connects'] * 100 / $this->data->status['Connections']]]> - data->status['Bytes_received']]]> - data->status['Bytes_received'] * $hourFactor]]> - data->status['Bytes_received'] + $this->data->status['Bytes_sent']]]> - data->status['Bytes_received'] + $this->data->status['Bytes_sent']]]> - data->status['Bytes_sent']]]> - data->status['Bytes_sent'] * $hourFactor]]> - data->status['Connections']]]> - data->status['Connections'] * $hourFactor]]> - data->status['Max_used_connections']]]> - data->status['Bytes_received'] + $this->data->status['Bytes_sent']) * $hourFactor]]> - - - - - - + data->status['Aborted_clients']]]> data->status['Aborted_clients']]]> data->status['Aborted_connects']]]> @@ -2351,40 +2313,38 @@ data->status['Bytes_received']]]> data->status['Bytes_received']]]> data->status['Bytes_sent']]]> + data->status['Bytes_sent']]]> + data->status['Bytes_sent']]]> + data->status['Bytes_sent']]]> + data->status['Connections']]]> + data->status['Connections']]]> data->status['Connections']]]> data->status['Uptime']]]> data->status['Uptime']]]> - data->status['Uptime']]]> - + + + data->variables['thread_cache_size']]]> + - - - - - - - - - + data->status['Key_read_requests']]]> data->status['Key_write_requests']]]> data->status['Qcache_total_blocks']]]> - data->variables['thread_cache_size']]]> - + @@ -9441,40 +9401,23 @@ - - - - + + + + + + + + + + - - - - - - - - - - - - - - + - - - - - - - + @@ -11839,14 +11782,11 @@ + - - data->dataLoaded]]> - data->dataLoaded]]> - @@ -11911,22 +11851,10 @@ - - data->status]]> - data->usedQueries]]> - - - - data->status['Uptime']]]> - - - - - - + data->status['Uptime']]]> data->status['Uptime']]]> - + @@ -11934,16 +11862,7 @@ - - - status]]> - status]]> - status]]> - status]]> - status]]> - status]]> - diff --git a/src/Server/Status/Data.php b/src/Server/Status/Data.php index a6df004902..0ce8757e7c 100644 --- a/src/Server/Status/Data.php +++ b/src/Server/Status/Data.php @@ -69,28 +69,22 @@ final class Data 'Opened_files' => 'files', ]; - /** - * @var mixed[] - * @readonly - * */ - public array $status; + /** @var array */ + public readonly array $status; /** @var array */ public readonly array $sections; - /** @var mixed[] */ + /** @var array */ public readonly array $variables; - /** - * @var mixed[] - * @readonly - */ - public array $usedQueries; + /** @var array */ + public readonly array $usedQueries; /** @var string[] */ public readonly array $allocationMap; - /** @var mixed[] */ + /** @var array> */ 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> */ 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 $serverStatus contains results of SHOW GLOBAL STATUS + * @param array $serverVariables contains results of SHOW GLOBAL VARIABLES * - * @return mixed[] + * @return array */ 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 $serverStatus contains results of SHOW GLOBAL STATUS * - * @return array{string[], true[], mixed[]} + * @return array{string[], true[], array} */ private function sortVariables(array $serverStatus): array { @@ -314,19 +307,19 @@ final class Data $this->dataLoaded = false; } else { $this->dataLoaded = true; + /** @var array $serverStatus */ $serverStatus = $serverStatusResult->fetchAllKeyPair(); unset($serverStatusResult); } // for some calculations we require also some server settings + /** @var array $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 $serverStatus status array to process * - * @return (string|null)[] + * @return array */ public static function cleanDeprecated(array $serverStatus): array { diff --git a/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php b/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php index 5257ea291f..d56bcb6c01 100644 --- a/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php +++ b/tests/unit/Controllers/Server/Status/AdvisorControllerTest.php @@ -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)); diff --git a/tests/unit/Controllers/Server/Status/QueriesControllerTest.php b/tests/unit/Controllers/Server/Status/QueriesControllerTest.php index 96251ba4ed..1aceeb2375 100644 --- a/tests/unit/Controllers/Server/Status/QueriesControllerTest.php +++ b/tests/unit/Controllers/Server/Status/QueriesControllerTest.php @@ -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 diff --git a/tests/unit/Controllers/Server/Status/StatusControllerTest.php b/tests/unit/Controllers/Server/Status/StatusControllerTest.php index f05e9b7eca..79ba64ce54 100644 --- a/tests/unit/Controllers/Server/Status/StatusControllerTest.php +++ b/tests/unit/Controllers/Server/Status/StatusControllerTest.php @@ -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();