Skip to content

Commit 2866fe7

Browse files
Merge pull request #18932 from kamil-tekiela/Add-type-hint-to-getStorageEngines
Add better type hint to getStorageEngines()
2 parents 0061af6 + fe159c3 commit 2866fe7

3 files changed

Lines changed: 8 additions & 30 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14635,11 +14635,6 @@ parameters:
1463514635
count: 1
1463614636
path: src/StorageEngine.php
1463714637

14638-
-
14639-
message: "#^Cannot access offset 'Support' on mixed\\.$#"
14640-
count: 1
14641-
path: src/StorageEngine.php
14642-
1464314638
-
1464414639
message: "#^Cannot access offset 'desc' on mixed\\.$#"
1464514640
count: 1
@@ -14677,7 +14672,7 @@ parameters:
1467714672

1467814673
-
1467914674
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
14680-
count: 3
14675+
count: 2
1468114676
path: src/StorageEngine.php
1468214677

1468314678
-
@@ -14691,7 +14686,7 @@ parameters:
1469114686
path: src/StorageEngine.php
1469214687

1469314688
-
14694-
message: "#^Method PhpMyAdmin\\\\StorageEngine\\:\\:getStorageEngines\\(\\) should return array\\<array\\> but returns mixed\\.$#"
14689+
message: "#^Method PhpMyAdmin\\\\StorageEngine\\:\\:getStorageEngines\\(\\) should return array\\<string, array\\{Engine\\: string, Comment\\: string, Support\\: string\\}\\> but returns mixed\\.$#"
1469514690
count: 1
1469614691
path: src/StorageEngine.php
1469714692

@@ -14725,16 +14720,6 @@ parameters:
1472514720
count: 1
1472614721
path: src/StorageEngine.php
1472714722

14728-
-
14729-
message: "#^Property PhpMyAdmin\\\\StorageEngine\\:\\:\\$comment \\(string\\) does not accept mixed\\.$#"
14730-
count: 1
14731-
path: src/StorageEngine.php
14732-
14733-
-
14734-
message: "#^Property PhpMyAdmin\\\\StorageEngine\\:\\:\\$title \\(string\\) does not accept mixed\\.$#"
14735-
count: 1
14736-
path: src/StorageEngine.php
14737-
1473814723
-
1473914724
message: "#^Variable method call on \\$this\\(PhpMyAdmin\\\\StorageEngine\\)\\.$#"
1474014725
count: 1

psalm-baseline.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11128,23 +11128,17 @@
1112811128
<code><![CDATA[$mysqlVars[$row['Variable_name']]['title']]]></code>
1112911129
<code><![CDATA[$mysqlVars[$row['Variable_name']]['type']]]></code>
1113011130
<code><![CDATA[$mysqlVars[$row['Variable_name']]['value']]]></code>
11131-
<code><![CDATA[$storageEngines[$engine]['Support']]]></code>
1113211131
</MixedArrayAssignment>
11133-
<MixedArrayOffset>
11134-
<code><![CDATA[$engines[$details['Engine']]]]></code>
11135-
</MixedArrayOffset>
1113611132
<MixedAssignment>
1113711133
<code>$dataLength</code>
1113811134
<code>$decodedData</code>
1113911135
<code>$details</code>
1114011136
<code>$indexLength</code>
1114111137
<code>$mroongaData</code>
1114211138
<code><![CDATA[$mysqlVars[$row['Variable_name']]]]></code>
11143-
<code><![CDATA[$this->comment]]></code>
11144-
<code><![CDATA[$this->title]]></code>
1114511139
</MixedAssignment>
1114611140
<MixedInferredReturnType>
11147-
<code>mixed[][]</code>
11141+
<code><![CDATA[array<string, array{Engine: string, Comment: string, Support: string}>]]></code>
1114811142
<code>string</code>
1114911143
</MixedInferredReturnType>
1115011144
<MixedOperand>

src/StorageEngine.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class StorageEngine
6767
public function __construct(string $engine)
6868
{
6969
$storageEngines = self::getStorageEngines();
70-
if (empty($storageEngines[$engine])) {
70+
if (! array_key_exists($engine, $storageEngines)) {
7171
return;
7272
}
7373

7474
$this->engine = $engine;
7575
$this->title = $storageEngines[$engine]['Engine'];
76-
$this->comment = $storageEngines[$engine]['Comment'] ?? '';
76+
$this->comment = $storageEngines[$engine]['Comment'];
7777
$this->support = match ($storageEngines[$engine]['Support']) {
7878
'DEFAULT' => self::SUPPORT_DEFAULT,
7979
'YES' => self::SUPPORT_YES,
@@ -85,7 +85,7 @@ public function __construct(string $engine)
8585
/**
8686
* Returns array of storage engines
8787
*
88-
* @return mixed[][] array of storage engines
88+
* @return array<string, array{Engine: string, Comment: string, Support: string}>
8989
*
9090
* @staticvar array $storage_engines storage engines
9191
*/
@@ -95,6 +95,7 @@ public static function getStorageEngines(): array
9595

9696
if ($storageEngines == null) {
9797
$dbi = DatabaseInterface::getInstance();
98+
/** @var array<string, array{Engine: string, Comment: string, Support: string}> $storageEngines */
9899
$storageEngines = $dbi->fetchResult('SHOW STORAGE ENGINES', 'Engine');
99100
if (! $dbi->isMariaDB() && $dbi->getVersion() >= 50708) {
100101
$disabled = (string) SessionCache::get(
@@ -269,9 +270,7 @@ public static function isValid(string $engine): bool
269270
return true;
270271
}
271272

272-
$storageEngines = self::getStorageEngines();
273-
274-
return isset($storageEngines[$engine]);
273+
return array_key_exists($engine, self::getStorageEngines());
275274
}
276275

277276
/**

0 commit comments

Comments
 (0)