From cd1b8a9b770b9e8e4589e5de808ead4ab781595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 22 May 2021 15:14:24 -0300 Subject: [PATCH] Fix some errors found by PHPStan and Psalm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../classes/Controllers/HomeController.php | 2 +- .../Server/PrivilegesController.php | 3 +- libraries/classes/DatabaseInterface.php | 2 +- libraries/classes/Dbal/DbalInterface.php | 2 +- libraries/classes/Dbal/DbiExtension.php | 14 ++--- libraries/classes/Dbal/DbiMysqli.php | 56 +++++++++-------- libraries/classes/Error.php | 2 +- libraries/classes/Footer.php | 14 ++--- libraries/classes/Linter.php | 2 +- .../classes/Plugins/Export/ExportCsv.php | 2 +- .../classes/Plugins/Export/ExportHtmlword.php | 2 +- .../classes/Plugins/Export/ExportOds.php | 2 +- .../classes/Plugins/Export/ExportOdt.php | 2 +- .../classes/Plugins/Export/ExportSql.php | 2 +- .../classes/Plugins/Export/ExportTexytext.php | 2 +- .../classes/Plugins/Export/ExportXml.php | 2 +- .../classes/Plugins/Export/ExportYaml.php | 3 +- libraries/classes/Sanitize.php | 4 +- libraries/classes/Server/Privileges.php | 2 +- libraries/classes/Sql.php | 7 ++- phpstan-baseline.neon | 60 ------------------- phpstan.neon.dist | 1 - psalm-baseline.xml | 48 +++------------ test/classes/FooterTest.php | 14 ++--- .../classes/Plugins/Export/ExportYamlTest.php | 3 + test/classes/Stubs/DbiDummy.php | 18 +++--- 26 files changed, 90 insertions(+), 181 deletions(-) diff --git a/libraries/classes/Controllers/HomeController.php b/libraries/classes/Controllers/HomeController.php index 02d47cd24948..ae3b796d9927 100644 --- a/libraries/classes/Controllers/HomeController.php +++ b/libraries/classes/Controllers/HomeController.php @@ -146,7 +146,7 @@ public function index(): void } $databaseServer = []; - if ($server > 0 && $cfg['ShowServerInfo']) { + if ($server > 0) { $hostInfo = ''; if (! empty($cfg['Server']['verbose'])) { $hostInfo .= $cfg['Server']['verbose']; diff --git a/libraries/classes/Controllers/Server/PrivilegesController.php b/libraries/classes/Controllers/Server/PrivilegesController.php index b68dab5ee2de..eb6186f7ed5a 100644 --- a/libraries/classes/Controllers/Server/PrivilegesController.php +++ b/libraries/classes/Controllers/Server/PrivilegesController.php @@ -334,8 +334,7 @@ public function index(): void && empty($_REQUEST['ajax_page_request']) && ! isset($_GET['export']) && (! isset($_POST['submit_mult']) || $_POST['submit_mult'] !== 'export') - && ((! isset($_GET['initial']) || $_GET['initial'] === null - || $_GET['initial'] === '') + && ((! isset($_GET['initial']) || $_GET['initial'] === '') || (isset($_POST['delete']) && $_POST['delete'] === __('Go'))) && ! isset($_GET['showall']) ) { diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index b303ff5c2de4..72e3c1fc8ab6 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -2165,7 +2165,7 @@ public function getError($link = self::CONNECT_USER) /** * returns the number of rows returned by last query * - * @param object $result result set identifier + * @param object|bool $result result set identifier * * @return string|int */ diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index eddc5a0e10b0..246f6837da63 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -625,7 +625,7 @@ public function getError($link = DatabaseInterface::CONNECT_USER); /** * returns the number of rows returned by last query * - * @param object $result result set identifier + * @param object|bool $result result set identifier * * @return string|int */ diff --git a/libraries/classes/Dbal/DbiExtension.php b/libraries/classes/Dbal/DbiExtension.php index cf325dde2dc4..2915438e896e 100644 --- a/libraries/classes/Dbal/DbiExtension.php +++ b/libraries/classes/Dbal/DbiExtension.php @@ -32,12 +32,12 @@ public function connect( /** * selects given database * - * @param string|DatabaseName $dbname database name to select - * @param object $link connection object + * @param string|DatabaseName $databaseName database name to select + * @param object $link connection object * * @return bool */ - public function selectDb($dbname, $link); + public function selectDb($databaseName, $link); /** * runs a query and returns the result @@ -166,7 +166,7 @@ public function getError($link); /** * returns the number of rows returned by last query * - * @param object $result result set identifier + * @param object|bool $result result set identifier * * @return string|int */ @@ -222,12 +222,12 @@ public function fieldName($result, $i); /** * returns properly escaped string for use in MySQL queries * - * @param mixed $link database link - * @param string $str string to be escaped + * @param mixed $link database link + * @param string $string string to be escaped * * @return string a MySQL escaped string */ - public function escapeString($link, $str); + public function escapeString($link, $string); /** * Prepare an SQL statement for execution. diff --git a/libraries/classes/Dbal/DbiMysqli.php b/libraries/classes/Dbal/DbiMysqli.php index 0c40cc31df47..2132b83c13bb 100644 --- a/libraries/classes/Dbal/DbiMysqli.php +++ b/libraries/classes/Dbal/DbiMysqli.php @@ -18,6 +18,8 @@ use function defined; use function is_array; use function is_bool; +use function mysqli_connect_errno; +use function mysqli_connect_error; use function mysqli_init; use function mysqli_report; use function stripos; @@ -62,6 +64,10 @@ public function connect($user, $password, array $server) $mysqli = mysqli_init(); + if ($mysqli === false) { + return false; + } + $client_flags = 0; /* Optionally compress connection */ @@ -118,7 +124,7 @@ public function connect($user, $password, array $server) $client_flags ); - if ($return_value === false || $return_value === null) { + if ($return_value === false) { /* * Switch to SSL if server asked us to do so, unfortunately * there are more ways MySQL server can tell this: @@ -160,25 +166,25 @@ public function connect($user, $password, array $server) * selects given database * * @param string|DatabaseName $databaseName database name to select - * @param mysqli $mysqli the mysqli object + * @param mysqli $link the mysqli object * * @return bool */ - public function selectDb($databaseName, $mysqli) + public function selectDb($databaseName, $link) { - return $mysqli->select_db((string) $databaseName); + return $link->select_db((string) $databaseName); } /** * runs a query and returns the result * * @param string $query query to execute - * @param mysqli $mysqli mysqli object + * @param mysqli $link mysqli object * @param int $options query options * * @return mysqli_result|bool */ - public function realQuery($query, $mysqli, $options) + public function realQuery($query, $link, $options) { if ($options == ($options | DatabaseInterface::QUERY_STORE)) { $method = MYSQLI_STORE_RESULT; @@ -188,20 +194,20 @@ public function realQuery($query, $mysqli, $options) $method = 0; } - return $mysqli->query($query, $method); + return $link->query($query, $method); } /** * Run the multi query and output the results * - * @param mysqli $mysqli mysqli object - * @param string $query multi query statement to execute + * @param mysqli $link mysqli object + * @param string $query multi query statement to execute * * @return bool */ - public function realMultiQuery($mysqli, $query) + public function realMultiQuery($link, $query) { - return $mysqli->multi_query($query); + return $link->multi_query($query); } /** @@ -350,7 +356,7 @@ public function getClientInfo($mysqli) /** * returns last error message or false if no errors occurred * - * @param mysqli $mysqli mysql link + * @param mysqli|false|null $mysqli mysql link * * @return string|bool error or false */ @@ -362,11 +368,11 @@ public function getError($mysqli) $error_number = $mysqli->errno; $error_message = $mysqli->error; } else { - $error_number = $mysqli->connect_errno; - $error_message = $mysqli->connect_error; + $error_number = mysqli_connect_errno(); + $error_message = (string) mysqli_connect_error(); } - if ($error_number == 0) { + if ($error_number === 0 || $error_message === '') { return false; } @@ -380,7 +386,7 @@ public function getError($mysqli) /** * returns the number of rows returned by last query * - * @param mysqli_result $result result set identifier + * @param mysqli_result|bool $result result set identifier * * @return string|int */ @@ -457,7 +463,7 @@ public function fieldLen($result, $i) return false; } - /** @var stdClass $fieldDefinition */ + /** @var stdClass|false $fieldDefinition */ $fieldDefinition = $result->fetch_field_direct($i); if ($fieldDefinition !== false) { return $fieldDefinition->length; @@ -480,7 +486,7 @@ public function fieldName($result, $i) return ''; } - /** @var stdClass $fieldDefinition */ + /** @var stdClass|false $fieldDefinition */ $fieldDefinition = $result->fetch_field_direct($i); if ($fieldDefinition !== false) { return $fieldDefinition->name; @@ -492,26 +498,26 @@ public function fieldName($result, $i) /** * returns properly escaped string for use in MySQL queries * - * @param mysqli $mysqli database link + * @param mysqli $link database link * @param string $string string to be escaped * * @return string a MySQL escaped string */ - public function escapeString($mysqli, $string) + public function escapeString($link, $string) { - return $mysqli->real_escape_string($string); + return $link->real_escape_string($string); } /** * Prepare an SQL statement for execution. * - * @param mysqli $mysqli database link - * @param string $query The query, as a string. + * @param mysqli $link database link + * @param string $query The query, as a string. * * @return mysqli_stmt|false A statement object or false. */ - public function prepare($mysqli, string $query) + public function prepare($link, string $query) { - return $mysqli->prepare($query); + return $link->prepare($query); } } diff --git a/libraries/classes/Error.php b/libraries/classes/Error.php index 2ed3bbc305fd..303735e0c54a 100644 --- a/libraries/classes/Error.php +++ b/libraries/classes/Error.php @@ -427,7 +427,7 @@ public static function getFunctionCall(array $step, string $separator): string * if $function is one of include/require * the $arg is converted to a relative path * - * @param string $arg argument to process + * @param mixed $arg argument to process * @param string $function function name */ public static function getArg($arg, string $function): string diff --git a/libraries/classes/Footer.php b/libraries/classes/Footer.php index 37766430d29e..478dd8125f95 100644 --- a/libraries/classes/Footer.php +++ b/libraries/classes/Footer.php @@ -92,11 +92,10 @@ private function getGitRevisionInfo(): array /** * Remove recursions and iterator objects from an object * - * @param object|array $object Object to clean - * @param array $stack Stack used to keep track of recursion, - * need not be passed for the first time + * @param mixed $object Object to clean + * @param array $stack Stack used to keep track of recursion, need not be passed for the first time * - * @return object Reference passed object + * @return mixed Reference passed object */ private static function removeRecursion(&$object, array $stack = []) { @@ -105,8 +104,9 @@ private static function removeRecursion(&$object, array $stack = []) $object = '***ITERATOR***'; } elseif (! in_array($object, $stack, true)) { $stack[] = $object; - foreach ($object as &$subobject) { - self::removeRecursion($subobject, $stack); + // @phpstan-ignore-next-line + foreach ($object as &$subObject) { + self::removeRecursion($subObject, $stack); } } else { $object = '***RECURSION***'; @@ -130,7 +130,7 @@ public function getDebugMessage(): string // Remove recursions and iterators from $_SESSION['debug'] self::removeRecursion($_SESSION['debug']); - $retval = json_encode($_SESSION['debug']); + $retval = (string) json_encode($_SESSION['debug']); $_SESSION['debug'] = []; return json_last_error() ? '\'false\'' : $retval; diff --git a/libraries/classes/Linter.php b/libraries/classes/Linter.php index b8e6b0d9632b..a165ab817e25 100644 --- a/libraries/classes/Linter.php +++ b/libraries/classes/Linter.php @@ -26,7 +26,7 @@ class Linter /** * Gets the starting position of each line. * - * @param string $str String to be analyzed. + * @param string|UtfString $str String to be analyzed. * * @return array */ diff --git a/libraries/classes/Plugins/Export/ExportCsv.php b/libraries/classes/Plugins/Export/ExportCsv.php index 1bb65656461a..680476ccb4f0 100644 --- a/libraries/classes/Plugins/Export/ExportCsv.php +++ b/libraries/classes/Plugins/Export/ExportCsv.php @@ -284,7 +284,7 @@ public function exportData( while ($row = $dbi->fetchRow($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $schema_insert .= $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { // always enclose fields diff --git a/libraries/classes/Plugins/Export/ExportHtmlword.php b/libraries/classes/Plugins/Export/ExportHtmlword.php index 0db9332fbd56..0defd6ddeb8b 100644 --- a/libraries/classes/Plugins/Export/ExportHtmlword.php +++ b/libraries/classes/Plugins/Export/ExportHtmlword.php @@ -254,7 +254,7 @@ public function exportData( while ($row = $dbi->fetchRow($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $value = $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; diff --git a/libraries/classes/Plugins/Export/ExportOds.php b/libraries/classes/Plugins/Export/ExportOds.php index 58793c9ed6cc..a7ba85e34013 100644 --- a/libraries/classes/Plugins/Export/ExportOds.php +++ b/libraries/classes/Plugins/Export/ExportOds.php @@ -263,7 +263,7 @@ public function exportData( $row[$j] = '0x' . bin2hex($row[$j]); } - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $GLOBALS['ods_buffer'] .= '' . '' . htmlspecialchars($GLOBALS[$what . '_null']) diff --git a/libraries/classes/Plugins/Export/ExportOdt.php b/libraries/classes/Plugins/Export/ExportOdt.php index 8ee29bae4af1..c7ecaa60d1d5 100644 --- a/libraries/classes/Plugins/Export/ExportOdt.php +++ b/libraries/classes/Plugins/Export/ExportOdt.php @@ -301,7 +301,7 @@ public function exportData( $row[$j] = '0x' . bin2hex($row[$j]); } - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $GLOBALS['odt_buffer'] .= '' . '' . htmlspecialchars($GLOBALS[$what . '_null']) diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index 2b5e4ae85dd8..4c166fc277be 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -2583,7 +2583,7 @@ public function exportData( $values = []; for ($j = 0; $j < $fieldsCnt; $j++) { // NULL - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $values[] = 'NULL'; } elseif ( $fieldsMeta[$j]->isNumeric diff --git a/libraries/classes/Plugins/Export/ExportTexytext.php b/libraries/classes/Plugins/Export/ExportTexytext.php index 395a172325fb..4feed79a920f 100644 --- a/libraries/classes/Plugins/Export/ExportTexytext.php +++ b/libraries/classes/Plugins/Export/ExportTexytext.php @@ -228,7 +228,7 @@ public function exportData( while ($row = $dbi->fetchRow($result)) { $text_output = ''; for ($j = 0; $j < $fields_cnt; $j++) { - if (! isset($row[$j]) || $row[$j] === null) { + if (! isset($row[$j])) { $value = $GLOBALS[$what . '_null']; } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; diff --git a/libraries/classes/Plugins/Export/ExportXml.php b/libraries/classes/Plugins/Export/ExportXml.php index 0e380cba376d..f12d88427859 100644 --- a/libraries/classes/Plugins/Export/ExportXml.php +++ b/libraries/classes/Plugins/Export/ExportXml.php @@ -551,7 +551,7 @@ public function exportData( // If a cell is NULL, still export it to preserve // the XML structure - if (! isset($record[$i]) || $record[$i] === null) { + if (! isset($record[$i])) { $record[$i] = 'NULL'; } diff --git a/libraries/classes/Plugins/Export/ExportYaml.php b/libraries/classes/Plugins/Export/ExportYaml.php index 3cc9d82f6519..4bb1e7b5287a 100644 --- a/libraries/classes/Plugins/Export/ExportYaml.php +++ b/libraries/classes/Plugins/Export/ExportYaml.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem; use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; +use function array_key_exists; use function is_numeric; use function str_replace; use function stripslashes; @@ -187,7 +188,7 @@ public function exportData( } for ($i = 0; $i < $columns_cnt; $i++) { - if (! isset($record[$i])) { + if (! array_key_exists($i, $record)) { continue; } diff --git a/libraries/classes/Sanitize.php b/libraries/classes/Sanitize.php index 0ee7e60a7849..9b30e71897f6 100644 --- a/libraries/classes/Sanitize.php +++ b/libraries/classes/Sanitize.php @@ -323,7 +323,7 @@ public static function escapeJsString($string) /** * Formats a value for javascript code. * - * @param string $value String to be formatted. + * @param string|bool|int $value String to be formatted. * * @return int|string formatted value. */ @@ -338,7 +338,7 @@ public static function formatJsVal($value) } if (is_int($value)) { - return (int) $value; + return $value; } return '"' . self::escapeJsString($value) . '"'; diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 76f43158cc6c..eaf8f3e99e2a 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -121,7 +121,7 @@ public function wildcardEscapeForGrant(string $dbname, string $tablename): strin /** * Generates a condition on the user name * - * @param string $initial the user's initial + * @param string|null $initial the user's initial * * @return string the generated condition */ diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index c74a18aa720e..87b9a33b8f02 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -26,6 +26,7 @@ use function in_array; use function is_array; use function is_bool; +use function is_object; use function microtime; use function session_start; use function session_write_close; @@ -1460,7 +1461,7 @@ private function getMessageIfMissingColumnIndex($table, $database, $editable, $h /** * Function to display results when the executed query returns non empty results * - * @param object|null $result executed query results + * @param object|bool|null $result executed query results * @param array $analyzedSqlResults analysed sql results * @param string $db current database * @param string $table current table @@ -1495,13 +1496,13 @@ private function getQueryResponseForResultsReturned( // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here - if (isset($_POST['grid_edit']) && $_POST['grid_edit'] == true) { + if (isset($_POST['grid_edit']) && $_POST['grid_edit'] == true && is_object($result)) { $this->getResponseForGridEdit($result); exit; } // Gets the list of fields properties - if (isset($result) && $result) { + if (isset($result) && is_object($result)) { $fieldsMeta = $this->dbi->getFieldsMeta($result) ?? []; } else { $fieldsMeta = []; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 03d71fe2d07a..ed7f7e2191bb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -325,41 +325,6 @@ parameters: count: 1 path: libraries/classes/DatabaseInterface.php - - - message: "#^Cannot access property \\$connect_errno on mysqli\\|false\\.$#" - count: 1 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Cannot access property \\$connect_error on mysqli\\|false\\.$#" - count: 1 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Cannot call method options\\(\\) on mysqli\\|false\\.$#" - count: 3 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Cannot call method real_connect\\(\\) on mysqli\\|false\\.$#" - count: 1 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Cannot call method ssl_set\\(\\) on mysqli\\|false\\.$#" - count: 1 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Strict comparison using \\=\\=\\= between true and null will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Dbal/DbiMysqli.php - - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 2 - path: libraries/classes/Dbal/DbiMysqli.php - - message: "#^Call to an undefined method object\\:\\:getMIMESubtype\\(\\)\\.$#" count: 1 @@ -550,21 +515,6 @@ parameters: count: 4 path: libraries/classes/File.php - - - message: "#^Argument of an invalid type array\\|object supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: libraries/classes/Footer.php - - - - message: "#^Method PhpMyAdmin\\\\Footer\\:\\:getDebugMessage\\(\\) should return string but returns string\\|false\\.$#" - count: 1 - path: libraries/classes/Footer.php - - - - message: "#^Method PhpMyAdmin\\\\Footer\\:\\:removeRecursion\\(\\) should return object but returns array\\|object\\|string\\.$#" - count: 1 - path: libraries/classes/Footer.php - - message: "#^Negated boolean expression is always false\\.$#" count: 1 @@ -1815,11 +1765,6 @@ parameters: count: 1 path: libraries/classes/Sql.php - - - message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\Sql\\:\\:getResponseForGridEdit\\(\\) expects object, object\\|null given\\.$#" - count: 1 - path: libraries/classes/Sql.php - - message: "#^Parameter \\#1 \\$table of method PhpMyAdmin\\\\Menu\\:\\:setTable\\(\\) expects string, string\\|null given\\.$#" count: 1 @@ -2000,11 +1945,6 @@ parameters: count: 1 path: test/classes/ConfigTest.php - - - message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\Dbal\\\\DbiMysqli\\:\\:numRows\\(\\) expects mysqli_result, false given\\.$#" - count: 1 - path: test/classes/Dbal/DbiMysqliTest.php - - message: "#^Parameter \\#3 \\$empty of method PhpMyAdmin\\\\Gis\\\\GisGeometryCollection\\:\\:generateWkt\\(\\) expects string, string\\|null given\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2d9a7ccde2de..d16476576104 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,7 +11,6 @@ parameters: - test/phpstan-constants.php checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false - treatPhpDocTypesAsCertain: false excludes_analyse: - examples/openid.php - node_modules/* diff --git a/psalm-baseline.xml b/psalm-baseline.xml index cd1950014d57..3fb82ee6f53d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -671,16 +671,12 @@ - - $mysqli->connect_errno - $mysqli->connect_error - - $mysqli - $mysqli - $mysqli - $mysqli - $mysqli + $link + $link + $link + $link + $link $mysqli $mysqli $mysqli @@ -700,23 +696,6 @@ $result $result - - $databaseName - $mysqli - $mysqli - $mysqli - $mysqli - $mysqli - $string - - - $mysqli->connect_errno - $mysqli->connect_error - - - $return_value === false || $return_value === null - $return_value === null - @@ -936,17 +915,6 @@ empty($charLists) - - - $object - - - object - - - return $object; - - $last_comma @@ -2376,15 +2344,14 @@ save - - $result + $result $result $insertId - + $_POST['purge'] ?? null $db $db @@ -2395,7 +2362,6 @@ $messageToShow ?? null $printView $printView - $result $result ?? null $row[0] $showtable diff --git a/test/classes/FooterTest.php b/test/classes/FooterTest.php index e2af27acfda4..906e0e8dbe71 100644 --- a/test/classes/FooterTest.php +++ b/test/classes/FooterTest.php @@ -4,6 +4,7 @@ namespace PhpMyAdmin\Tests; +use ArrayIterator; use PhpMyAdmin\ErrorHandler; use PhpMyAdmin\Footer; @@ -94,19 +95,12 @@ public function testRemoveRecursion(): void { $object = (object) []; $object->child = (object) []; + $object->childIterator = new ArrayIterator(); $object->child->parent = $object; - $this->callFunction( - $this->object, - Footer::class, - 'removeRecursion', - [ - &$object, - ] - ); - + $this->callFunction($this->object, Footer::class, 'removeRecursion', [&$object]); $this->assertEquals( - '{"child":{"parent":"***RECURSION***"}}', + '{"child":{"parent":"***RECURSION***"},"childIterator":"***ITERATOR***"}', json_encode($object) ); } diff --git a/test/classes/Plugins/Export/ExportYamlTest.php b/test/classes/Plugins/Export/ExportYamlTest.php index 7566ea5c9763..7c40a879a8ed 100644 --- a/test/classes/Plugins/Export/ExportYamlTest.php +++ b/test/classes/Plugins/Export/ExportYamlTest.php @@ -189,14 +189,17 @@ public function testExportData(): void ' id: 1' . "\n" . ' name: "abcd"' . "\n" . ' datetimefield: "2011-01-20 02:00:02"' . "\n" . + ' textfield: null' . "\n" . '-' . "\n" . ' id: 2' . "\n" . ' name: "foo"' . "\n" . ' datetimefield: "2010-01-20 02:00:02"' . "\n" . + ' textfield: null' . "\n" . '-' . "\n" . ' id: 3' . "\n" . ' name: "Abcd"' . "\n" . ' datetimefield: "2012-01-20 02:00:02"' . "\n" . + ' textfield: null' . "\n" . '-' . "\n" . ' id: 4' . "\n" . ' name: "Abcd"' . "\n" . diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index 5521fa426c07..0a60f173a180 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -68,14 +68,14 @@ public function connect( /** * selects given database * - * @param string|DatabaseName $dbname name of db to select - * @param object $link mysql link resource + * @param string|DatabaseName $databaseName name of db to select + * @param object $link mysql link resource * * @return bool */ - public function selectDb($dbname, $link) + public function selectDb($databaseName, $link) { - $GLOBALS['dummy_db'] = (string) $dbname; + $GLOBALS['dummy_db'] = (string) $databaseName; return true; } @@ -326,7 +326,7 @@ public function getError($link) /** * returns the number of rows returned by last query * - * @param object $result MySQL result + * @param object|bool $result MySQL result * * @return string|int */ @@ -424,14 +424,14 @@ public function fieldName($result, $i) /** * returns properly escaped string for use in MySQL queries * - * @param mixed $link database link - * @param string $str string to be escaped + * @param mixed $link database link + * @param string $string string to be escaped * * @return string a MySQL escaped string */ - public function escapeString($link, $str) + public function escapeString($link, $string) { - return addslashes($str); + return addslashes($string); } /**