Skip to content

Commit

Permalink
Merge pull request #19501 from MauricioFauth/error-global-variable
Browse files Browse the repository at this point in the history
Remove error global variable
  • Loading branch information
MauricioFauth authored Jan 7, 2025
2 parents a6350ad + 4b30f0e commit 17c477b
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 191 deletions.
66 changes: 0 additions & 66 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2964,12 +2964,6 @@ parameters:
count: 1
path: src/Controllers/Import/ImportController.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 5
path: src/Controllers/Import/ImportController.php

-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
Expand All @@ -2994,12 +2988,6 @@ parameters:
count: 2
path: src/Controllers/Import/ImportController.php

-
message: '#^Parameter \#5 \$exit of static method PhpMyAdmin\\Html\\Generator\:\:mysqlDie\(\) expects bool, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Import/ImportController.php

-
message: '#^Result of \|\| is always true\.$#'
identifier: booleanOr.alwaysTrue
Expand Down Expand Up @@ -3255,12 +3243,6 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: '#^Only booleans are allowed in an if condition, PhpMyAdmin\\Message\|string given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Controllers/Preferences/ManageController.php

-
message: '#^Only numeric types are allowed in \+, int\<0, max\>\|false given on the left side\.$#'
identifier: plus.leftNonNumeric
Expand Down Expand Up @@ -9363,18 +9345,6 @@ parameters:
count: 1
path: src/Import/Import.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Import/Import.php

-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Import/Import.php

-
message: '#^Parameter \#1 \$precision of static method PhpMyAdmin\\Import\\DecimalSize\:\:fromPrecisionAndScale\(\) expects int, int\|PhpMyAdmin\\Import\\DecimalSize given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -12846,12 +12816,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportCsv.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportCsv.php

-
message: '#^Parameter \#1 \$columnNames of method PhpMyAdmin\\Plugins\\Import\\ImportCsv\:\:getColumnNames\(\) expects list\<string\>, array\|null given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -12894,12 +12858,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportMediawiki.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportMediawiki.php

-
message: '#^Cannot access property \$body on SimpleXMLElement\|null\.$#'
identifier: property.nonObject
Expand Down Expand Up @@ -12960,12 +12918,6 @@ parameters:
count: 2
path: src/Plugins/Import/ImportOds.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportOds.php

-
message: '#^Parameter \#1 \$cellAttrs of method PhpMyAdmin\\Plugins\\Import\\ImportOds\:\:getValue\(\) expects SimpleXMLElement, \(SimpleXMLElement\|null\) given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -13086,18 +13038,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportSql.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 2
path: src/Plugins/Import/ImportSql.php

-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Plugins/Import/ImportSql.php

-
message: '#^Parameter \#1 \$delimiter of method PhpMyAdmin\\SqlParser\\Utils\\BufferedQuery\:\:setDelimiter\(\) expects string, mixed given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -13158,12 +13098,6 @@ parameters:
count: 4
path: src/Plugins/Import/ImportXml.php

-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportXml.php

-
message: '#^Method PhpMyAdmin\\Plugins\\Import\\ShapeFileImport\:\:readSHP\(\) never returns false so it can be removed from the return type\.$#'
identifier: return.unusedType
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1918,9 +1918,6 @@
<code><![CDATA[is_array($_FILES['import_file'])]]></code>
<code><![CDATA[is_string($_FILES['import_file']['tmp_name'])]]></code>
</RedundantCondition>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$GLOBALS['error']]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Controllers/Preferences/NavigationController.php">
<DeprecatedMethod>
Expand Down Expand Up @@ -7529,9 +7526,6 @@
<code><![CDATA[$values[count($values) - 1]]]></code>
<code><![CDATA[$values[count($values) - 1]]]></code>
</InvalidArrayOffset>
<MixedAssignment>
<code><![CDATA[$GLOBALS['error']]]></code>
</MixedAssignment>
<PossiblyNullOperand>
<code><![CDATA[$ch]]></code>
</PossiblyNullOperand>
Expand Down
19 changes: 9 additions & 10 deletions src/Controllers/Import/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function __invoke(ServerRequest $request): Response
$GLOBALS['display_query'] ??= null;
$GLOBALS['ajax_reload'] ??= null;
$GLOBALS['import_text'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['result'] ??= null;

ImportSettings::$charsetOfFile = $request->getParsedBodyParamAsString('charset_of_file', '');
Expand Down Expand Up @@ -240,7 +239,7 @@ public function __invoke(ServerRequest $request): Response

// set default values
ImportSettings::$timeoutPassed = false;
$GLOBALS['error'] = false;
Import::$hasError = false;
ImportSettings::$readMultiply = 1;
ImportSettings::$finished = false;
ImportSettings::$offset = 0;
Expand Down Expand Up @@ -333,7 +332,7 @@ public function __invoke(ServerRequest $request): Response
}

ImportSettings::$runQuery = false;
$GLOBALS['error'] = true; // this is kind of hack to skip processing the query
Import::$hasError = true; // this is kind of hack to skip processing the query
break;
}
}
Expand Down Expand Up @@ -394,7 +393,7 @@ public function __invoke(ServerRequest $request): Response

// Do we have file to import?
if (ImportSettings::$importFile !== 'none' && ! $GLOBALS['error']) {
if (ImportSettings::$importFile !== 'none' && ! Import::$hasError) {

Check warning on line 396 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ ImportSettings::$importFile = 'none'; } // Do we have file to import? - if (ImportSettings::$importFile !== 'none' && !Import::$hasError) { + if (ImportSettings::$importFile !== 'none' && Import::$hasError) { /** * Handle file compression */

Check warning on line 396 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ ImportSettings::$importFile = 'none'; } // Do we have file to import? - if (ImportSettings::$importFile !== 'none' && !Import::$hasError) { + if (!(ImportSettings::$importFile !== 'none') && Import::$hasError) { /** * Handle file compression */
/**
* Handle file compression
*/
Expand Down Expand Up @@ -431,7 +430,7 @@ public function __invoke(ServerRequest $request): Response

return $this->response->response();
}
} elseif (! $GLOBALS['error'] && empty($GLOBALS['import_text'])) {
} elseif (! Import::$hasError && empty($GLOBALS['import_text'])) {

Check warning on line 433 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ $this->response->addHTML($errorMessage->getDisplay()); return $this->response->response(); } - } elseif (!Import::$hasError && empty($GLOBALS['import_text'])) { + } elseif (Import::$hasError && empty($GLOBALS['import_text'])) { Current::$message = Message::error(__('No data was received to import. Either no file name was ' . 'submitted, or the file size exceeded the maximum size permitted ' . 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].')); $_SESSION['Import_message']['message'] = Current::$message->getDisplay(); $this->response->setRequestStatus(false);

Check warning on line 433 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ $this->response->addHTML($errorMessage->getDisplay()); return $this->response->response(); } - } elseif (!Import::$hasError && empty($GLOBALS['import_text'])) { + } elseif (Import::$hasError && !empty($GLOBALS['import_text'])) { Current::$message = Message::error(__('No data was received to import. Either no file name was ' . 'submitted, or the file size exceeded the maximum size permitted ' . 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].')); $_SESSION['Import_message']['message'] = Current::$message->getDisplay(); $this->response->setRequestStatus(false);
Current::$message = Message::error(
__(
'No data was received to import. Either no file name was ' .
Expand Down Expand Up @@ -463,7 +462,7 @@ public function __invoke(ServerRequest $request): Response
}

// Something to skip? (because timeout has passed)
if (! $GLOBALS['error'] && $request->hasBodyParam('skip')) {
if (! Import::$hasError && $request->hasBodyParam('skip')) {

Check warning on line 465 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ $resetCharset = true; } // Something to skip? (because timeout has passed) - if (!Import::$hasError && $request->hasBodyParam('skip')) { + if (Import::$hasError && $request->hasBodyParam('skip')) { $originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip'); while ($skip > 0 && !ImportSettings::$finished) { $this->import->getNextChunk($importHandle ?? null, min($skip, ImportSettings::$readLimit));

Check warning on line 465 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $resetCharset = true; } // Something to skip? (because timeout has passed) - if (!Import::$hasError && $request->hasBodyParam('skip')) { + if (!Import::$hasError || $request->hasBodyParam('skip')) { $originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip'); while ($skip > 0 && !ImportSettings::$finished) { $this->import->getNextChunk($importHandle ?? null, min($skip, ImportSettings::$readLimit));

Check warning on line 465 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ $resetCharset = true; } // Something to skip? (because timeout has passed) - if (!Import::$hasError && $request->hasBodyParam('skip')) { + if (Import::$hasError && !$request->hasBodyParam('skip')) { $originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip'); while ($skip > 0 && !ImportSettings::$finished) { $this->import->getNextChunk($importHandle ?? null, min($skip, ImportSettings::$readLimit));

Check warning on line 465 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ $resetCharset = true; } // Something to skip? (because timeout has passed) - if (!Import::$hasError && $request->hasBodyParam('skip')) { + if (!(!Import::$hasError && $request->hasBodyParam('skip'))) { $originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip'); while ($skip > 0 && !ImportSettings::$finished) { $this->import->getNextChunk($importHandle ?? null, min($skip, ImportSettings::$readLimit));

Check warning on line 465 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $resetCharset = true; } // Something to skip? (because timeout has passed) - if (!Import::$hasError && $request->hasBodyParam('skip')) { + if (!Import::$hasError && !$request->hasBodyParam('skip')) { $originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip'); while ($skip > 0 && !ImportSettings::$finished) { $this->import->getNextChunk($importHandle ?? null, min($skip, ImportSettings::$readLimit));
$originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip');
while ($skip > 0 && ! ImportSettings::$finished) {
$this->import->getNextChunk(
Expand All @@ -482,7 +481,7 @@ public function __invoke(ServerRequest $request): Response
// and complete valid sql statement (which affected for rows)
$queriesToBeExecuted = [];

if (! $GLOBALS['error']) {
if (! Import::$hasError) {
$importPlugin = new ($importFormat->getClassName());

$importPlugin->setImportOptions($request);
Expand Down Expand Up @@ -513,10 +512,10 @@ public function __invoke(ServerRequest $request): Response
if ($idBookmark !== 0 && $actionBookmark === 2) {
Current::$message = Message::success(__('The bookmark has been deleted.'));
$GLOBALS['display_query'] = $GLOBALS['import_text'];
$GLOBALS['error'] = false; // unset error marker, it was used just to skip processing
Import::$hasError = false; // unset error marker, it was used just to skip processing
} elseif ($idBookmark !== 0 && $actionBookmark === 1) {
Current::$message = Message::notice(__('Showing bookmark'));
} elseif (ImportSettings::$finished && ! $GLOBALS['error']) {
} elseif (ImportSettings::$finished && ! Import::$hasError) {

Check warning on line 518 in src/Controllers/Import/ImportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ // unset error marker, it was used just to skip processing } elseif ($idBookmark !== 0 && $actionBookmark === 1) { Current::$message = Message::notice(__('Showing bookmark')); - } elseif (ImportSettings::$finished && !Import::$hasError) { + } elseif (ImportSettings::$finished && Import::$hasError) { // Do not display the query with message, we do it separately $GLOBALS['display_query'] = ';'; if (ImportSettings::$importType !== 'query') {
// Do not display the query with message, we do it separately
$GLOBALS['display_query'] = ';';
if (ImportSettings::$importType !== 'query') {
Expand Down Expand Up @@ -604,7 +603,7 @@ public function __invoke(ServerRequest $request): Response
}

foreach (ImportSettings::$failedQueries as $die) {
Generator::mysqlDie($die['error'], $die['sql'], false, $GLOBALS['errorUrl'], $GLOBALS['error']);
Generator::mysqlDie($die['error'], $die['sql'], false, $GLOBALS['errorUrl'], Import::$hasError);
}

if (ImportSettings::$goSql) {
Expand Down
8 changes: 2 additions & 6 deletions src/Controllers/Preferences/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;

$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);

Expand All @@ -50,7 +48,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
Expand All @@ -66,8 +64,6 @@ public function __invoke(ServerRequest $request): Response

return $this->response->response();
}

$GLOBALS['error'] = $result;
}

$relationParameters = $this->relation->getRelationParameters();
Expand All @@ -81,7 +77,7 @@ public function __invoke(ServerRequest $request): Response
$formErrors = $formDisplay->displayErrors();

$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(
Expand Down
8 changes: 2 additions & 6 deletions src/Controllers/Preferences/FeaturesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;

$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);

Expand All @@ -50,7 +48,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
Expand All @@ -66,8 +64,6 @@ public function __invoke(ServerRequest $request): Response

return $this->response->response();
}

$GLOBALS['error'] = $result;
}

$relationParameters = $this->relation->getRelationParameters();
Expand All @@ -81,7 +77,7 @@ public function __invoke(ServerRequest $request): Response
$formErrors = $formDisplay->displayErrors();

$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(
Expand Down
8 changes: 2 additions & 6 deletions src/Controllers/Preferences/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;

$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);

Expand All @@ -50,7 +48,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
Expand All @@ -66,8 +64,6 @@ public function __invoke(ServerRequest $request): Response

return $this->response->response();
}

$GLOBALS['error'] = $result;
}

$relationParameters = $this->relation->getRelationParameters();
Expand All @@ -81,7 +77,7 @@ public function __invoke(ServerRequest $request): Response
$formErrors = $formDisplay->displayErrors();

$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(
Expand Down
8 changes: 2 additions & 6 deletions src/Controllers/Preferences/MainPanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;

$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);

Expand All @@ -50,7 +48,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
Expand All @@ -66,8 +64,6 @@ public function __invoke(ServerRequest $request): Response

return $this->response->response();
}

$GLOBALS['error'] = $result;
}

$relationParameters = $this->relation->getRelationParameters();
Expand All @@ -81,7 +77,7 @@ public function __invoke(ServerRequest $request): Response
$formErrors = $formDisplay->displayErrors();

$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(
Expand Down
Loading

0 comments on commit 17c477b

Please sign in to comment.