diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c8d05cdea9..76b3f335d9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3010,11 +3010,6 @@ parameters: count: 2 path: src/Controllers/Export/ExportController.php - - - message: "#^Only booleans are allowed in an if condition, string given\\.$#" - count: 1 - path: src/Controllers/Export/ExportController.php - - message: "#^PHPDoc tag @var for variable \\$aliasesParam has no value type specified in iterable type array\\.$#" count: 1 @@ -3612,7 +3607,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 3 + count: 2 path: src/Controllers/Import/SimulateDmlController.php - @@ -8507,7 +8502,7 @@ parameters: - message: "#^Cannot access offset 'col_extra' on mixed\\.$#" - count: 4 + count: 3 path: src/Database/CentralColumns.php - @@ -9426,7 +9421,7 @@ parameters: path: src/DatabaseInterface.php - - message: "#^Only booleans are allowed in an if condition, bool\\|string given\\.$#" + message: "#^Only booleans are allowed in a ternary operator condition, bool\\|string given\\.$#" count: 1 path: src/DatabaseInterface.php @@ -11102,7 +11097,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 17 + count: 16 path: src/Html/Generator.php - @@ -12275,11 +12270,6 @@ parameters: count: 5 path: src/Navigation/NavigationTree.php - - - message: "#^Only booleans are allowed in a negated boolean, int given\\.$#" - count: 1 - path: src/Navigation/NavigationTree.php - - message: "#^Only numeric types are allowed in \\+, int\\|false given on the left side\\.$#" count: 1 @@ -12902,7 +12892,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 3 + count: 2 path: src/Partitioning/Partition.php - @@ -12915,11 +12905,6 @@ parameters: count: 1 path: src/Partitioning/Partition.php - - - message: "#^Only booleans are allowed in an if condition, array given\\.$#" - count: 1 - path: src/Partitioning/Partition.php - - message: "#^Only booleans are allowed in an if condition, string\\|false\\|null given\\.$#" count: 1 @@ -13180,11 +13165,6 @@ parameters: count: 1 path: src/Plugins.php - - - message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" - count: 1 - path: src/Plugins/Auth/AuthenticationConfig.php - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" count: 1 @@ -20331,12 +20311,12 @@ parameters: path: test/classes/InsertEditTest.php - - message: "#^Method PhpMyAdmin\\\\Tests\\\\InsertEditTest\\:\\:parseString\\(\\) should return string but returns mixed\\.$#" + message: "#^Cannot cast bool\\|float\\|int\\|object to string\\.$#" count: 1 path: test/classes/InsertEditTest.php - - message: "#^Parameter \\#1 \\$value of function strval expects bool\\|float\\|int\\|resource\\|string\\|null, bool\\|float\\|int\\|object given\\.$#" + message: "#^Method PhpMyAdmin\\\\Tests\\\\InsertEditTest\\:\\:parseString\\(\\) should return string but returns mixed\\.$#" count: 1 path: test/classes/InsertEditTest.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 869360ed59..4c452f62e0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -447,6 +447,7 @@ $_POST[$key] $_POST[$key] $_POST[$key] + $_POST[$key] $canonicalPath @@ -4712,7 +4713,6 @@ - $centralListTable @@ -10706,17 +10706,11 @@ $colCollation $colType - $columnInfo - $tableInfo $eachTables mixed[][] - - $columnInfo - $tableInfo - @@ -14799,6 +14793,9 @@ $result $result + + $value + dataProviderConfigValueInsertRows providerForTestGetSpecialCharsForInsertingMode diff --git a/src/Config/Descriptions.php b/src/Config/Descriptions.php index 593947da48..45a8a27485 100644 --- a/src/Config/Descriptions.php +++ b/src/Config/Descriptions.php @@ -35,11 +35,7 @@ class Descriptions /* Fallback to path for name and empty string for description and comment */ if ($value === null) { - if ($type === 'name') { - $value = $path; - } else { - $value = ''; - } + $value = $type === 'name' ? $path : ''; } return Sanitize::sanitizeMessage($value); diff --git a/src/Config/FormDisplay.php b/src/Config/FormDisplay.php index 0347e5e7ab..3cc26029f9 100644 --- a/src/Config/FormDisplay.php +++ b/src/Config/FormDisplay.php @@ -516,7 +516,7 @@ class FormDisplay // equality comparison only if both values are numeric or not numeric // (allows to skip 0 == 'string' equalling to true) // or identity (for string-string) - if (! (($vk == $value && ! (is_numeric($valueCmp) xor is_numeric($vk))) || $vk === $value)) { + if (! ($vk == $value && ! (is_numeric($valueCmp) xor is_numeric($vk))) && $vk !== $value) { continue; } @@ -598,8 +598,7 @@ class FormDisplay switch ($type) { case 'double': $_POST[$key] = Util::requestString($_POST[$key]); - // phpcs:ignore Generic.PHP.ForbiddenFunctions - settype($_POST[$key], 'float'); + $_POST[$key] = (float) $_POST[$key]; break; case 'boolean': case 'integer': diff --git a/src/Config/Settings/Transformations.php b/src/Config/Settings/Transformations.php index 22bb7a1036..b2f420b4a8 100644 --- a/src/Config/Settings/Transformations.php +++ b/src/Config/Settings/Transformations.php @@ -323,12 +323,10 @@ final class Transformations */ private function setHex(array $transformations): array { - if (isset($transformations['Hex']) && is_array($transformations['Hex'])) { - if (isset($transformations['Hex'][0])) { - $length = (int) $transformations['Hex'][0]; - if ($length >= 0) { - return [$length]; - } + if (isset($transformations['Hex']) && is_array($transformations['Hex']) && isset($transformations['Hex'][0])) { + $length = (int) $transformations['Hex'][0]; + if ($length >= 0) { + return [$length]; } } diff --git a/src/ConfigStorage/Relation.php b/src/ConfigStorage/Relation.php index dcc874898d..43946f141b 100644 --- a/src/ConfigStorage/Relation.php +++ b/src/ConfigStorage/Relation.php @@ -850,11 +850,7 @@ class Relation $key = $relrow[$foreignField]; // if the display field has been defined for this foreign table - if ($foreignDisplay !== '') { - $value = $relrow[$foreignDisplay]; - } else { - $value = ''; - } + $value = $foreignDisplay !== '' ? $relrow[$foreignDisplay] : ''; $foreign[$key] = $value; } @@ -981,7 +977,7 @@ class Relation . Util::backquote($foreignTable) . '.' . Util::backquote($foreignDisplay); - $fQueryLimit = $foreignLimit !== '' ? $foreignLimit : ''; + $fQueryLimit = $foreignLimit; if ($foreignFilter !== '') { $theTotal = $this->dbi->fetchValue('SELECT COUNT(*)' . $fQueryFrom . $fQueryFilter); diff --git a/src/Controllers/AbstractController.php b/src/Controllers/AbstractController.php index 4886029d66..005a9adea7 100644 --- a/src/Controllers/AbstractController.php +++ b/src/Controllers/AbstractController.php @@ -50,11 +50,7 @@ abstract class AbstractController { $foundError = false; $errorMessage = ''; - if ($request) { - $array = $_REQUEST; - } else { - $array = $GLOBALS; - } + $array = $request ? $_REQUEST : $GLOBALS; foreach ($params as $param) { if (isset($array[$param]) && $array[$param] !== '') { diff --git a/src/Controllers/Database/Structure/FavoriteTableController.php b/src/Controllers/Database/Structure/FavoriteTableController.php index 355ebb2bcc..c08e5fcd25 100644 --- a/src/Controllers/Database/Structure/FavoriteTableController.php +++ b/src/Controllers/Database/Structure/FavoriteTableController.php @@ -54,11 +54,7 @@ final class FavoriteTableController extends AbstractController $favoriteInstance = RecentFavoriteTable::getInstance('favorite'); $favoriteTables = $request->getParam('favoriteTables'); - if ($favoriteTables !== null) { - $favoriteTables = json_decode($favoriteTables, true); - } else { - $favoriteTables = []; - } + $favoriteTables = $favoriteTables !== null ? json_decode($favoriteTables, true) : []; // Required to keep each user's preferences separate. $user = sha1($config->selectedServer['user']); diff --git a/src/Controllers/Database/StructureController.php b/src/Controllers/Database/StructureController.php index 8ea60b899c..6f1a5e8011 100644 --- a/src/Controllers/Database/StructureController.php +++ b/src/Controllers/Database/StructureController.php @@ -523,14 +523,12 @@ class StructureController extends AbstractController protected function getTrackingIcon(string $table, TrackedTable|null $trackedTable): string { $trackingIcon = ''; - if (Tracker::isActive()) { - if ($trackedTable !== null) { - $trackingIcon = $this->template->render('database/structure/tracking_icon', [ - 'db' => $GLOBALS['db'], - 'table' => $table, - 'is_tracked' => $trackedTable->active, - ]); - } + if (Tracker::isActive() && $trackedTable !== null) { + $trackingIcon = $this->template->render('database/structure/tracking_icon', [ + 'db' => $GLOBALS['db'], + 'table' => $table, + 'is_tracked' => $trackedTable->active, + ]); } return $trackingIcon; diff --git a/src/Controllers/ErrorReportController.php b/src/Controllers/ErrorReportController.php index c673bb20a5..ed8a890aa5 100644 --- a/src/Controllers/ErrorReportController.php +++ b/src/Controllers/ErrorReportController.php @@ -109,11 +109,7 @@ class ErrorReportController extends AbstractController $msg .= ' ' . __('You may want to refresh the page.'); /* Create message object */ - if ($success) { - $msg = Message::notice($msg); - } else { - $msg = Message::error($msg); - } + $msg = $success ? Message::notice($msg) : Message::error($msg); /* Add message to response */ if ($request->isAjax()) { diff --git a/src/Controllers/Export/ExportController.php b/src/Controllers/Export/ExportController.php index 5a00b81e6e..2fed20d29f 100644 --- a/src/Controllers/Export/ExportController.php +++ b/src/Controllers/Export/ExportController.php @@ -512,7 +512,7 @@ final class ExportController extends AbstractController // Compression needed? if ($GLOBALS['compression']) { - if ($separateFiles) { + if ($separateFiles !== '') { $this->export->dumpBuffer = $this->export->compress( $this->export->dumpBufferObjects, $GLOBALS['compression'], diff --git a/src/Controllers/Import/SimulateDmlController.php b/src/Controllers/Import/SimulateDmlController.php index 52d1522ce5..5d564d6c34 100644 --- a/src/Controllers/Import/SimulateDmlController.php +++ b/src/Controllers/Import/SimulateDmlController.php @@ -38,7 +38,7 @@ final class SimulateDmlController extends AbstractController $sqlData = []; $queries = explode($sqlDelimiter, $GLOBALS['sql_query']); foreach ($queries as $sqlQuery) { - if (empty($sqlQuery)) { + if ($sqlQuery === '') { continue; } diff --git a/src/Controllers/Server/Variables/SetVariableController.php b/src/Controllers/Server/Variables/SetVariableController.php index e69e0b2201..41e2230990 100644 --- a/src/Controllers/Server/Variables/SetVariableController.php +++ b/src/Controllers/Server/Variables/SetVariableController.php @@ -72,11 +72,7 @@ final class SetVariableController extends AbstractController ); [$formattedValue, $isHtmlFormatted] = $this->formatVariable($variableName, $varValue[1]); - if ($isHtmlFormatted === false) { - $json['variable'] = htmlspecialchars($formattedValue); - } else { - $json['variable'] = $formattedValue; - } + $json['variable'] = $isHtmlFormatted === false ? htmlspecialchars($formattedValue) : $formattedValue; } else { $this->response->setRequestStatus(false); $json['error'] = __('Setting variable failed'); diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index 21350b7b20..dc3e27babb 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -134,10 +134,8 @@ class SqlController extends AbstractController // set $goto to what will be displayed if query returns 0 rows $GLOBALS['goto'] = ''; - } else { - if (! $this->checkParameters(['sql_query'])) { - return; - } + } elseif (! $this->checkParameters(['sql_query'])) { + return; } /** diff --git a/src/Controllers/UserPasswordController.php b/src/Controllers/UserPasswordController.php index e4b0301866..47b35c9b59 100644 --- a/src/Controllers/UserPasswordController.php +++ b/src/Controllers/UserPasswordController.php @@ -64,12 +64,7 @@ class UserPasswordController extends AbstractController * and submit the query or logout */ if ($noPass !== null) { - if ($noPass == '1') { - $password = ''; - } else { - $password = $pmaPw; - } - + $password = $noPass == '1' ? '' : $pmaPw; $GLOBALS['change_password_message'] = $this->userPassword->setChangePasswordMsg( $pmaPw, $pmaPw2, diff --git a/src/Core.php b/src/Core.php index 7fd56585ee..8536c44ece 100644 --- a/src/Core.php +++ b/src/Core.php @@ -86,11 +86,7 @@ class Core $lang = 'en'; if (isset($GLOBALS['lang']) && in_array($GLOBALS['lang'], $phpDocLanguages)) { - if ($GLOBALS['lang'] === 'zh_CN') { - $lang = 'zh'; - } else { - $lang = $GLOBALS['lang']; - } + $lang = $GLOBALS['lang'] === 'zh_CN' ? 'zh' : $GLOBALS['lang']; } return self::linkURL('https://www.php.net/manual/' . $lang . '/' . $target); diff --git a/src/Database/CentralColumns.php b/src/Database/CentralColumns.php index 353369a3e2..03c039a453 100644 --- a/src/Database/CentralColumns.php +++ b/src/Database/CentralColumns.php @@ -227,7 +227,7 @@ class CentralColumns $length = $extractedColumnSpec['spec_in_brackets']; $collation = $def->collation ?? ''; - $isNull = ! $def->isNull ? '0' : '1'; + $isNull = $def->isNull ? '1' : '0'; $extra = $def->extra; $default = $def->default ?? ''; @@ -764,11 +764,7 @@ class CentralColumns $row['col_attribute'] = ''; } - if (in_array('auto_increment', $vals)) { - $row['col_extra'] = 'auto_increment'; - } else { - $row['col_extra'] = ''; - } + $row['col_extra'] = in_array('auto_increment', $vals) ? 'auto_increment' : ''; } } diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index ecf35b0ac0..2612bd8b1b 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -964,11 +964,7 @@ class DatabaseInterface implements DbalInterface continue; } - if ($index->isUnique()) { - $fields[$field]['Key'] = 'UNI'; - } else { - $fields[$field]['Key'] = 'MUL'; - } + $fields[$field]['Key'] = $index->isUnique() ? 'UNI' : 'MUL'; } } diff --git a/src/Dbal/MysqliResult.php b/src/Dbal/MysqliResult.php index a4076936ca..da12892a64 100644 --- a/src/Dbal/MysqliResult.php +++ b/src/Dbal/MysqliResult.php @@ -93,11 +93,7 @@ final class MysqliResult implements ResultInterface */ public function fetchValue(int|string $field = 0): string|false|null { - if (is_string($field)) { - $row = $this->fetchAssoc(); - } else { - $row = $this->fetchRow(); - } + $row = is_string($field) ? $this->fetchAssoc() : $this->fetchRow(); if (! array_key_exists($field, $row)) { return false; diff --git a/src/ErrorReport.php b/src/ErrorReport.php index 9004d052fe..1388991a62 100644 --- a/src/ErrorReport.php +++ b/src/ErrorReport.php @@ -176,11 +176,7 @@ class ErrorReport // get script name preg_match('<([a-zA-Z\-_\d\.]*\.php|js\/[a-zA-Z\-_\d\/\.]*\.js)$>', $components['path'] ?? '', $matches); - if (count($matches) < 2) { - $scriptName = 'index.php'; - } else { - $scriptName = $matches[1]; - } + $scriptName = count($matches) < 2 ? 'index.php' : $matches[1]; // remove deployment specific details to make uri more generic if (isset($components['query'])) { diff --git a/src/Git.php b/src/Git.php index 686c12ef8a..092bdc1421 100644 --- a/src/Git.php +++ b/src/Git.php @@ -216,11 +216,7 @@ class Git $firstbyte = intval(substr($hash, 0, 2), 16); // array is indexed from 1 and we need to get // previous entry for start - if ($firstbyte == 0) { - $start = 0; - } else { - $start = $fanout[$firstbyte]; - } + $start = $firstbyte == 0 ? 0 : $fanout[$firstbyte]; $end = $fanout[$firstbyte + 1]; diff --git a/src/Header.php b/src/Header.php index e69abb9bec..a73c42578a 100644 --- a/src/Header.php +++ b/src/Header.php @@ -58,7 +58,7 @@ class Header /** * Whether to show the warnings */ - private bool $warningsEnabled; + private bool $warningsEnabled = true; /** * Whether we are servicing an ajax request. */ @@ -71,7 +71,7 @@ class Header * Whether the HTTP headers (and possibly some HTML) * have already been sent to the browser */ - private bool $headerIsSent; + private bool $headerIsSent = false; private UserPreferences $userPreferences; @@ -86,11 +86,8 @@ class Header $this->console = $console; $this->menuEnabled = $dbi->isConnected(); $this->menu = new Menu($dbi, $this->template, $GLOBALS['db'] ?? '', $GLOBALS['table'] ?? ''); - - $this->warningsEnabled = true; $this->scripts = new Scripts($this->template); $this->addDefaultScripts(); - $this->headerIsSent = false; $this->userPreferences = new UserPreferences($dbi, new Relation($dbi), $this->template); } diff --git a/src/Html/Generator.php b/src/Html/Generator.php index dd81ac2bb2..fe163fc92c 100644 --- a/src/Html/Generator.php +++ b/src/Html/Generator.php @@ -258,7 +258,7 @@ class Generator // Can we get field class based values? $currentClass = $dbi->types->getTypeClass($trueType); $config = Config::getInstance(); - if (! empty($currentClass) && isset($config->settings['DefaultFunctions']['FUNC_' . $currentClass])) { + if ($currentClass !== '' && isset($config->settings['DefaultFunctions']['FUNC_' . $currentClass])) { $defaultFunction = $config->settings['DefaultFunctions']['FUNC_' . $currentClass]; // Change the configured default function to include the ST_ prefix with MySQL 5.6 and later. // It needs to match the function listed in the select html element. diff --git a/src/Import/Import.php b/src/Import/Import.php index 5507abe9e4..611a063b0a 100644 --- a/src/Import/Import.php +++ b/src/Import/Import.php @@ -826,7 +826,7 @@ class Import } if ( - $cell == (string) (float) $cell + $cell === (string) (float) $cell && str_contains($cell, '.') && mb_substr_count($cell, '.') === 1 ) { @@ -1036,7 +1036,7 @@ class Import ]; /* TODO: Do more checking here to make sure they really are matched */ - if (count($tables) != count($analyses)) { + if (count($tables) !== count($analyses)) { ResponseRenderer::getInstance()->callExit(); } diff --git a/src/InsertEdit.php b/src/InsertEdit.php index d8e828dafb..cc47e89bb0 100644 --- a/src/InsertEdit.php +++ b/src/InsertEdit.php @@ -346,11 +346,7 @@ class InsertEdit ): string { $foreigner = $this->relation->searchColumnInForeigners($foreigners, $column->field); if (mb_strstr($column->trueType, 'enum')) { - if (mb_strlen($column->type) > 20) { - $nullifyCode = '1'; - } else { - $nullifyCode = '2'; - } + $nullifyCode = mb_strlen($column->type) > 20 ? '1' : '2'; } elseif (mb_strstr($column->trueType, 'set')) { $nullifyCode = '3'; } elseif ($foreigner && $foreignData['foreign_link'] == false) { @@ -891,11 +887,7 @@ class InsertEdit if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) { // this should NOT happen //$GLOBALS['goto'] = false; - if ($GLOBALS['goto'] === 'index.php?route=/sql') { - $gotoInclude = '/sql'; - } else { - $gotoInclude = false; - } + $gotoInclude = $GLOBALS['goto'] === 'index.php?route=/sql' ? '/sql' : false; } else { $gotoInclude = $GLOBALS['goto']; } @@ -906,11 +898,7 @@ class InsertEdit } if (! $gotoInclude) { - if ($GLOBALS['table'] === '') { - $gotoInclude = '/database/sql'; - } else { - $gotoInclude = '/table/sql'; - } + $gotoInclude = $GLOBALS['table'] === '' ? '/database/sql' : '/table/sql'; } return $gotoInclude; diff --git a/src/Language.php b/src/Language.php index 51bd565a1b..e82cb774ab 100644 --- a/src/Language.php +++ b/src/Language.php @@ -164,11 +164,7 @@ class Language } /* Text direction for language */ - if ($this->isRTL()) { - $GLOBALS['text_dir'] = 'rtl'; - } else { - $GLOBALS['text_dir'] = 'ltr'; - } + $GLOBALS['text_dir'] = $this->isRTL() ? 'rtl' : 'ltr'; /* TCPDF */ $GLOBALS['l'] = []; diff --git a/src/Navigation/NavigationTree.php b/src/Navigation/NavigationTree.php index c8453ad203..49db35b76c 100644 --- a/src/Navigation/NavigationTree.php +++ b/src/Navigation/NavigationTree.php @@ -426,7 +426,7 @@ class NavigationTree /** @var NodeTable|null $table */ $table = $container->getChild($path[0], true); if ($table === null) { - if (! $db->getPresence('tables', $path[0])) { + if ($db->getPresence('tables', $path[0]) === 0) { return false; } @@ -1047,7 +1047,7 @@ class NavigationTree $args = []; $parents = $node->parents(true); foreach ($parents as $parent) { - if (! isset($parent->urlParamName)) { + if ($parent->urlParamName === null) { continue; } diff --git a/src/Navigation/Nodes/NodeDatabase.php b/src/Navigation/Nodes/NodeDatabase.php index 0df4955108..aff0415a29 100644 --- a/src/Navigation/Nodes/NodeDatabase.php +++ b/src/Navigation/Nodes/NodeDatabase.php @@ -91,11 +91,7 @@ class NodeDatabase extends Node */ private function getTableOrViewCount(string $which, string $searchClause): int { - if ($which === 'tables') { - $condition = 'IN'; - } else { - $condition = 'NOT IN'; - } + $condition = $which === 'tables' ? 'IN' : 'NOT IN'; $dbi = DatabaseInterface::getInstance(); if (! Config::getInstance()->selectedServer['DisableIS']) { @@ -336,11 +332,7 @@ class NodeDatabase extends Node */ private function getTablesOrViews(string $which, int $pos, string $searchClause): array { - if ($which === 'tables') { - $condition = 'IN'; - } else { - $condition = 'NOT IN'; - } + $condition = $which === 'tables' ? 'IN' : 'NOT IN'; $config = Config::getInstance(); $maxItems = $config->settings['MaxNavigationItems']; @@ -570,19 +562,17 @@ class NodeDatabase extends Node public function getHtmlForControlButtons(NavigationItemsHidingFeature|null $navigationItemsHidingFeature): string { $ret = ''; - if ($navigationItemsHidingFeature !== null) { - if ($this->hiddenCount > 0) { - $params = ['showUnhideDialog' => true, 'dbName' => $this->realName]; - $ret = '' - . '' - . Generator::getImage( - 'show', - __('Show hidden items'), - ) - . ''; - } + if ($navigationItemsHidingFeature !== null && $this->hiddenCount > 0) { + $params = ['showUnhideDialog' => true, 'dbName' => $this->realName]; + $ret = '' + . '' + . Generator::getImage( + 'show', + __('Show hidden items'), + ) + . ''; } return $ret; diff --git a/src/Partitioning/Partition.php b/src/Partitioning/Partition.php index e2f62cf5da..ded43c1e2e 100644 --- a/src/Partitioning/Partition.php +++ b/src/Partitioning/Partition.php @@ -145,7 +145,7 @@ class Partition extends SubPartition . ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db) . ' AND `TABLE_NAME` = ' . $dbi->quoteString($table), ); - if ($result) { + if ($result !== []) { $partitionMap = []; /** @var array $row */ foreach ($result as $row) { @@ -213,7 +213,7 @@ class Partition extends SubPartition . ' AND `TABLE_NAME` = ' . $dbi->quoteString($table) . ' LIMIT 1', ); - if (! empty($partitionMethod)) { + if ($partitionMethod !== []) { return $partitionMethod[0]; } } diff --git a/src/Plugins/Auth/AuthenticationConfig.php b/src/Plugins/Auth/AuthenticationConfig.php index 323df8e4f8..5ccb45fd46 100644 --- a/src/Plugins/Auth/AuthenticationConfig.php +++ b/src/Plugins/Auth/AuthenticationConfig.php @@ -73,7 +73,7 @@ class AuthenticationConfig extends AuthenticationPlugin parent::showFailure($failure); $connError = DatabaseInterface::getInstance()->getError(); - if (! $connError) { + if ($connError === '' || $connError === '0') { $connError = __('Cannot connect: invalid settings.'); } diff --git a/src/Plugins/Export/ExportHtmlword.php b/src/Plugins/Export/ExportHtmlword.php index 6c37c42b26..2b970c2dd0 100644 --- a/src/Plugins/Export/ExportHtmlword.php +++ b/src/Plugins/Export/ExportHtmlword.php @@ -603,7 +603,7 @@ class ExportHtmlword extends ExportPlugin . htmlspecialchars($colAlias) . $fmtPost . ''; $definition .= '' . htmlspecialchars($type) . ''; $definition .= '' - . (! $column->isNull ? __('No') : __('Yes')) + . ($column->isNull ? __('Yes') : __('No')) . ''; $definition .= '' . htmlspecialchars($column->default ?? ($column->isNull ? 'NULL' : '')) diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php index 2dc61264d5..83ac431009 100644 --- a/src/Plugins/Export/ExportLatex.php +++ b/src/Plugins/Export/ExportLatex.php @@ -378,7 +378,7 @@ class ExportLatex extends ExportPlugin } // last column ... no need for & character - if ($i == $columnsCnt - 1) { + if ($i === $columnsCnt - 1) { $buffer .= $columnValue; } else { $buffer .= $columnValue . ' & '; @@ -573,7 +573,7 @@ class ExportLatex extends ExportPlugin } $localBuffer = $colAs . "\000" . $type . "\000" - . (! $row->isNull ? __('No') : __('Yes')) + . ($row->isNull ? __('Yes') : __('No')) . "\000" . ($row->default ?? ($row->isNull ? 'NULL' : '')); if ($doRelation && $foreigners !== []) { diff --git a/src/Plugins/Export/ExportOdt.php b/src/Plugins/Export/ExportOdt.php index 9578886426..a53691da91 100644 --- a/src/Plugins/Export/ExportOdt.php +++ b/src/Plugins/Export/ExportOdt.php @@ -717,7 +717,7 @@ class ExportOdt extends ExportPlugin $definition .= '' . '' - . (! $column->isNull ? __('No') : __('Yes')) + . ($column->isNull ? __('Yes') : __('No')) . '' . ''; $definition .= '' diff --git a/src/Plugins/Export/ExportTexytext.php b/src/Plugins/Export/ExportTexytext.php index 66b1ec25f1..3c58e36c8a 100644 --- a/src/Plugins/Export/ExportTexytext.php +++ b/src/Plugins/Export/ExportTexytext.php @@ -557,7 +557,7 @@ class ExportTexytext extends ExportPlugin $definition = '|' . $fmtPre . htmlspecialchars($colAlias) . $fmtPost; $definition .= '|' . htmlspecialchars($type); - $definition .= '|' . (! $column->isNull ? __('No') : __('Yes')); + $definition .= '|' . ($column->isNull ? __('Yes') : __('No')); $definition .= '|' . htmlspecialchars($column->default ?? ($column->isNull ? 'NULL' : '')); return $definition; diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php index 597ab070ea..93e9cf29e0 100644 --- a/src/Plugins/Export/ExportXml.php +++ b/src/Plugins/Export/ExportXml.php @@ -199,11 +199,7 @@ class ExportXml extends ExportPlugin || isset($GLOBALS['xml_export_views']); $exportData = isset($GLOBALS['xml_export_contents']); - if ($GLOBALS['output_charset_conversion']) { - $charset = $GLOBALS['charset']; - } else { - $charset = 'utf-8'; - } + $charset = $GLOBALS['output_charset_conversion'] ? $GLOBALS['charset'] : 'utf-8'; $config = Config::getInstance(); $head = '' . "\n" @@ -269,11 +265,7 @@ class ExportXml extends ExportPlugin $isView = $dbi->getTable($GLOBALS['db'], $table) ->isView(); - if ($isView) { - $type = 'view'; - } else { - $type = 'table'; - } + $type = $isView ? 'view' : 'table'; if ($isView && ! isset($GLOBALS['xml_export_views'])) { continue; diff --git a/src/Plugins/Export/Helpers/Pdf.php b/src/Plugins/Export/Helpers/Pdf.php index 98ff46cd53..195ac0ab80 100644 --- a/src/Plugins/Export/Helpers/Pdf.php +++ b/src/Plugins/Export/Helpers/Pdf.php @@ -567,7 +567,7 @@ class Pdf extends PdfLib $data[] = $column->field; $data[] = $type; - $data[] = ! $column->isNull ? 'No' : 'Yes'; + $data[] = $column->isNull ? 'Yes' : 'No'; $data[] = $column->default ?? ($column->isNull ? 'NULL' : ''); $fieldName = $column->field; diff --git a/src/Plugins/Import/ImportCsv.php b/src/Plugins/Import/ImportCsv.php index 17c84c0464..40fd20e223 100644 --- a/src/Plugins/Import/ImportCsv.php +++ b/src/Plugins/Import/ImportCsv.php @@ -711,7 +711,7 @@ class ImportCsv extends AbstractImportCsv // logic to get table name from filename // if no table then use filename as table name - if (count($result) === 0) { + if ($result === []) { return $importFileName; } diff --git a/src/Plugins/Import/ImportXml.php b/src/Plugins/Import/ImportXml.php index e8390e4c79..b1894f6f6a 100644 --- a/src/Plugins/Import/ImportXml.php +++ b/src/Plugins/Import/ImportXml.php @@ -291,19 +291,12 @@ class ImportXml extends ImportPlugin unset($xml, $tempCells, $rows); /** - * Only build SQL from data if there is data present + * Only build SQL from data if there is data present. + * Set values to NULL if they were not present + * to maintain Import::buildSql() call integrity */ - if ($dataPresent) { - /** - * Set values to NULL if they were not present - * to maintain Import::buildSql() call integrity - */ - if (! isset($analyses)) { - $analyses = null; - if (! $structPresent) { - $create = null; - } - } + if ($dataPresent && $analyses === null && ! $structPresent) { + $create = null; } /* Set database name to the currently selected one, if applicable */ diff --git a/src/Plugins/Schema/Dia/RelationStatsDia.php b/src/Plugins/Schema/Dia/RelationStatsDia.php index faa9ca92b8..f27f9868df 100644 --- a/src/Plugins/Schema/Dia/RelationStatsDia.php +++ b/src/Plugins/Schema/Dia/RelationStatsDia.php @@ -106,10 +106,11 @@ class RelationStatsDia ++DiaRelationSchema::$objectId; // if source connection points and destination connection points are same then // don't draw that relation - if ($this->srcConnPointsRight == $this->destConnPointsRight) { - if ($this->srcConnPointsLeft == $this->destConnPointsLeft) { - return; - } + if ( + $this->srcConnPointsRight == $this->destConnPointsRight + && $this->srcConnPointsLeft == $this->destConnPointsLeft + ) { + return; } if ($showColor) { diff --git a/src/Plugins/Schema/Pdf/PdfRelationSchema.php b/src/Plugins/Schema/Pdf/PdfRelationSchema.php index 4817b3b08e..9cd8990fee 100644 --- a/src/Plugins/Schema/Pdf/PdfRelationSchema.php +++ b/src/Plugins/Schema/Pdf/PdfRelationSchema.php @@ -692,7 +692,7 @@ class PdfRelationSchema extends ExportRelationSchema $fieldName, $type, $attribute, - ! $row->isNull ? __('No') : __('Yes'), + $row->isNull ? __('Yes') : __('No'), $row->default ?? ($row->isNull ? 'NULL' : ''), $row->extra, $linksTo, diff --git a/src/Query/Compatibility.php b/src/Query/Compatibility.php index 4e89fbf2db..75279cfae3 100644 --- a/src/Query/Compatibility.php +++ b/src/Query/Compatibility.php @@ -7,6 +7,7 @@ namespace PhpMyAdmin\Query; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Util; +use function array_keys; use function in_array; use function is_string; use function strlen; @@ -26,7 +27,7 @@ class Compatibility */ public static function getISCompatForGetTablesFull(array $eachTables, string $eachDatabase): array { - foreach ($eachTables as $tableName => $tableInfo) { + foreach (array_keys($eachTables) as $tableName) { if (! isset($eachTables[$tableName]['Type']) && isset($eachTables[$tableName]['Engine'])) { // pma BC, same parts of PMA still uses 'Type' $eachTables[$tableName]['Type'] =& $eachTables[$tableName]['Engine']; @@ -83,7 +84,7 @@ class Compatibility public static function getISCompatForGetColumnsFull(array $columns, string $database, string $table): array { $ordinalPosition = 1; - foreach ($columns as $columnName => $columnInfo) { + foreach (array_keys($columns) as $columnName) { // Compatibility with INFORMATION_SCHEMA output $columns[$columnName]['COLUMN_NAME'] =& $columns[$columnName]['Field']; $columns[$columnName]['COLUMN_TYPE'] =& $columns[$columnName]['Type']; diff --git a/src/Replication/ReplicationInfo.php b/src/Replication/ReplicationInfo.php index c1b5930a8d..46dcca0aa7 100644 --- a/src/Replication/ReplicationInfo.php +++ b/src/Replication/ReplicationInfo.php @@ -127,7 +127,7 @@ final class ReplicationInfo * * @return mixed[] */ - private static function fill(array $status, string $key): array + private function fill(array $status, string $key): array { if (empty($status[0][$key])) { return []; @@ -148,8 +148,8 @@ final class ReplicationInfo return; } - $this->primaryInfo['Do_DB'] = self::fill($this->primaryStatus, 'Binlog_Do_DB'); - $this->primaryInfo['Ignore_DB'] = self::fill($this->primaryStatus, 'Binlog_Ignore_DB'); + $this->primaryInfo['Do_DB'] = $this->fill($this->primaryStatus, 'Binlog_Do_DB'); + $this->primaryInfo['Ignore_DB'] = $this->fill($this->primaryStatus, 'Binlog_Ignore_DB'); } /** @return mixed[] */ @@ -170,12 +170,12 @@ final class ReplicationInfo return; } - $this->replicaInfo['Do_DB'] = self::fill($this->replicaStatus, 'Replicate_Do_DB'); - $this->replicaInfo['Ignore_DB'] = self::fill($this->replicaStatus, 'Replicate_Ignore_DB'); - $this->replicaInfo['Do_Table'] = self::fill($this->replicaStatus, 'Replicate_Do_Table'); - $this->replicaInfo['Ignore_Table'] = self::fill($this->replicaStatus, 'Replicate_Ignore_Table'); - $this->replicaInfo['Wild_Do_Table'] = self::fill($this->replicaStatus, 'Replicate_Wild_Do_Table'); - $this->replicaInfo['Wild_Ignore_Table'] = self::fill($this->replicaStatus, 'Replicate_Wild_Ignore_Table'); + $this->replicaInfo['Do_DB'] = $this->fill($this->replicaStatus, 'Replicate_Do_DB'); + $this->replicaInfo['Ignore_DB'] = $this->fill($this->replicaStatus, 'Replicate_Ignore_DB'); + $this->replicaInfo['Do_Table'] = $this->fill($this->replicaStatus, 'Replicate_Do_Table'); + $this->replicaInfo['Ignore_Table'] = $this->fill($this->replicaStatus, 'Replicate_Ignore_Table'); + $this->replicaInfo['Wild_Do_Table'] = $this->fill($this->replicaStatus, 'Replicate_Wild_Do_Table'); + $this->replicaInfo['Wild_Ignore_Table'] = $this->fill($this->replicaStatus, 'Replicate_Wild_Ignore_Table'); } /** @return mixed[] */ diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index 503ed5e08d..dd80c22b5d 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -202,11 +202,7 @@ class Privileges */ public function extractPrivInfo(array|null $row = null, bool $enableHTML = false, bool $tablePrivs = false): array { - if ($tablePrivs) { - $grants = $this->getTableGrantsArray(); - } else { - $grants = $this->getGrantsArray(); - } + $grants = $tablePrivs ? $this->getTableGrantsArray() : $this->getGrantsArray(); if ($row !== null && isset($row['Table_priv'])) { $this->fillInTablePrivileges($row); diff --git a/src/Sql.php b/src/Sql.php index 88fe3a7b0e..c9b1e3f0e2 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -361,8 +361,7 @@ class Sql return (isset($statementInfo->parser) && $statementInfo->parser->errors === []) && ($_SESSION['tmpval']['max_rows'] !== 'all') - && ! ($statementInfo->isExport - || $statementInfo->isAnalyse) + && (! $statementInfo->isExport && ! $statementInfo->isAnalyse) && ($statementInfo->selectFrom || $statementInfo->isSubquery) && ! $statementInfo->limit; diff --git a/src/Table/ColumnsDefinition.php b/src/Table/ColumnsDefinition.php index 61c8531661..6d433baa93 100644 --- a/src/Table/ColumnsDefinition.php +++ b/src/Table/ColumnsDefinition.php @@ -459,11 +459,7 @@ final class ColumnsDefinition switch ($default) { case null: - if ($isNull) { - $metaDefault['DefaultType'] = 'NULL'; - } else { - $metaDefault['DefaultType'] = 'NONE'; - } + $metaDefault['DefaultType'] = $isNull ? 'NULL' : 'NONE'; break; case 'CURRENT_TIMESTAMP': diff --git a/src/Table/Search.php b/src/Table/Search.php index 62b184e4d7..d84a13a2ce 100644 --- a/src/Table/Search.php +++ b/src/Table/Search.php @@ -195,11 +195,7 @@ final class Search //Don't explode if this is already an array //(Case for (NOT) IN/BETWEEN.) - if (is_array($criteriaValues)) { - $values = $criteriaValues; - } else { - $values = explode(',', $criteriaValues); - } + $values = is_array($criteriaValues) ? $criteriaValues : explode(',', $criteriaValues); // quote values one by one $emptyKey = false; diff --git a/src/Table/Table.php b/src/Table/Table.php index 3c02a45022..e19577bcef 100644 --- a/src/Table/Table.php +++ b/src/Table/Table.php @@ -1221,11 +1221,7 @@ class Table implements Stringable $dbi->selectDb($sourceDb); $sourceTableObj = new Table($sourceTable, $sourceDb, $dbi); - if ($sourceTableObj->isView()) { - $sqlDropQuery = 'DROP VIEW'; - } else { - $sqlDropQuery = 'DROP TABLE'; - } + $sqlDropQuery = $sourceTableObj->isView() ? 'DROP VIEW' : 'DROP TABLE'; $sqlDropQuery .= ' ' . $source; $dbi->query($sqlDropQuery); @@ -1470,11 +1466,7 @@ class Table implements Stringable continue; } - if ($fullName) { - $possibleColumn = $this->getFullName($backquoted) . '.'; - } else { - $possibleColumn = ''; - } + $possibleColumn = $fullName ? $this->getFullName($backquoted) . '.' : ''; if ($backquoted) { $possibleColumn .= Util::backquote($index[0]); diff --git a/src/Types.php b/src/Types.php index c0f58646ca..5b04d99b50 100644 --- a/src/Types.php +++ b/src/Types.php @@ -175,11 +175,7 @@ class Types $html = ''; foreach ($this->getTypeOperators($type, $null) as $fc) { - if ($selectedOperator !== null && $selectedOperator === $fc) { - $selected = ' selected="selected"'; - } else { - $selected = ''; - } + $selected = $selectedOperator !== null && $selectedOperator === $fc ? ' selected="selected"' : ''; $html .= '