From fe159c3f50b430fd5e5c146084ac354220ddab81 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 23 Jan 2024 23:17:56 +0100 Subject: [PATCH] Add better type hint to getStorageEngines() Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 19 ++----------------- psalm-baseline.xml | 8 +------- src/StorageEngine.php | 11 +++++------ 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 73ae547596..af2780d750 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -14910,11 +14910,6 @@ parameters: count: 1 path: src/StorageEngine.php - - - message: "#^Cannot access offset 'Support' on mixed\\.$#" - count: 1 - path: src/StorageEngine.php - - message: "#^Cannot access offset 'desc' on mixed\\.$#" count: 1 @@ -14952,7 +14947,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 3 + count: 2 path: src/StorageEngine.php - @@ -14966,7 +14961,7 @@ parameters: path: src/StorageEngine.php - - message: "#^Method PhpMyAdmin\\\\StorageEngine\\:\\:getStorageEngines\\(\\) should return array\\ but returns mixed\\.$#" + message: "#^Method PhpMyAdmin\\\\StorageEngine\\:\\:getStorageEngines\\(\\) should return array\\ but returns mixed\\.$#" count: 1 path: src/StorageEngine.php @@ -15000,16 +14995,6 @@ parameters: count: 1 path: src/StorageEngine.php - - - message: "#^Property PhpMyAdmin\\\\StorageEngine\\:\\:\\$comment \\(string\\) does not accept mixed\\.$#" - count: 1 - path: src/StorageEngine.php - - - - message: "#^Property PhpMyAdmin\\\\StorageEngine\\:\\:\\$title \\(string\\) does not accept mixed\\.$#" - count: 1 - path: src/StorageEngine.php - - message: "#^Variable method call on \\$this\\(PhpMyAdmin\\\\StorageEngine\\)\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c420b39355..274206ec38 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -11297,11 +11297,7 @@ - - - - $dataLength $decodedData @@ -11309,11 +11305,9 @@ $indexLength $mroongaData - comment]]> - title]]> - mixed[][] + ]]> string diff --git a/src/StorageEngine.php b/src/StorageEngine.php index bafa85bf12..37b3345034 100644 --- a/src/StorageEngine.php +++ b/src/StorageEngine.php @@ -67,13 +67,13 @@ class StorageEngine public function __construct(string $engine) { $storageEngines = self::getStorageEngines(); - if (empty($storageEngines[$engine])) { + if (! array_key_exists($engine, $storageEngines)) { return; } $this->engine = $engine; $this->title = $storageEngines[$engine]['Engine']; - $this->comment = $storageEngines[$engine]['Comment'] ?? ''; + $this->comment = $storageEngines[$engine]['Comment']; $this->support = match ($storageEngines[$engine]['Support']) { 'DEFAULT' => self::SUPPORT_DEFAULT, 'YES' => self::SUPPORT_YES, @@ -85,7 +85,7 @@ class StorageEngine /** * Returns array of storage engines * - * @return mixed[][] array of storage engines + * @return array * * @staticvar array $storage_engines storage engines */ @@ -95,6 +95,7 @@ class StorageEngine if ($storageEngines == null) { $dbi = DatabaseInterface::getInstance(); + /** @var array $storageEngines */ $storageEngines = $dbi->fetchResult('SHOW STORAGE ENGINES', 'Engine'); if (! $dbi->isMariaDB() && $dbi->getVersion() >= 50708) { $disabled = (string) SessionCache::get( @@ -269,9 +270,7 @@ class StorageEngine return true; } - $storageEngines = self::getStorageEngines(); - - return isset($storageEngines[$engine]); + return array_key_exists($engine, self::getStorageEngines()); } /**