From 4ea2bcdf4b58281bd1faf1aadeaa9fe15976db94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 6 Dec 2019 10:01:25 -0300 Subject: [PATCH] Fix some PHPStan level 3 errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Dbi/DbiExtension.php | 32 +++++++++---------- libraries/classes/Engines/Pbxt.php | 2 +- .../classes/Plugins/Export/ExportOdt.php | 4 +-- .../classes/Plugins/Export/ExportSql.php | 8 ++--- libraries/classes/Properties/PropertyItem.php | 2 +- test/classes/Plugins/Export/ExportOdtTest.php | 18 +++++------ test/classes/Stubs/DbiDummy.php | 32 +++++++++---------- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/libraries/classes/Dbi/DbiExtension.php b/libraries/classes/Dbi/DbiExtension.php index 3d814cd62b..2c464cf57d 100644 --- a/libraries/classes/Dbi/DbiExtension.php +++ b/libraries/classes/Dbi/DbiExtension.php @@ -33,8 +33,8 @@ interface DbiExtension /** * selects given database * - * @param string $dbname database name to select - * @param resource $link connection object + * @param string $dbname database name to select + * @param object $link connection object * * @return boolean */ @@ -43,9 +43,9 @@ interface DbiExtension /** * runs a query and returns the result * - * @param string $query query to execute - * @param resource $link connection object - * @param int $options query options + * @param string $query query to execute + * @param object $link connection object + * @param int $options query options * * @return mixed result */ @@ -54,8 +54,8 @@ interface DbiExtension /** * Run the multi query and output the results * - * @param resource $link connection object - * @param string $query multi query statement to execute + * @param object $link connection object + * @param string $query multi query statement to execute * * @return array|bool */ @@ -110,7 +110,7 @@ interface DbiExtension /** * Check if there are any more query results from a multi query * - * @param resource $link the connection object + * @param object $link the connection object * * @return bool true or false */ @@ -119,7 +119,7 @@ interface DbiExtension /** * Prepare next result from multi_query * - * @param resource $link the connection object + * @param object $link the connection object * * @return bool true or false */ @@ -128,7 +128,7 @@ interface DbiExtension /** * Store the result returned from multi query * - * @param resource $link mysql link + * @param object $link mysql link * * @return mixed false when empty results / result set when not empty */ @@ -137,7 +137,7 @@ interface DbiExtension /** * Returns a string representing the type of connection used * - * @param resource $link mysql link + * @param object $link mysql link * * @return string type of connection used */ @@ -146,16 +146,16 @@ interface DbiExtension /** * Returns the version of the MySQL protocol used * - * @param resource $link mysql link + * @param object $link mysql link * - * @return integer version of the MySQL protocol used + * @return int|string version of the MySQL protocol used */ public function getProtoInfo($link); /** * returns a string that represents the client library version * - * @param resource $link mysql link + * @param object $link mysql link * * @return string MySQL client library version */ @@ -164,7 +164,7 @@ interface DbiExtension /** * returns last error message or false if no errors occurred * - * @param resource $link connection link + * @param object $link connection link * * @return string|bool error or false */ @@ -182,7 +182,7 @@ interface DbiExtension /** * returns the number of rows affected by last query * - * @param resource $link the connection object + * @param object $link the connection object * * @return int */ diff --git a/libraries/classes/Engines/Pbxt.php b/libraries/classes/Engines/Pbxt.php index 271887c9a1..ae84af7cbf 100644 --- a/libraries/classes/Engines/Pbxt.php +++ b/libraries/classes/Engines/Pbxt.php @@ -139,7 +139,7 @@ class Pbxt extends StorageEngine * returns the pbxt engine specific handling for * PMA_ENGINE_DETAILS_TYPE_SIZE variables. * - * @param string $formatted_size the size expression (for example 8MB) + * @param int|string $formatted_size the size expression (for example 8MB) * * @return array the formatted value and its unit */ diff --git a/libraries/classes/Plugins/Export/ExportOdt.php b/libraries/classes/Plugins/Export/ExportOdt.php index 51e83ee628..8810c90fa7 100644 --- a/libraries/classes/Plugins/Export/ExportOdt.php +++ b/libraries/classes/Plugins/Export/ExportOdt.php @@ -596,7 +596,7 @@ class ExportOdt extends ExportPlugin * @param string $table table name * @param array $aliases Aliases of db/table/columns * - * @return bool true + * @return string */ protected function getTriggers($db, $table, array $aliases = []) { @@ -651,7 +651,7 @@ class ExportOdt extends ExportPlugin $GLOBALS['odt_buffer'] .= ''; - return true; + return $GLOBALS['odt_buffer']; } /** diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index 4fe2aee404..979ad7ac44 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -1054,7 +1054,7 @@ class ExportSql extends ExportPlugin $r &= $this->_exportMetadata($db, $tables, $metadataTypes); } - return $r; + return (bool) $r; } /** @@ -2757,7 +2757,7 @@ class ExportSql extends ExportPlugin ) { $statement->name->database = $new_database; $statement->name->table = $new_table; - $statement->name->expr = null; // Force rebuild. + $statement->name->expr = ''; // Force rebuild. $flag = true; } @@ -2788,7 +2788,7 @@ class ExportSql extends ExportPlugin if (! empty($aliases[$old_database]['tables'][$ref_table]['alias'])) { $field->references->table->table = $aliases[$old_database]['tables'][$ref_table]['alias']; - $field->references->table->expr = null; + $field->references->table->expr = ''; $flag = true; } // Replacing column names. @@ -2818,7 +2818,7 @@ class ExportSql extends ExportPlugin if (! empty($aliases[$old_database]['tables'][$old_table]['alias'])) { $statement->table->table = $aliases[$old_database]['tables'][$old_table]['alias']; - $statement->table->expr = null; // Force rebuild. + $statement->table->expr = ''; // Force rebuild. $flag = true; } } diff --git a/libraries/classes/Properties/PropertyItem.php b/libraries/classes/Properties/PropertyItem.php index 1137c8ab58..55a71ad398 100644 --- a/libraries/classes/Properties/PropertyItem.php +++ b/libraries/classes/Properties/PropertyItem.php @@ -38,7 +38,7 @@ abstract class PropertyItem * the addProperty() or removeProperty() methods, which are not available * for simple PhpMyAdmin\Properties\Options\OptionsPropertyOneItem subclasses. * - * @return null + * @return null|object */ public function getGroup() { diff --git a/test/classes/Plugins/Export/ExportOdtTest.php b/test/classes/Plugins/Export/ExportOdtTest.php index 722901bffd..878eaa0e4b 100644 --- a/test/classes/Plugins/Export/ExportOdtTest.php +++ b/test/classes/Plugins/Export/ExportOdtTest.php @@ -917,33 +917,31 @@ class ExportOdtTest extends PmaTestCase $method->setAccessible(true); $result = $method->invoke($this->object, 'database', 'taassertTrue( + $this->assertSame($result, $GLOBALS['odt_buffer']); + + $this->assertStringContainsString( + '', $result ); - $this->assertStringContainsString( - '', - $GLOBALS['odt_buffer'] - ); - $this->assertStringContainsString( 'tna"me', - $GLOBALS['odt_buffer'] + $result ); $this->assertStringContainsString( 'ac>t', - $GLOBALS['odt_buffer'] + $result ); $this->assertStringContainsString( 'manip&', - $GLOBALS['odt_buffer'] + $result ); $this->assertStringContainsString( 'def', - $GLOBALS['odt_buffer'] + $result ); } diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index f0946b4bab..67fa6d80bd 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -65,8 +65,8 @@ class DbiDummy implements DbiExtension /** * selects given database * - * @param string $dbname name of db to select - * @param resource $link mysql link resource + * @param string $dbname name of db to select + * @param object $link mysql link resource * * @return bool */ @@ -80,9 +80,9 @@ class DbiDummy implements DbiExtension /** * runs a query and returns the result * - * @param string $query query to run - * @param resource $link mysql link resource - * @param int $options query options + * @param string $query query to run + * @param object $link mysql link resource + * @param int $options query options * * @return mixed */ @@ -121,8 +121,8 @@ class DbiDummy implements DbiExtension /** * Run the multi query and output the results * - * @param resource $link connection object - * @param string $query multi query statement to execute + * @param object $link connection object + * @param string $query multi query statement to execute * * @return array|bool */ @@ -243,7 +243,7 @@ class DbiDummy implements DbiExtension /** * Check if there are any more query results from a multi query * - * @param resource $link the connection object + * @param object $link the connection object * * @return bool false */ @@ -255,7 +255,7 @@ class DbiDummy implements DbiExtension /** * Prepare next result from multi_query * - * @param resource $link the connection object + * @param object $link the connection object * * @return boolean false */ @@ -267,7 +267,7 @@ class DbiDummy implements DbiExtension /** * Store the result returned from multi query * - * @param resource $link the connection object + * @param object $link the connection object * * @return mixed false when empty results / result set when not empty */ @@ -279,7 +279,7 @@ class DbiDummy implements DbiExtension /** * Returns a string representing the type of connection used * - * @param resource $link mysql link + * @param object $link mysql link * * @return string type of connection used */ @@ -291,7 +291,7 @@ class DbiDummy implements DbiExtension /** * Returns the version of the MySQL protocol used * - * @param resource $link mysql link + * @param object $link mysql link * * @return integer version of the MySQL protocol used */ @@ -303,7 +303,7 @@ class DbiDummy implements DbiExtension /** * returns a string that represents the client library version * - * @param resource $link connection link + * @param object $link connection link * * @return string MySQL client library version */ @@ -315,7 +315,7 @@ class DbiDummy implements DbiExtension /** * returns last error message or false if no errors occurred * - * @param resource $link connection link + * @param object $link connection link * * @return string|bool error or false */ @@ -345,8 +345,8 @@ class DbiDummy implements DbiExtension /** * returns the number of rows affected by last query * - * @param resource $link the mysql object - * @param bool $get_from_cache whether to retrieve from cache + * @param object $link the mysql object + * @param bool $get_from_cache whether to retrieve from cache * * @return string|int */