Merge pull request #18809 from kamil-tekiela/Simplify-code

Simplify code
This commit is contained in:
Maurício Meneghini Fauth 2023-11-28 13:41:33 -03:00 committed by GitHub
commit 54631fa63b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 159 additions and 328 deletions

View File

@ -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

View File

@ -447,6 +447,7 @@
<code>$_POST[$key]</code>
<code>$_POST[$key]</code>
<code>$_POST[$key]</code>
<code>$_POST[$key]</code>
</MixedArrayOffset>
<MixedAssignment>
<code>$canonicalPath</code>
@ -4712,7 +4713,6 @@
<code><![CDATA[$row['col_attribute']]]></code>
<code><![CDATA[$row['col_attribute']]]></code>
<code><![CDATA[$row['col_extra']]]></code>
<code><![CDATA[$row['col_extra']]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$centralListTable</code>
@ -10706,17 +10706,11 @@
<MixedAssignment>
<code>$colCollation</code>
<code>$colType</code>
<code>$columnInfo</code>
<code>$tableInfo</code>
</MixedAssignment>
<MixedReturnTypeCoercion>
<code>$eachTables</code>
<code>mixed[][]</code>
</MixedReturnTypeCoercion>
<UnusedForeachValue>
<code>$columnInfo</code>
<code>$tableInfo</code>
</UnusedForeachValue>
</file>
<file src="src/Query/Utilities.php">
<DeprecatedMethod>
@ -14799,6 +14793,9 @@
<code>$result</code>
<code>$result</code>
</MixedAssignment>
<PossiblyInvalidCast>
<code>$value</code>
</PossiblyInvalidCast>
<PossiblyUnusedMethod>
<code>dataProviderConfigValueInsertRows</code>
<code>providerForTestGetSpecialCharsForInsertingMode</code>

View File

@ -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);

View File

@ -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':

View File

@ -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];
}
}

View File

@ -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);

View File

@ -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] !== '') {

View File

@ -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']);

View File

@ -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;

View File

@ -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()) {

View File

@ -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'],

View File

@ -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;
}

View File

@ -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');

View File

@ -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;
}
/**

View File

@ -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,

View File

@ -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);

View File

@ -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' : '';
}
}

View File

@ -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';
}
}

View File

@ -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;

View File

@ -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'])) {

View File

@ -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];

View File

@ -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);
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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;

View File

@ -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'] = [];

View File

@ -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;
}

View File

@ -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 = '<span class="dbItemControls">'
. '<a href="' . Url::getFromRoute('/navigation') . '" data-post="'
. Url::getCommon($params, '', false) . '"'
. ' class="showUnhide ajax">'
. Generator::getImage(
'show',
__('Show hidden items'),
)
. '</a></span>';
}
if ($navigationItemsHidingFeature !== null && $this->hiddenCount > 0) {
$params = ['showUnhideDialog' => true, 'dbName' => $this->realName];
$ret = '<span class="dbItemControls">'
. '<a href="' . Url::getFromRoute('/navigation') . '" data-post="'
. Url::getCommon($params, '', false) . '"'
. ' class="showUnhide ajax">'
. Generator::getImage(
'show',
__('Show hidden items'),
)
. '</a></span>';
}
return $ret;

View File

@ -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];
}
}

View File

@ -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.');
}

View File

@ -603,7 +603,7 @@ class ExportHtmlword extends ExportPlugin
. htmlspecialchars($colAlias) . $fmtPost . '</td>';
$definition .= '<td class="print">' . htmlspecialchars($type) . '</td>';
$definition .= '<td class="print">'
. (! $column->isNull ? __('No') : __('Yes'))
. ($column->isNull ? __('Yes') : __('No'))
. '</td>';
$definition .= '<td class="print">'
. htmlspecialchars($column->default ?? ($column->isNull ? 'NULL' : ''))

View File

@ -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 !== []) {

View File

@ -717,7 +717,7 @@ class ExportOdt extends ExportPlugin
$definition .= '<table:table-cell office:value-type="string">'
. '<text:p>'
. (! $column->isNull ? __('No') : __('Yes'))
. ($column->isNull ? __('Yes') : __('No'))
. '</text:p>'
. '</table:table-cell>';
$definition .= '<table:table-cell office:value-type="string">'

View File

@ -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;

View File

@ -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 = '<?xml version="1.0" encoding="' . $charset . '"?>' . "\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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 */

View File

@ -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) {

View File

@ -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,

View File

@ -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'];

View File

@ -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[] */

View File

@ -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);

View File

@ -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;

View File

@ -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':

View File

@ -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;

View File

@ -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]);

View File

@ -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 .= '<option value="' . htmlspecialchars($fc) . '"'
. $selected . '>'

View File

@ -16,9 +16,9 @@ use function trim;
class UniqueCondition
{
private string $whereClause;
private bool $clauseIsUnique;
private bool $clauseIsUnique = true;
/** @var array<string, string> */
private array $conditionArray;
private array $conditionArray = [];
/**
* Function to generate unique condition for specified row.
@ -129,9 +129,6 @@ class UniqueCondition
// Correction University of Virginia 19991216:
// prefer primary or unique keys for condition,
// but use conjunction of all values if no primary key
$this->clauseIsUnique = true;
$this->conditionArray = [];
if ($primaryKey !== '') {
$preferredCondition = $primaryKey;
$this->conditionArray = $primaryKeyArray;

View File

@ -81,11 +81,7 @@ class VersionInformation
public function versionToInt(string $version): int
{
$parts = explode('-', $version);
if (count($parts) > 1) {
$suffix = $parts[1];
} else {
$suffix = '';
}
$suffix = count($parts) > 1 ? $parts[1] : '';
$parts = explode('.', $parts[0]);

View File

@ -34,7 +34,6 @@ use function mb_substr;
use function md5;
use function password_verify;
use function sprintf;
use function strval;
use const MYSQLI_PRI_KEY_FLAG;
use const MYSQLI_TYPE_DECIMAL;
@ -2717,7 +2716,7 @@ class InsertEditTest extends AbstractTestCase
}
if (is_object($value) || is_scalar($value)) {
return strval($value);
return (string) $value;
}
return '';

View File

@ -123,11 +123,7 @@ class DummyResult 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;

View File

@ -356,59 +356,52 @@ class TrackerTest extends AbstractTestCase
*/
public static function parseQueryData(): array
{
// query
// type
// identifier
// table name
// db (optional)
// table name after rename (optional)
$query = [];
/* TODO: Should test fail when USE is in conjunction with * identifiers?
$query[] = array(
" - USE db1;\n- CREATE VIEW db1.v AS SELECT * FROM t;",
"DDL",
"CREATE VIEW",
"v",
"db1"
);
*/
$query[] = ['CREATE VIEW v AS SELECT * FROM t;', 'DDL', 'CREATE VIEW', 'v'];
$query[] = ['ALTER VIEW db1.v AS SELECT col1, col2, col3, col4 FROM t', 'DDL', 'ALTER VIEW', 'v'];
$query[] = ['DROP VIEW db1.v;', 'DDL', 'DROP VIEW', 'v'];
$query[] = ['DROP VIEW IF EXISTS db1.v;', 'DDL', 'DROP VIEW', 'v'];
$query[] = ['CREATE DATABASE db1;', 'DDL', 'CREATE DATABASE', '', 'db1'];
$query[] = ['ALTER DATABASE db1;', 'DDL', 'ALTER DATABASE', ''];
$query[] = ['DROP DATABASE db1;', 'DDL', 'DROP DATABASE', '', 'db1'];
$query[] = ['CREATE TABLE db1.t1 (c1 INT);', 'DDL', 'CREATE TABLE', 't1'];
$query[] = ['ALTER TABLE db1.t1 ADD c2 TEXT;', 'DDL', 'ALTER TABLE', 't1'];
$query[] = ['DROP TABLE db1.t1', 'DDL', 'DROP TABLE', 't1'];
$query[] = ['DROP TABLE IF EXISTS db1.t1', 'DDL', 'DROP TABLE', 't1'];
$query[] = ['CREATE INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'];
$query[] = ['CREATE UNIQUE INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'];
$query[] = ['CREATE SPATIAL INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'];
$query[] = ['DROP INDEX ind ON db1.t1;', 'DDL', 'DROP INDEX', 't1'];
$query[] = ['RENAME TABLE db1.t1 TO db1.t2', 'DDL', 'RENAME TABLE', 't1', '', 't2'];
$query[] = ['UPDATE db1.t1 SET a = 2', 'DML', 'UPDATE', 't1'];
$query[] = ['INSERT INTO db1.t1 (a, b, c) VALUES(1, 2, 3)', 'DML', 'INSERT', 't1'];
$query[] = ['DELETE FROM db1.t1', 'DML', 'DELETE', 't1'];
$query[] = ['TRUNCATE db1.t1', 'DML', 'TRUNCATE', 't1'];
$query[] = [
'create table event(' . "\n"
. 'eventID varchar(10) not null,' . "\n"
. 'b char(30),' . "\n"
. 'c varchar(20),' . "\n"
. 'd TIME,' . "\n"
. 'e Date,' . "\n"
. 'f int,' . "\n"
. 'g char(70),' . "\n"
. 'h char(90),' . "\n"
. 'primary key(eventID)' . "\n"
. ')' . "\n",
'DDL',
'CREATE TABLE',
null,// switch this to 'event' when sql-parse is fixed
return [
/* TODO: Should test fail when USE is in conjunction with * identifiers?
$query[] = array(
" - USE db1;\n- CREATE VIEW db1.v AS SELECT * FROM t;",
"DDL",
"CREATE VIEW",
"v",
"db1"
);
*/
['CREATE VIEW v AS SELECT * FROM t;', 'DDL', 'CREATE VIEW', 'v'],
['ALTER VIEW db1.v AS SELECT col1, col2, col3, col4 FROM t', 'DDL', 'ALTER VIEW', 'v'],
['DROP VIEW db1.v;', 'DDL', 'DROP VIEW', 'v'],
['DROP VIEW IF EXISTS db1.v;', 'DDL', 'DROP VIEW', 'v'],
['CREATE DATABASE db1;', 'DDL', 'CREATE DATABASE', '', 'db1'],
['ALTER DATABASE db1;', 'DDL', 'ALTER DATABASE', ''],
['DROP DATABASE db1;', 'DDL', 'DROP DATABASE', '', 'db1'],
['CREATE TABLE db1.t1 (c1 INT);', 'DDL', 'CREATE TABLE', 't1'],
['ALTER TABLE db1.t1 ADD c2 TEXT;', 'DDL', 'ALTER TABLE', 't1'],
['DROP TABLE db1.t1', 'DDL', 'DROP TABLE', 't1'],
['DROP TABLE IF EXISTS db1.t1', 'DDL', 'DROP TABLE', 't1'],
['CREATE INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'],
['CREATE UNIQUE INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'],
['CREATE SPATIAL INDEX ind ON db1.t1 (c2(10));', 'DDL', 'CREATE INDEX', 't1'],
['DROP INDEX ind ON db1.t1;', 'DDL', 'DROP INDEX', 't1'],
['RENAME TABLE db1.t1 TO db1.t2', 'DDL', 'RENAME TABLE', 't1', '', 't2'],
['UPDATE db1.t1 SET a = 2', 'DML', 'UPDATE', 't1'],
['INSERT INTO db1.t1 (a, b, c) VALUES(1, 2, 3)', 'DML', 'INSERT', 't1'],
['DELETE FROM db1.t1', 'DML', 'DELETE', 't1'],
['TRUNCATE db1.t1', 'DML', 'TRUNCATE', 't1'],
[
'create table event(' . "\n"
. 'eventID varchar(10) not null,' . "\n"
. 'b char(30),' . "\n"
. 'c varchar(20),' . "\n"
. 'd TIME,' . "\n"
. 'e Date,' . "\n"
. 'f int,' . "\n"
. 'g char(70),' . "\n"
. 'h char(90),' . "\n"
. 'primary key(eventID)' . "\n"
. ')' . "\n",
'DDL',
'CREATE TABLE',
null,// switch this to 'event' when sql-parse is fixed
],
];
return $query;
}
}