Skip to content

Commit

Permalink
Fix some PHPStan errors
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Aug 23, 2020
1 parent 7966f5b commit ccbcc08
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 106 deletions.
4 changes: 2 additions & 2 deletions libraries/classes/Advisor.php
Expand Up @@ -400,7 +400,7 @@ public function runRules(): bool
*/
public static function escapePercent(string $str): string
{
return preg_replace('/%( |,|\.|$|\(|\)|<|>)/', '%%\1', $str);
return (string) preg_replace('/%( |,|\.|$|\(|\)|<|>)/', '%%\1', $str);
}

/**
Expand Down Expand Up @@ -751,6 +751,6 @@ public static function timespanFormat(int $seconds): string
*/
public static function formatByteDown($value, int $limes = 6, int $comma = 0): string
{
return implode(' ', Util::formatByteDown($value, $limes, $comma));
return implode(' ', (array) Util::formatByteDown($value, $limes, $comma));
}
}
4 changes: 2 additions & 2 deletions libraries/classes/Bookmark.php
Expand Up @@ -180,7 +180,7 @@ public function getVariableCount(): int
public function applyVariables(array $variables): string
{
// remove comments that encloses a variable placeholder
$query = preg_replace(
$query = (string) preg_replace(
'|/\*(.*\[VARIABLE[0-9]*\].*)\*/|imsU',
'${1}',
$this->query
Expand Down Expand Up @@ -295,7 +295,7 @@ protected static function createFromRow(
*
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $user Current user
* @param string|bool $db the current database name or false
* @param string|false $db the current database name or false
*
* @return Bookmark[] the bookmarks list
*
Expand Down
85 changes: 0 additions & 85 deletions phpstan-baseline.neon
@@ -1,30 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Method PhpMyAdmin\\\\Advisor\\:\\:escapePercent\\(\\) should return string but returns string\\|null\\.$#"
count: 1
path: libraries/classes/Advisor.php

-
message: "#^Parameter \\#2 \\$pieces of function implode expects array, array\\|null given\\.$#"
count: 1
path: libraries/classes/Advisor.php

-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
count: 1
path: libraries/classes/Bookmark.php

-
message: "#^Method PhpMyAdmin\\\\Bookmark\\:\\:applyVariables\\(\\) should return string but returns string\\|null\\.$#"
count: 1
path: libraries/classes/Bookmark.php

-
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:escapeString\\(\\) expects string, string\\|true given\\.$#"
count: 1
path: libraries/classes/Bookmark.php

-
message: "#^Parameter \\#1 \\$message of static method PhpMyAdmin\\\\Message\\:\\:rawError\\(\\) expects string, bool\\|string given\\.$#"
count: 2
Expand Down Expand Up @@ -3030,71 +3005,11 @@ parameters:
count: 1
path: test/classes/TrackingTest.php

-
message: "#^Offset 0 does not exist on array\\|null\\.$#"
count: 1
path: test/classes/UtilTest.php

-
message: "#^Parameter \\#2 \\$newvalue of function ini_set expects string, string\\|false given\\.$#"
count: 1
path: test/classes/UtilTest.php

-
message: "#^Cannot access property \\$version on stdClass\\|null\\.$#"
count: 1
path: test/classes/VersionInformationTest.php

-
message: "#^Cannot access property \\$date on stdClass\\|null\\.$#"
count: 1
path: test/classes/VersionInformationTest.php

-
message: "#^Offset 'version' does not exist on array\\|null\\.$#"
count: 3
path: test/classes/VersionInformationTest.php

-
message: "#^Parameter \\#1 \\$filename of function fopen expects string, string\\|false given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#2 \\$str of function fwrite expects string, bool\\|string given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#1 \\$source of method ZipArchive\\:\\:open\\(\\) expects string, string\\|false given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#1 \\$filename of function unlink expects string, string\\|false given\\.$#"
count: 2
path: test/classes/ZipExtensionTest.php

-
message: "#^Parameter \\#1 \\$element of method PhpMyAdmin\\\\Tests\\\\Selenium\\\\TestBase\\:\\:moveto\\(\\) expects Facebook\\\\WebDriver\\\\Remote\\\\RemoteWebElement, Facebook\\\\WebDriver\\\\WebDriverElement given\\.$#"
count: 1
path: test/selenium/CreateRemoveUserTest.php

-
message: "#^Parameter \\#1 \\$str of function trim expects string, string\\|null given\\.$#"
count: 1
path: test/selenium/Database/QueryByExampleTest.php

-
message: "#^Parameter \\#1 \\$element of method PhpMyAdmin\\\\Tests\\\\Selenium\\\\TestBase\\:\\:moveto\\(\\) expects Facebook\\\\WebDriver\\\\Remote\\\\RemoteWebElement, Facebook\\\\WebDriver\\\\WebDriverElement given\\.$#"
count: 2
Expand Down
14 changes: 5 additions & 9 deletions psalm-baseline.xml
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.14.1@9822043ca46d6682b76097bfa97d7c450eef9e90">
<files psalm-version="3.14.2@3538fe1955d47f6ee926c0769d71af6db08aa488">
<file src="libraries/classes/Advisor.php">
<PossiblyNullArgument occurrences="1">
<code>Util::formatByteDown($value, $limes, $comma)</code>
</PossiblyNullArgument>
</file>
<file src="libraries/classes/Bookmark.php">
<PossiblyInvalidArgument occurrences="1">
<code>$db</code>
</PossiblyInvalidArgument>
<InvalidArrayOffset occurrences="2">
<code>$ruleSyntax[$ruleLine++]</code>
<code>$ruleSyntax[$ruleLine]</code>
</InvalidArrayOffset>
</file>
<file src="libraries/classes/CentralColumns.php">
<InvalidScalarArgument occurrences="1">
Expand Down
3 changes: 2 additions & 1 deletion test/classes/UtilTest.php
Expand Up @@ -1060,6 +1060,7 @@ public function providerIsForeignKeySupported(): array
public function testFormatByteDown(float $a, int $b, int $c, array $e): void
{
$result = Util::formatByteDown($a, $b, $c);
$this->assertIsArray($result);
$result[0] = trim($result[0]);
$this->assertSame($e, $result);
}
Expand Down Expand Up @@ -1193,7 +1194,7 @@ public function testFormatNumber(float $a, int $b, int $c, string $d): void
$this->assertFormatNumber($a, $b, $c, $d);

// Test with various precisions
$old_precision = ini_get('precision');
$old_precision = (string) ini_get('precision');
try {
ini_set('precision', '20');
$this->assertFormatNumber($a, $b, $c, $d);
Expand Down
13 changes: 7 additions & 6 deletions test/classes/VersionInformationTest.php
Expand Up @@ -64,6 +64,7 @@ public function testGetLatestVersion(): void
$GLOBALS['cfg']['VersionCheck'] = true;
$versionInformation = new VersionInformation();
$version = $versionInformation->getLatestVersion();
$this->assertIsObject($version);
$this->assertNotEmpty($version->version);
$this->assertNotEmpty($version->date);
}
Expand Down Expand Up @@ -198,8 +199,8 @@ public function testGetLatestCompatibleVersionWithSingleServer(): void
->with('MySQL', '>=5.5')
->will($this->returnValue(true));

$compatible = $mockVersionInfo
->getLatestCompatibleVersion($this->releases);
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.4.14.1', $compatible['version']);
}

Expand Down Expand Up @@ -227,8 +228,8 @@ public function testGetLatestCompatibleVersionWithMultipleServers(): void
->with('PHP', '<7.1')
->will($this->returnValue(true));

$compatible = $mockVersionInfo
->getLatestCompatibleVersion($this->releases);
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.4.14.1', $compatible['version']);
}

Expand Down Expand Up @@ -266,8 +267,8 @@ public function testGetLatestCompatibleVersionWithOldPHPVersion(): void
->with('PHP', '<5.3')
->will($this->returnValue(true));

$compatible = $mockVersionInfo
->getLatestCompatibleVersion($this->releases);
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.0.10.10', $compatible['version']);
}

Expand Down
6 changes: 6 additions & 0 deletions test/classes/ZipExtensionTest.php
Expand Up @@ -146,9 +146,12 @@ public function testCreateSingleFile(): void
{
$file = $this->zipExtension->createFile('Test content', 'test.txt');
$this->assertNotEmpty($file);
$this->assertIsString($file);

$tmp = tempnam('./', 'zip-test');
$this->assertNotFalse($tmp);
$handle = fopen($tmp, 'w');
$this->assertNotFalse($handle);
fwrite($handle, $file);
fclose($handle);

Expand Down Expand Up @@ -195,9 +198,12 @@ public function testCreateMultiFile(): void
]
);
$this->assertNotEmpty($file);
$this->assertIsString($file);

$tmp = tempnam('./', 'zip-test');
$this->assertNotFalse($tmp);
$handle = fopen($tmp, 'w');
$this->assertNotFalse($handle);
fwrite($handle, $file);
fclose($handle);

Expand Down
2 changes: 1 addition & 1 deletion test/selenium/Database/QueryByExampleTest.php
Expand Up @@ -113,7 +113,7 @@ public function testQueryByExample(): void
. "\nFROM `test_table`"
. "\nWHERE ((`test_table`.`id` > 1) AND (`test_table`.`val` < 6))"
. "\nORDER BY `test_table`.`val` ASC, `test_table`.`id` DESC";
$actual = trim($this->waitForElement('id', 'textSqlquery')->getAttribute('value'));
$actual = trim((string) $this->waitForElement('id', 'textSqlquery')->getAttribute('value'));

/* Compare generated query */
$this->assertEquals(
Expand Down

0 comments on commit ccbcc08

Please sign in to comment.