Skip to content

Commit

Permalink
Remove $route global
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Jan 27, 2022
1 parent ef6dbe0 commit 47e81a5
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 45 deletions.
4 changes: 2 additions & 2 deletions index.php
Expand Up @@ -35,9 +35,9 @@

require AUTOLOAD_FILE;

global $route, $containerBuilder;
global $containerBuilder;

Common::run();

$dispatcher = Routing::getDispatcher();
Routing::callControllerForRoute(Common::getRequest(), $route, $dispatcher, $containerBuilder);
Routing::callControllerForRoute(Common::getRequest(), Routing::getCurrentRoute(), $dispatcher, $containerBuilder);
2 changes: 1 addition & 1 deletion libraries/classes/Common.php
Expand Up @@ -81,7 +81,7 @@ final class Common
public static function run(): void
{
global $containerBuilder, $errorHandler, $config, $server, $dbi;
global $lang, $cfg, $isConfigLoading, $auth_plugin, $route, $theme;
global $lang, $cfg, $isConfigLoading, $auth_plugin, $theme;
global $urlParams, $isMinimumCommon, $sql_query, $token_mismatch;

$request = self::getRequest();
Expand Down
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -13,6 +13,7 @@
use PhpMyAdmin\File;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\UserPreferences;
Expand Down Expand Up @@ -67,7 +68,9 @@ public function __construct(
public function __invoke(): void
{
global $cf, $error, $filename, $json, $lang;
global $new_config, $return_url, $form_display, $all_ok, $params, $query, $route;
global $new_config, $return_url, $form_display, $all_ok, $params, $query;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
5 changes: 4 additions & 1 deletion libraries/classes/Controllers/Preferences/SqlController.php
Expand Up @@ -10,6 +10,7 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -44,7 +45,9 @@ public function __construct(

public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server, $route;
global $cfg, $cf, $error, $tabHash, $hash, $server;

$route = Routing::getCurrentRoute();

$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
Expand Down
Expand Up @@ -8,6 +8,7 @@
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;

Expand All @@ -27,7 +28,9 @@ public function __construct(ResponseRenderer $response, Template $template, Rela

public function __invoke(): void
{
global $cfg, $route;
global $cfg;

$route = Routing::getCurrentRoute();

$relationParameters = $this->relation->getRelationParameters();

Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Table/RelationController.php
Expand Up @@ -12,6 +12,7 @@
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Index;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function __construct(
*/
public function __invoke(): void
{
global $route;
$route = Routing::getCurrentRoute();

$options = [
'CASCADE' => 'CASCADE',
Expand Down
5 changes: 4 additions & 1 deletion libraries/classes/Controllers/Table/StructureController.php
Expand Up @@ -21,6 +21,7 @@
use PhpMyAdmin\Partitioning\Partition;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\StorageEngine;
use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
Expand Down Expand Up @@ -164,7 +165,9 @@ protected function displayStructure(
array $columns_with_index,
bool $isSystemSchema
) {
global $route, $tbl_is_view, $tbl_storage_engine;
global $tbl_is_view, $tbl_storage_engine;

$route = Routing::getCurrentRoute();

// prepare comments
$comments_map = [];
Expand Down
6 changes: 2 additions & 4 deletions libraries/classes/Footer.php
Expand Up @@ -140,12 +140,10 @@ public function getDebugMessage(): string
*/
public function getSelfUrl(): string
{
global $route, $db, $table, $server;
global $db, $table, $server;

$params = [];
if (isset($route)) {
$params['route'] = $route;
}
$params['route'] = Routing::getCurrentRoute();

if (isset($db) && strlen($db) > 0) {
$params['db'] = $db;
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Menu.php
Expand Up @@ -220,7 +220,7 @@ private function getBreadcrumbs(): string
*/
private function getTableTabs(): array
{
global $route;
$route = Routing::getCurrentRoute();

$isSystemSchema = Utilities::isSystemSchema($this->db);
$tableIsView = $this->dbi->getTable($this->db, $this->table)
Expand Down Expand Up @@ -342,7 +342,7 @@ private function getTableTabs(): array
*/
private function getDbTabs(): array
{
global $route;
$route = Routing::getCurrentRoute();

$isSystemSchema = Utilities::isSystemSchema($this->db);
$numTables = count($this->dbi->getTables($this->db));
Expand Down Expand Up @@ -459,7 +459,7 @@ private function getDbTabs(): array
*/
private function getServerTabs(): array
{
global $route;
$route = Routing::getCurrentRoute();

$isSuperUser = $this->dbi->isSuperUser();
$isCreateOrGrantUser = $this->dbi->isGrantUser() || $this->dbi->isCreateUser();
Expand Down
13 changes: 4 additions & 9 deletions libraries/classes/Plugins/Auth/AuthenticationCookie.php
Expand Up @@ -13,6 +13,7 @@
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Server\Select;
use PhpMyAdmin\Session;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -63,7 +64,7 @@ class AuthenticationCookie extends AuthenticationPlugin
*/
public function showLoginForm(): bool
{
global $conn_error, $route;
global $conn_error;

$response = ResponseRenderer::getInstance();

Expand Down Expand Up @@ -147,9 +148,7 @@ public function showLoginForm(): bool
}

$_form_params = [];
if (isset($route)) {
$_form_params['route'] = $route;
}
$_form_params['route'] = Routing::getCurrentRoute();

if (strlen($GLOBALS['db'])) {
$_form_params['db'] = $GLOBALS['db'];
Expand Down Expand Up @@ -455,8 +454,6 @@ public function storeCredentials(): bool
*/
public function rememberCredentials(): void
{
global $route;

// Name and password cookies need to be refreshed each time
// Duration = one month for username
$this->storeUsernameCookie($this->user);
Expand All @@ -470,9 +467,7 @@ public function rememberCredentials(): void

// any parameters to pass?
$url_params = [];
if (isset($route)) {
$url_params['route'] = $route;
}
$url_params['route'] = Routing::getCurrentRoute();

if (strlen($GLOBALS['db']) > 0) {
$url_params['db'] = $GLOBALS['db'];
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Server/Privileges.php
Expand Up @@ -19,6 +19,7 @@
use PhpMyAdmin\Message;
use PhpMyAdmin\Query\Compatibility;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
Expand Down Expand Up @@ -3710,7 +3711,7 @@ private function getRoutinePrivileges(

public function getFormForChangePassword(string $username, string $hostname, bool $editOthers): string
{
global $route;
$route = Routing::getCurrentRoute();

$isPrivileges = $route === '/server/privileges';

Expand Down
15 changes: 3 additions & 12 deletions psalm-baseline.xml
Expand Up @@ -2,11 +2,8 @@
<files psalm-version="4.18.1@dda05fa913f4dc6eb3386f2f7ce5a45d37a71bcb">
<file src="index.php">
<InvalidGlobal occurrences="1">
<code>global $route, $containerBuilder;</code>
<code>global $containerBuilder;</code>
</InvalidGlobal>
<MixedArgument occurrences="1">
<code>$route</code>
</MixedArgument>
</file>
<file src="js/messages.php">
<UnusedVariable occurrences="1">
Expand Down Expand Up @@ -6444,11 +6441,10 @@
<MixedArgumentTypeCoercion occurrences="1">
<code>$params</code>
</MixedArgumentTypeCoercion>
<MixedAssignment occurrences="8">
<MixedAssignment occurrences="7">
<code>$info</code>
<code>$params['checkprivsdb']</code>
<code>$params['checkprivstable']</code>
<code>$params['route']</code>
<code>$params['server']</code>
<code>$params['single_table']</code>
<code>$params['viewing_mode']</code>
Expand Down Expand Up @@ -9069,18 +9065,14 @@
<code>$serverCookie</code>
<code>$tmp_host</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="1">
<code>$url_params</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="1">
<code>$_SESSION['browser_access_time'][$key]</code>
</MixedArrayAccess>
<MixedArrayOffset occurrences="1">
<code>$_SESSION['browser_access_time'][$key]</code>
</MixedArrayOffset>
<MixedAssignment occurrences="14">
<MixedAssignment occurrences="12">
<code>$GLOBALS['pma_auth_server']</code>
<code>$_form_params['route']</code>
<code>$captchaSiteVerifyURL</code>
<code>$captchaSiteVerifyURL</code>
<code>$key</code>
Expand All @@ -9091,7 +9083,6 @@
<code>$serverCookie</code>
<code>$this-&gt;password</code>
<code>$tmp_host</code>
<code>$url_params['route']</code>
<code>$value</code>
</MixedAssignment>
<MixedMethodCall occurrences="6">
Expand Down
4 changes: 1 addition & 3 deletions test/classes/Server/PrivilegesTest.php
Expand Up @@ -1817,11 +1817,9 @@ public function testDeleteUser(): void

public function testGetFormForChangePassword(): void
{
global $route;

$username = 'pma_username';
$hostname = 'pma_hostname';
$route = '/server/privileges';
$_GET['route'] = '/server/privileges';

$html = $this->serverPrivileges->getFormForChangePassword($username, $hostname, false);

Expand Down

0 comments on commit 47e81a5

Please sign in to comment.