From 80c4db72539f06b7b9534bf121cb3f1f158a16af Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 19 Feb 2023 21:21:24 +0000 Subject: [PATCH 1/2] Use strict check when type is known Signed-off-by: Kamil Tekiela --- libraries/classes/BrowseForeigners.php | 2 +- libraries/classes/Common.php | 2 +- libraries/classes/Config.php | 2 +- libraries/classes/ConfigStorage/Relation.php | 4 ++-- .../Controllers/Table/RelationController.php | 2 +- .../classes/Database/Designer/Common.php | 4 ++-- libraries/classes/Database/Qbe.php | 4 ++-- libraries/classes/Database/Routines.php | 2 +- libraries/classes/Dbal/DbiMysqli.php | 2 +- libraries/classes/Display/Results.php | 4 ++-- libraries/classes/Encoding.php | 4 ++-- libraries/classes/Error.php | 2 +- libraries/classes/ErrorHandler.php | 6 +++--- libraries/classes/Export.php | 2 +- libraries/classes/Gis/GisVisualization.php | 2 +- libraries/classes/Git.php | 4 ++-- libraries/classes/Import.php | 8 +++---- libraries/classes/IpAllowDeny.php | 4 ++-- libraries/classes/Mime.php | 4 ++-- .../classes/Navigation/NavigationTree.php | 21 +++++++++++-------- libraries/classes/Normalization.php | 2 +- .../classes/Plugins/Import/ImportCsv.php | 16 +++++++------- libraries/classes/Plugins/Schema/Pdf/Pdf.php | 2 +- .../Abs/SubstringTransformationsPlugin.php | 2 +- libraries/classes/Server/Privileges.php | 2 +- libraries/classes/Session.php | 2 +- libraries/classes/Sql.php | 2 +- libraries/classes/SystemDatabase.php | 2 +- libraries/classes/Table.php | 2 +- libraries/classes/Util.php | 6 +++--- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 11 ++++++++-- 32 files changed, 73 insertions(+), 63 deletions(-) diff --git a/libraries/classes/BrowseForeigners.php b/libraries/classes/BrowseForeigners.php index 4216bfc820..ff902552e6 100644 --- a/libraries/classes/BrowseForeigners.php +++ b/libraries/classes/BrowseForeigners.php @@ -325,7 +325,7 @@ class BrowseForeigners */ public function getForeignLimit(?string $foreignShowAll): ?string { - if (isset($foreignShowAll) && $foreignShowAll == __('Show all')) { + if ($foreignShowAll === __('Show all')) { return null; } diff --git a/libraries/classes/Common.php b/libraries/classes/Common.php index ef1702c1eb..335bb61150 100644 --- a/libraries/classes/Common.php +++ b/libraries/classes/Common.php @@ -424,7 +424,7 @@ final class Common $path_info_pos = mb_strrpos($GLOBALS['PMA_PHP_SELF'], $_PATH_INFO); if ($path_info_pos !== false) { $path_info_part = mb_substr($GLOBALS['PMA_PHP_SELF'], $path_info_pos, mb_strlen($_PATH_INFO)); - if ($path_info_part == $_PATH_INFO) { + if ($path_info_part === $_PATH_INFO) { $GLOBALS['PMA_PHP_SELF'] = mb_substr($GLOBALS['PMA_PHP_SELF'], 0, $path_info_pos); } } diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index e185a71e0c..d86e7cc9d0 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -1106,7 +1106,7 @@ class Config if ( $server['host'] == $request || $server['verbose'] == $request - || $verboseToLower == $serverToLower + || $verboseToLower === $serverToLower || md5($verboseToLower) === $serverToLower ) { $request = $i; diff --git a/libraries/classes/ConfigStorage/Relation.php b/libraries/classes/ConfigStorage/Relation.php index 61ab73493f..028ecc6af5 100644 --- a/libraries/classes/ConfigStorage/Relation.php +++ b/libraries/classes/ConfigStorage/Relation.php @@ -837,9 +837,9 @@ class Relation } else { $key = '0x' . bin2hex($key); if (str_contains($data, '0x')) { - $selected = ($key == trim($data)); + $selected = ($key === trim($data)); } else { - $selected = ($key == '0x' . $data); + $selected = ($key === '0x' . $data); } } diff --git a/libraries/classes/Controllers/Table/RelationController.php b/libraries/classes/Controllers/Table/RelationController.php index 65dae0b491..8f77d45591 100644 --- a/libraries/classes/Controllers/Table/RelationController.php +++ b/libraries/classes/Controllers/Table/RelationController.php @@ -381,7 +381,7 @@ final class RelationController extends AbstractController $tables_rs = $this->dbi->query($query); foreach ($tables_rs as $row) { - if (! isset($row['Engine']) || mb_strtoupper($row['Engine']) != $storageEngine) { + if (! isset($row['Engine']) || mb_strtoupper($row['Engine']) !== $storageEngine) { continue; } diff --git a/libraries/classes/Database/Designer/Common.php b/libraries/classes/Database/Designer/Common.php index 06e7840384..6041ff68ba 100644 --- a/libraries/classes/Database/Designer/Common.php +++ b/libraries/classes/Database/Designer/Common.php @@ -554,7 +554,7 @@ class Common $type_T2 = mb_strtoupper($tables[$T2]['ENGINE'] ?? ''); // native foreign key - if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 == $type_T2) { + if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 === $type_T2) { // relation exists? $existrel_foreign = $this->relation->getForeigners($DB2, $T2, '', 'foreign'); $foreigner = $this->relation->searchColumnInForeigners($existrel_foreign, $F2); @@ -693,7 +693,7 @@ class Common $tables = $this->dbi->getTablesFull($DB2, $T2); $type_T2 = mb_strtoupper($tables[$T2]['ENGINE']); - if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 == $type_T2) { + if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 === $type_T2) { // InnoDB $existrel_foreign = $this->relation->getForeigners($DB2, $T2, '', 'foreign'); $foreigner = $this->relation->searchColumnInForeigners($existrel_foreign, $F2); diff --git a/libraries/classes/Database/Qbe.php b/libraries/classes/Database/Qbe.php index 367568ef67..f45ec8c6cb 100644 --- a/libraries/classes/Database/Qbe.php +++ b/libraries/classes/Database/Qbe.php @@ -819,7 +819,7 @@ class Qbe $htmlOutput .= $this->getAndOrColCell( $newColumnCount, $checkedOptions, - $columnIndex + 1 == $this->criteriaColumnCount + $columnIndex + 1 === $this->criteriaColumnCount ); $newColumnCount++; } @@ -1573,7 +1573,7 @@ class Qbe } // We are done if all tables are in $finalized - if (count($finalized) == count($searchTables)) { + if (count($finalized) === count($searchTables)) { return; } } diff --git a/libraries/classes/Database/Routines.php b/libraries/classes/Database/Routines.php index 5f53277930..06816f4404 100644 --- a/libraries/classes/Database/Routines.php +++ b/libraries/classes/Database/Routines.php @@ -884,7 +884,7 @@ class Routines } } - if ($i == count($itemParamName) - 1) { + if ($i === count($itemParamName) - 1) { continue; } diff --git a/libraries/classes/Dbal/DbiMysqli.php b/libraries/classes/Dbal/DbiMysqli.php index eea70c32f2..e3ed97ef1b 100644 --- a/libraries/classes/Dbal/DbiMysqli.php +++ b/libraries/classes/Dbal/DbiMysqli.php @@ -182,7 +182,7 @@ class DbiMysqli implements DbiExtension public function realQuery(string $query, Connection $connection, int $options): MysqliResult|false { $method = MYSQLI_STORE_RESULT; - if ($options == ($options | DatabaseInterface::QUERY_UNBUFFERED)) { + if ($options === ($options | DatabaseInterface::QUERY_UNBUFFERED)) { $method = MYSQLI_USE_RESULT; } diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index b508f25690..288a64bc6a 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -526,7 +526,7 @@ class Results $isLink && $previousTable != '' && $fieldsMeta[$i]->table != '' - && $fieldsMeta[$i]->table != $previousTable + && $fieldsMeta[$i]->table !== $previousTable ) { // don't display links $hasEditLink = false; @@ -3636,7 +3636,7 @@ class Results $sortedColumnIndex = false; foreach ($fieldsMeta as $key => $meta) { - if (($meta->table == $sortTable) && ($meta->name == $sortColumn)) { + if (($meta->table === $sortTable) && ($meta->name === $sortColumn)) { $sortedColumnIndex = $key; break; } diff --git a/libraries/classes/Encoding.php b/libraries/classes/Encoding.php index ae0cb5cbf5..ae223873f5 100644 --- a/libraries/classes/Encoding.php +++ b/libraries/classes/Encoding.php @@ -177,7 +177,7 @@ class Encoding string $dest_charset, string $what ): string { - if ($src_charset == $dest_charset) { + if ($src_charset === $dest_charset) { return $what; } @@ -263,7 +263,7 @@ class Encoding $str = $dist; } - if ($string_encoding != $enc && $enc != '') { + if ($string_encoding !== $enc && $enc != '') { return mb_convert_encoding($str, $enc, $string_encoding); } diff --git a/libraries/classes/Error.php b/libraries/classes/Error.php index 4a80b38f4c..775e9baaec 100644 --- a/libraries/classes/Error.php +++ b/libraries/classes/Error.php @@ -513,7 +513,7 @@ class Error extends Message $destParts = explode(DIRECTORY_SEPARATOR, $dest); $result = '.'; - while (implode(DIRECTORY_SEPARATOR, $destParts) != implode(DIRECTORY_SEPARATOR, $hereParts)) { + while (implode(DIRECTORY_SEPARATOR, $destParts) !== implode(DIRECTORY_SEPARATOR, $hereParts)) { if (count($hereParts) > count($destParts)) { array_pop($hereParts); $result .= DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'; diff --git a/libraries/classes/ErrorHandler.php b/libraries/classes/ErrorHandler.php index 808c3cb652..e87321fafe 100644 --- a/libraries/classes/ErrorHandler.php +++ b/libraries/classes/ErrorHandler.php @@ -416,7 +416,7 @@ class ErrorHandler // if preference is not 'never' and // there are 'actual' errors to be reported - if ($GLOBALS['cfg']['SendErrorReports'] !== 'never' && $this->countErrors() != $this->countUserErrors()) { + if ($GLOBALS['cfg']['SendErrorReports'] !== 'never' && $this->countErrors() !== $this->countUserErrors()) { // add report button. $retval .= '
countErrors() != $this->countUserErrors(); + && $this->countErrors() !== $this->countUserErrors(); } /** @@ -582,7 +582,7 @@ class ErrorHandler public function reportErrors(): void { // if there're no actual errors, - if (! $this->hasErrors() || $this->countErrors() == $this->countUserErrors()) { + if (! $this->hasErrors() || $this->countErrors() === $this->countUserErrors()) { // then simply return. return; } diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 7cbfeaaa88..f7c3b6fa2f 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -311,7 +311,7 @@ class Export $requiredExtension = '.' . $exportPlugin->getProperties()->getExtension(); $extensionLength = mb_strlen($requiredExtension); $userExtension = mb_substr($filename, -$extensionLength); - if (mb_strtolower($userExtension) != $requiredExtension) { + if (mb_strtolower($userExtension) !== $requiredExtension) { $filename .= $requiredExtension; } diff --git a/libraries/classes/Gis/GisVisualization.php b/libraries/classes/Gis/GisVisualization.php index 1322b89de2..eae696c6df 100644 --- a/libraries/classes/Gis/GisVisualization.php +++ b/libraries/classes/Gis/GisVisualization.php @@ -261,7 +261,7 @@ class GisVisualization $required_extension = '.' . $ext; $extension_length = mb_strlen($required_extension); $user_extension = mb_substr($file_name, -$extension_length); - if (mb_strtolower($user_extension) != $required_extension) { + if (mb_strtolower($user_extension) !== $required_extension) { $file_name .= $required_extension; } diff --git a/libraries/classes/Git.php b/libraries/classes/Git.php index a105815d10..bcb470f235 100644 --- a/libraries/classes/Git.php +++ b/libraries/classes/Git.php @@ -233,7 +233,7 @@ class Git substr($index_data, $offset + ($position * 20), 20) ) ); - if ($sha == $hash) { + if ($sha === $hash) { $found = true; break; } @@ -501,7 +501,7 @@ class Git } // have found our ref? - if ($parts[1] == $refHead) { + if ($parts[1] === $refHead) { $hash = $parts[0]; break; } diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index 00557e42e9..ad4eaec6e9 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -1093,7 +1093,7 @@ class Import for ($m = 0; $m < $numCols; ++$m) { $tempSQLStr .= Util::backquote($tables[$i][self::COL_NAMES][$m]); - if ($m == $numCols - 1) { + if ($m === $numCols - 1) { continue; } @@ -1131,11 +1131,11 @@ class Import : (string) $tables[$i][self::ROWS][$j][$k]; } - if ($k != $numCols - 1) { + if ($k !== $numCols - 1) { $tempSQLStr .= ', '; } - if ($colCount == $numCols - 1) { + if ($colCount === $numCols - 1) { $colCount = 0; } else { $colCount++; @@ -1147,7 +1147,7 @@ class Import $tempSQLStr .= ')'; - if ($j != $numRows - 1) { + if ($j !== $numRows - 1) { $tempSQLStr .= ",\n "; } diff --git a/libraries/classes/IpAllowDeny.php b/libraries/classes/IpAllowDeny.php index 36499dfcab..30a528a1e0 100644 --- a/libraries/classes/IpAllowDeny.php +++ b/libraries/classes/IpAllowDeny.php @@ -81,7 +81,7 @@ class IpAllowDeny $maskl += 2 ** (30 - $i); } - return ($maskl & $rangel) == ($maskl & $ipl); + return ($maskl & $rangel) === ($maskl & $ipl); } // range based @@ -95,7 +95,7 @@ class IpAllowDeny $result = false; } } else { - if ($maskocts[$i] <> $ipocts[$i]) { + if ($maskocts[$i] !== $ipocts[$i]) { $result = false; } } diff --git a/libraries/classes/Mime.php b/libraries/classes/Mime.php index b4067a18ba..76275c7680 100644 --- a/libraries/classes/Mime.php +++ b/libraries/classes/Mime.php @@ -26,10 +26,10 @@ class Mime * * @return string */ - public static function detect($test) + public static function detect(string $test) { $len = mb_strlen($test); - if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { + if ($len >= 2 && $test[0] === chr(0xff) && $test[1] === chr(0xd8)) { return 'image/jpeg'; } diff --git a/libraries/classes/Navigation/NavigationTree.php b/libraries/classes/Navigation/NavigationTree.php index 1eec0e0954..09cc28b73b 100644 --- a/libraries/classes/Navigation/NavigationTree.php +++ b/libraries/classes/Navigation/NavigationTree.php @@ -430,7 +430,7 @@ class NavigationTree continue; } - if ($type2 == $container->realName) { + if ($type2 === $container->realName) { $node->pos2 = $pos2; } @@ -455,7 +455,7 @@ class NavigationTree } $node = NodeFactory::getInstance(NodeTable::class, $path[0]); - if ($type2 == $container->realName) { + if ($type2 === $container->realName) { $node->pos2 = $pos2; } @@ -498,7 +498,7 @@ class NavigationTree } $node->pos2 = $container->parent->pos2; - if ($type3 == $container->realName) { + if ($type3 === $container->realName) { $node->pos3 = $pos3; } @@ -544,7 +544,7 @@ class NavigationTree // Add all new Nodes to the tree foreach ($retval as $node) { $node->pos2 = $pos2; - if ($type3 == $node->realName) { + if ($type3 === $node->realName) { $node->pos3 = $pos3; } @@ -552,7 +552,7 @@ class NavigationTree } } else { foreach ($table->children as $node) { - if ($type3 == $node->realName) { + if ($type3 === $node->realName) { $node->pos3 = $pos3; } @@ -626,7 +626,7 @@ class NavigationTree // Add all new Nodes to the tree foreach ($retval as $node) { - if ($type == $node->realName) { + if ($type === $node->realName) { $node->pos2 = $pos2; } @@ -634,7 +634,7 @@ class NavigationTree } } else { foreach ($db->children as $node) { - if ($type == $node->realName) { + if ($type === $node->realName) { $node->pos2 = $pos2; } @@ -777,7 +777,10 @@ class NavigationTree foreach ($node->children as $child) { $keySeparatorLength = mb_strlen((string) $key) + $separatorLength; $nameSubstring = mb_substr((string) $child->name, 0, $keySeparatorLength); - if (($nameSubstring != $key . $separator && $child->name != $key) || $child->type != Node::OBJECT) { + if ( + ($nameSubstring !== $key . $separator && $child->name !== $key) + || $child->type != Node::OBJECT + ) { continue; } @@ -1162,7 +1165,7 @@ class NavigationTree $buffer = ''; $extraClass = ''; for ($i = 0, $nbChildren = count($children); $i < $nbChildren; $i++) { - if ($i + 1 == $nbChildren) { + if ($i + 1 === $nbChildren) { $extraClass = ' last'; } diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php index 4960070475..d8b2a1cdaa 100644 --- a/libraries/classes/Normalization.php +++ b/libraries/classes/Normalization.php @@ -414,7 +414,7 @@ class Normalization if (count($primarycols) > 1) { $this->dbi->selectDb($db); $columns = $this->dbi->getColumnNames($db, $table); - if (count($pk) == count($columns)) { + if (count($pk) === count($columns)) { $headText = sprintf( __( 'No partial dependencies possible as ' diff --git a/libraries/classes/Plugins/Import/ImportCsv.php b/libraries/classes/Plugins/Import/ImportCsv.php index f1680e3fe6..d1a43fe911 100644 --- a/libraries/classes/Plugins/Import/ImportCsv.php +++ b/libraries/classes/Plugins/Import/ImportCsv.php @@ -297,7 +297,7 @@ class ImportCsv extends AbstractImportCsv if (! $csv_finish) { // Grab empty field if ($ch == $GLOBALS['csv_terminated']) { - if ($i == $len - 1) { + if ($i === $len - 1) { break; } @@ -315,7 +315,7 @@ class ImportCsv extends AbstractImportCsv // Grab one field $fallbacki = $i; if ($ch == $GLOBALS['csv_enclosed']) { - if ($i == $len - 1) { + if ($i === $len - 1) { break; } @@ -343,7 +343,7 @@ class ImportCsv extends AbstractImportCsv && ($ch == "\r" || $ch == "\n")))) ) { if ($ch == $GLOBALS['csv_escaped']) { - if ($i == $len - 1) { + if ($i === $len - 1) { $fail = true; break; } @@ -367,7 +367,7 @@ class ImportCsv extends AbstractImportCsv } $value .= $ch; - if ($i == $len - 1) { + if ($i === $len - 1) { if (! $GLOBALS['finished']) { $fail = true; } @@ -402,9 +402,9 @@ class ImportCsv extends AbstractImportCsv // Need to strip trailing enclosing char? if ($need_end && $ch == $GLOBALS['csv_enclosed']) { - if ($GLOBALS['finished'] && $i == $len - 1) { + if ($GLOBALS['finished'] && $i === $len - 1) { $ch = null; - } elseif ($i == $len - 1) { + } elseif ($i === $len - 1) { $i = $fallbacki; $ch = mb_substr($buffer, $i, 1); if ($csv_terminated_len > 1 && $ch == $GLOBALS['csv_terminated'][0]) { @@ -426,14 +426,14 @@ class ImportCsv extends AbstractImportCsv if ( $ch == $GLOBALS['csv_new_line'] || ($GLOBALS['csv_new_line'] === 'auto' && ($ch == "\r" || $ch == "\n")) - || ($GLOBALS['finished'] && $i == $len - 1) + || ($GLOBALS['finished'] && $i === $len - 1) ) { $csv_finish = true; } // Go to next char if ($ch == $GLOBALS['csv_terminated']) { - if ($i == $len - 1) { + if ($i === $len - 1) { $i = $fallbacki; $ch = mb_substr($buffer, $i, 1); if ($csv_terminated_len > 1 && $ch == $GLOBALS['csv_terminated'][0]) { diff --git a/libraries/classes/Plugins/Schema/Pdf/Pdf.php b/libraries/classes/Plugins/Schema/Pdf/Pdf.php index 2f5fefcc3e..fbbd9b138b 100644 --- a/libraries/classes/Plugins/Schema/Pdf/Pdf.php +++ b/libraries/classes/Plugins/Schema/Pdf/Pdf.php @@ -401,7 +401,7 @@ class Pdf extends PdfLib $l += $cw[mb_ord($c)] ?? 0; if ($l > $wmax) { if ($sep == -1) { - if ($i == $j) { + if ($i === $j) { $i++; } } else { diff --git a/libraries/classes/Plugins/Transformations/Abs/SubstringTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/SubstringTransformationsPlugin.php index fa68609d50..86ad501f33 100644 --- a/libraries/classes/Plugins/Transformations/Abs/SubstringTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/SubstringTransformationsPlugin.php @@ -61,7 +61,7 @@ abstract class SubstringTransformationsPlugin extends TransformationsPlugin $length = mb_strlen($newtext); $baselength = mb_strlen((string) $buffer); - if ($length != $baselength) { + if ($length !== $baselength) { if ($optionZero !== 0) { $newtext = $options[2] . $newtext; } diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 8901595709..c2c038318e 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -1279,7 +1279,7 @@ class Privileges foreach ($grantsArr as $grant) { $specificPrivileges[$grant[0]] = 'N'; foreach ($tablePrivs as $tablePriv) { - if ($grant[0] != $tablePriv) { + if ($grant[0] !== $tablePriv) { continue; } diff --git a/libraries/classes/Session.php b/libraries/classes/Session.php index 6ae540a66d..521883fd26 100644 --- a/libraries/classes/Session.php +++ b/libraries/classes/Session.php @@ -187,7 +187,7 @@ class Session $session_result = session_start(); - if ($session_result !== true || $orig_error_count != $errorHandler->countErrors(false)) { + if ($session_result !== true || $orig_error_count !== $errorHandler->countErrors(false)) { setcookie($httpCookieName, '', 1); $errors = $errorHandler->sliceErrors($orig_error_count); self::sessionFailed($errors); diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 0e15af744b..e7cd72334a 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -208,7 +208,7 @@ class Sql $numberFound++; } - if ($numberFound == count($indexColumns)) { + if ($numberFound === count($indexColumns)) { return true; } } diff --git a/libraries/classes/SystemDatabase.php b/libraries/classes/SystemDatabase.php index 02fb152385..86fa4849e3 100644 --- a/libraries/classes/SystemDatabase.php +++ b/libraries/classes/SystemDatabase.php @@ -114,7 +114,7 @@ class SystemDatabase break; } - if ($columnCount == count($columnMap)) { + if ($columnCount === count($columnMap)) { break; } } diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index c9cfdca449..795110c716 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -886,7 +886,7 @@ class Table implements Stringable foreach ($tableCopyRs as $tableCopyRow) { $valueParts = []; foreach ($tableCopyRow as $key => $val) { - if (! isset($rowFields[$key]) || $rowFields[$key] != 'cc') { + if (! isset($rowFields[$key]) || $rowFields[$key] !== 'cc') { continue; } diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 0a7b97b3ec..ce1279adbd 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -444,7 +444,7 @@ class Util } } - if ($unit != $byteUnits[0]) { + if ($unit !== $byteUnits[0]) { // if the unit is not bytes (as represented in current language) // reformat with max length of 5 // 4th parameter=true means do not reformat if value < 1 @@ -980,7 +980,7 @@ class Util } return $keyword . $charset - . ($charset == $collation ? '' : ' COLLATE ' . $collation); + . ($charset === $collation ? '' : ' COLLATE ' . $collation); } /** @@ -1942,7 +1942,7 @@ class Util $len = strlen($test); fclose($file); - if ($len >= 2 && $test[0] == chr(31) && $test[1] == chr(139)) { + if ($len >= 2 && $test[0] === chr(31) && $test[1] === chr(139)) { return 'application/gzip'; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d79a52d3dd..2b544cba8d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8736,7 +8736,7 @@ parameters: path: libraries/classes/Table.php - - message: "#^Right side of \\|\\| is always false\\.$#" + message: "#^Strict comparison using \\!\\=\\= between 'cc' and 'cc' will always evaluate to false\\.$#" count: 1 path: libraries/classes/Table.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 01e9457b61..569ba0159e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4325,7 +4325,6 @@ $result - $result $request @@ -7693,6 +7692,10 @@ mixed mixed + + mb_strtolower($userExtension) !== $requiredExtension + mb_strtolower($userExtension) !== $requiredExtension + @@ -8689,6 +8692,10 @@ $modifiedSql + + mb_strtolower($user_extension) !== $required_extension + mb_strtolower($user_extension) !== $required_extension + is_numeric($pos) is_numeric($rows) @@ -15167,7 +15174,7 @@ dbi->query($GLOBALS['sql_query'])]]> - + $maintainRelations From 8f7c28b1813e855274e60bbc313bff7b0e673bbf Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 19 Feb 2023 22:55:54 +0000 Subject: [PATCH 2/2] Refactor the condition to get rid of redundant code Signed-off-by: Kamil Tekiela --- libraries/classes/Table.php | 16 ++++++++-------- phpstan-baseline.neon | 10 ---------- psalm-baseline.xml | 4 ---- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index 795110c716..153d9863d6 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -830,12 +830,12 @@ class Table implements Stringable * Inserts existing entries in a PMA_* table by reading a value from an old * entry * - * @param string $work The array index, which Relation feature to check ('relwork', 'commwork', ...) - * @param string $table The array index, which PMA-table to update ('bookmark', 'relation', ...) - * @param array $getFields Which fields will be SELECT'ed from the old entry - * @param array $whereFields Which fields will be used for the WHERE query (array('FIELDNAME' => 'FIELDVALUE')) - * @param array $newFields Which fields will be used as new VALUES. These are the important keys which differ - * from the old entry (array('FIELDNAME' => 'NEW FIELDVALUE')) + * @param string $work The array index, which Relation feature to check ('relwork', 'commwork', ...) + * @param string $table The array index, which PMA-table to update ('bookmark', 'relation', ...) + * @param string[] $getFields Which fields will be SELECT'ed from the old entry + * @param array $whereFields Which fields will be used for the WHERE query (array('FIELDNAME' => 'FIELDVALUE')) + * @param array $newFields Which fields will be used as new VALUES. These are the important keys which differ + * from the old entry (array('FIELDNAME' => 'NEW FIELDVALUE')) */ public static function duplicateInfo( $work, @@ -857,7 +857,7 @@ class Table implements Stringable $rowFields = []; foreach ($getFields as $getField) { $selectParts[] = Util::backquote($getField); - $rowFields[$getField] = 'cc'; + $rowFields[] = $getField; } $whereParts = []; @@ -886,7 +886,7 @@ class Table implements Stringable foreach ($tableCopyRs as $tableCopyRow) { $valueParts = []; foreach ($tableCopyRow as $key => $val) { - if (! isset($rowFields[$key]) || $rowFields[$key] !== 'cc') { + if (! in_array($key, $rowFields)) { continue; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2b544cba8d..075c20afbf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8530,11 +8530,6 @@ parameters: count: 1 path: libraries/classes/Table.php - - - message: "#^Method PhpMyAdmin\\\\Table\\:\\:duplicateInfo\\(\\) has parameter \\$getFields with no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/Table.php - - message: "#^Method PhpMyAdmin\\\\Table\\:\\:duplicateInfo\\(\\) has parameter \\$newFields with no value type specified in iterable type array\\.$#" count: 1 @@ -8735,11 +8730,6 @@ parameters: count: 1 path: libraries/classes/Table.php - - - message: "#^Strict comparison using \\!\\=\\= between 'cc' and 'cc' will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Table.php - - message: "#^Method PhpMyAdmin\\\\Table\\\\ColumnsDefinition\\:\\:displayForm\\(\\) has parameter \\$fields_meta with no value type specified in iterable type array\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 569ba0159e..a2848e59ba 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -14911,7 +14911,6 @@ $foreignTable $foreignTable $foreignTable - $getField $index $index[0] $masterField @@ -14995,7 +14994,6 @@ - $rowFields[$getField] @@ -15021,7 +15019,6 @@ $foreignField $foreignTable $foreignTable - $getField $index $key $masterField @@ -15174,7 +15171,6 @@ dbi->query($GLOBALS['sql_query'])]]> - $maintainRelations