Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-04 01:23:13 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-04 01:23:13 +0300
commit2b0a3da81033822643b5723000faf6f96a360b6e (patch)
treea7c53e8c6fa556eb497208279e93a0d41e868109
parent0319d34ee60b2b30a0c1096743b10fccadce7340 (diff)
Fix some errors found by PHPStan in ZipExtensionTest class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r--libraries/classes/ZipExtension.php6
-rw-r--r--phpstan-baseline.neon17
-rw-r--r--psalm-baseline.xml15
-rw-r--r--test/classes/ZipExtensionTest.php29
4 files changed, 28 insertions, 39 deletions
diff --git a/libraries/classes/ZipExtension.php b/libraries/classes/ZipExtension.php
index d2e49b76df..1c6330d198 100644
--- a/libraries/classes/ZipExtension.php
+++ b/libraries/classes/ZipExtension.php
@@ -46,10 +46,10 @@ class ZipExtension
* @param string $file path to zip file
* @param string $specificEntry regular expression to match a file
*
- * @return array ($error_message, $file_data); $error_message
- * is empty if no error
+ * @return array<string, string>
+ * @psalm-return array{error: string, data: string}
*/
- public function getContents($file, $specificEntry = null)
+ public function getContents($file, $specificEntry = null): array
{
/**
* This function is used to "import" a SQL file which has been exported earlier
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 23e7698e45..0a7dd54ec2 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -8321,7 +8321,12 @@ parameters:
path: libraries/classes/ZipExtension.php
-
- message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) return type has no value type specified in iterable type array\\.$#"
+ message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) should return array\\{error\\: string, data\\: string\\} but returns array\\{error\\: '', data\\: string\\|false\\}\\.$#"
+ count: 1
+ path: libraries/classes/ZipExtension.php
+
+ -
+ message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:getContents\\(\\) should return array\\{error\\: string, data\\: string\\} but returns array\\{error\\: string, data\\: string\\|false\\}\\.$#"
count: 1
path: libraries/classes/ZipExtension.php
@@ -10325,13 +10330,3 @@ parameters:
count: 1
path: test/classes/VersionInformationTest.php
- -
- message: "#^Method PhpMyAdmin\\\\Tests\\\\ZipExtensionTest\\:\\:provideTestFindFile\\(\\) return type has no value type specified in iterable type array\\.$#"
- count: 1
- path: test/classes/ZipExtensionTest.php
-
- -
- message: "#^Method PhpMyAdmin\\\\Tests\\\\ZipExtensionTest\\:\\:provideTestGetContents\\(\\) return type has no value type specified in iterable type array\\.$#"
- count: 1
- path: test/classes/ZipExtensionTest.php
-
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 6121d61b2c..1fcdd687e6 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -6520,9 +6520,8 @@
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;handle</code>
</InvalidPropertyAssignmentValue>
- <MixedArgument occurrences="2">
+ <MixedArgument occurrences="1">
<code>$file['tmp_name']</code>
- <code>$result['error']</code>
</MixedArgument>
<MixedArrayAccess occurrences="5">
<code>$file['error']['multi_edit']</code>
@@ -6531,9 +6530,6 @@
<code>$file['tmp_name']['multi_edit']</code>
<code>$file['type']['multi_edit']</code>
</MixedArrayAccess>
- <MixedAssignment occurrences="1">
- <code>$this-&gt;content</code>
- </MixedAssignment>
<PossiblyInvalidArgument occurrences="1">
<code>$_FILES['fields_upload']</code>
</PossiblyInvalidArgument>
@@ -15353,9 +15349,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="test/classes/OpenDocumentTest.php">
- <MixedArgument occurrences="1">
- <code>$zipExtension-&gt;getContents($tmpFile, '/meta\.xml/')['data']</code>
- </MixedArgument>
<RedundantConditionGivenDocblockType occurrences="1">
<code>assertNotFalse</code>
</RedundantConditionGivenDocblockType>
@@ -16137,12 +16130,6 @@
<code>testGetLatestCompatibleVersionWithNewPHPVersion</code>
</PossiblyInvalidArgument>
</file>
- <file src="test/classes/ZipExtensionTest.php">
- <MixedInferredReturnType occurrences="2">
- <code>array</code>
- <code>array</code>
- </MixedInferredReturnType>
- </file>
<file src="test/selenium/Database/ProceduresTest.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
diff --git a/test/classes/ZipExtensionTest.php b/test/classes/ZipExtensionTest.php
index 1468c1db62..cbb1244006 100644
--- a/test/classes/ZipExtensionTest.php
+++ b/test/classes/ZipExtensionTest.php
@@ -29,13 +29,14 @@ class ZipExtensionTest extends AbstractTestCase
/**
* Test for getContents
*
- * @param string $file path to zip file
- * @param string|null $specific_entry regular expression to match a file
- * @param mixed $output expected output
+ * @param string $file path to zip file
+ * @param string|null $specific_entry regular expression to match a file
+ * @param array<string, string> $output expected output
+ * @psalm-param array{error: string, data: string} $output
*
* @dataProvider provideTestGetContents
*/
- public function testGetContents(string $file, ?string $specific_entry, $output): void
+ public function testGetContents(string $file, ?string $specific_entry, array $output): void
{
$this->assertEquals(
$this->zipExtension->getContents($file, $specific_entry),
@@ -44,9 +45,8 @@ class ZipExtensionTest extends AbstractTestCase
}
/**
- * Provider for testGetZipContents
- *
- * @return array
+ * @return array<string, array<int, array<string, string>|string|null>>
+ * @psalm-return array<string, array{string, string|null, array{error: string, data: string}}>
*/
public function provideTestGetContents(): array
{
@@ -81,9 +81,10 @@ class ZipExtensionTest extends AbstractTestCase
/**
* Test for findFile
*
- * @param string $file path to zip file
- * @param string $file_regexp regular expression for the file name to match
- * @param mixed $output expected output
+ * @param string $file path to zip file
+ * @param string $file_regexp regular expression for the file name to match
+ * @param string|bool $output expected output
+ * @psalm-param string|false $output
*
* @dataProvider provideTestFindFile
*/
@@ -98,7 +99,8 @@ class ZipExtensionTest extends AbstractTestCase
/**
* Provider for testFindFileFromZipArchive
*
- * @return array Test data
+ * @return array<int, array<int, string|bool>>
+ * @psalm-return array<int, array{string, string, string|false}>
*/
public function provideTestFindFile(): array
{
@@ -108,6 +110,11 @@ class ZipExtensionTest extends AbstractTestCase
'/test/',
'test.file',
],
+ [
+ './test/test_data/test.zip',
+ '/invalid/',
+ false,
+ ],
];
}