Skip to content

Commit 2b0a3da

Browse files
committed
Fix some errors found by PHPStan in ZipExtensionTest class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 0319d34 commit 2b0a3da

4 files changed

Lines changed: 28 additions & 39 deletions

File tree

‎libraries/classes/ZipExtension.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public function __construct(?ZipArchive $zip = null)
4646
* @param string $file path to zip file
4747
* @param string $specificEntry regular expression to match a file
4848
*
49-
* @return array ($error_message, $file_data); $error_message
50-
* is empty if no error
49+
* @return array<string, string>
50+
* @psalm-return array{error: string, data: string}
5151
*/
52-
public function getContents($file, $specificEntry = null)
52+
public function getContents($file, $specificEntry = null): array
5353
{
5454
/**
5555
* This function is used to "import" a SQL file which has been exported earlier

‎phpstan-baseline.neon‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8321,7 +8321,12 @@ parameters:
83218321
path: libraries/classes/ZipExtension.php
83228322

83238323
-
8324-
message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) return type has no value type specified in iterable type array\\.$#"
8324+
message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) should return array\\{error\\: string, data\\: string\\} but returns array\\{error\\: '', data\\: string\\|false\\}\\.$#"
8325+
count: 1
8326+
path: libraries/classes/ZipExtension.php
8327+
8328+
-
8329+
message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) should return array\\{error\\: string, data\\: string\\} but returns array\\{error\\: string, data\\: string\\|false\\}\\.$#"
83258330
count: 1
83268331
path: libraries/classes/ZipExtension.php
83278332

@@ -10325,13 +10330,3 @@ parameters:
1032510330
count: 1
1032610331
path: test/classes/VersionInformationTest.php
1032710332

10328-
-
10329-
message: "#^Method PhpMyAdmin\\\\Tests\\\\ZipExtensionTest\\:\\:provideTestFindFile\\(\\) return type has no value type specified in iterable type array\\.$#"
10330-
count: 1
10331-
path: test/classes/ZipExtensionTest.php
10332-
10333-
-
10334-
message: "#^Method PhpMyAdmin\\\\Tests\\\\ZipExtensionTest\\:\\:provideTestGetContents\\(\\) return type has no value type specified in iterable type array\\.$#"
10335-
count: 1
10336-
path: test/classes/ZipExtensionTest.php
10337-

‎psalm-baseline.xml‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6520,9 +6520,8 @@
65206520
<InvalidPropertyAssignmentValue occurrences="1">
65216521
<code>$this-&gt;handle</code>
65226522
</InvalidPropertyAssignmentValue>
6523-
<MixedArgument occurrences="2">
6523+
<MixedArgument occurrences="1">
65246524
<code>$file['tmp_name']</code>
6525-
<code>$result['error']</code>
65266525
</MixedArgument>
65276526
<MixedArrayAccess occurrences="5">
65286527
<code>$file['error']['multi_edit']</code>
@@ -6531,9 +6530,6 @@
65316530
<code>$file['tmp_name']['multi_edit']</code>
65326531
<code>$file['type']['multi_edit']</code>
65336532
</MixedArrayAccess>
6534-
<MixedAssignment occurrences="1">
6535-
<code>$this-&gt;content</code>
6536-
</MixedAssignment>
65376533
<PossiblyInvalidArgument occurrences="1">
65386534
<code>$_FILES['fields_upload']</code>
65396535
</PossiblyInvalidArgument>
@@ -15353,9 +15349,6 @@
1535315349
</RedundantConditionGivenDocblockType>
1535415350
</file>
1535515351
<file src="test/classes/OpenDocumentTest.php">
15356-
<MixedArgument occurrences="1">
15357-
<code>$zipExtension-&gt;getContents($tmpFile, '/meta\.xml/')['data']</code>
15358-
</MixedArgument>
1535915352
<RedundantConditionGivenDocblockType occurrences="1">
1536015353
<code>assertNotFalse</code>
1536115354
</RedundantConditionGivenDocblockType>
@@ -16137,12 +16130,6 @@
1613716130
<code>testGetLatestCompatibleVersionWithNewPHPVersion</code>
1613816131
</PossiblyInvalidArgument>
1613916132
</file>
16140-
<file src="test/classes/ZipExtensionTest.php">
16141-
<MixedInferredReturnType occurrences="2">
16142-
<code>array</code>
16143-
<code>array</code>
16144-
</MixedInferredReturnType>
16145-
</file>
1614616133
<file src="test/selenium/Database/ProceduresTest.php">
1614716134
<MixedInferredReturnType occurrences="1">
1614816135
<code>string</code>

‎test/classes/ZipExtensionTest.php‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ protected function setUp(): void
2929
/**
3030
* Test for getContents
3131
*
32-
* @param string $file path to zip file
33-
* @param string|null $specific_entry regular expression to match a file
34-
* @param mixed $output expected output
32+
* @param string $file path to zip file
33+
* @param string|null $specific_entry regular expression to match a file
34+
* @param array<string, string> $output expected output
35+
* @psalm-param array{error: string, data: string} $output
3536
*
3637
* @dataProvider provideTestGetContents
3738
*/
38-
public function testGetContents(string $file, ?string $specific_entry, $output): void
39+
public function testGetContents(string $file, ?string $specific_entry, array $output): void
3940
{
4041
$this->assertEquals(
4142
$this->zipExtension->getContents($file, $specific_entry),
@@ -44,9 +45,8 @@ public function testGetContents(string $file, ?string $specific_entry, $output):
4445
}
4546

4647
/**
47-
* Provider for testGetZipContents
48-
*
49-
* @return array
48+
* @return array<string, array<int, array<string, string>|string|null>>
49+
* @psalm-return array<string, array{string, string|null, array{error: string, data: string}}>
5050
*/
5151
public function provideTestGetContents(): array
5252
{
@@ -81,9 +81,10 @@ public function provideTestGetContents(): array
8181
/**
8282
* Test for findFile
8383
*
84-
* @param string $file path to zip file
85-
* @param string $file_regexp regular expression for the file name to match
86-
* @param mixed $output expected output
84+
* @param string $file path to zip file
85+
* @param string $file_regexp regular expression for the file name to match
86+
* @param string|bool $output expected output
87+
* @psalm-param string|false $output
8788
*
8889
* @dataProvider provideTestFindFile
8990
*/
@@ -98,7 +99,8 @@ public function testFindFile(string $file, string $file_regexp, $output): void
9899
/**
99100
* Provider for testFindFileFromZipArchive
100101
*
101-
* @return array Test data
102+
* @return array<int, array<int, string|bool>>
103+
* @psalm-return array<int, array{string, string, string|false}>
102104
*/
103105
public function provideTestFindFile(): array
104106
{
@@ -108,6 +110,11 @@ public function provideTestFindFile(): array
108110
'/test/',
109111
'test.file',
110112
],
113+
[
114+
'./test/test_data/test.zip',
115+
'/invalid/',
116+
false,
117+
],
111118
];
112119
}
113120

0 commit comments

Comments
 (0)