Skip to content

Commit 5acfb45

Browse files
committed
Fix some errors in Common class found by Psalm
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent f7f8722 commit 5acfb45

File tree

2 files changed

+19
-60
lines changed

2 files changed

+19
-60
lines changed

libraries/classes/Common.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ final class Common
8585
public static function run(): void
8686
{
8787
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
88-
$GLOBALS['errorHandler'] = $GLOBALS['errorHandler'] ?? null;
89-
$GLOBALS['config'] = $GLOBALS['config'] ?? null;
9088
$GLOBALS['server'] = $GLOBALS['server'] ?? null;
9189
$GLOBALS['lang'] = $GLOBALS['lang'] ?? null;
9290
$GLOBALS['isConfigLoading'] = $GLOBALS['isConfigLoading'] ?? null;
@@ -114,7 +112,9 @@ public static function run(): void
114112

115113
$GLOBALS['containerBuilder'] = Core::getContainerBuilder();
116114

117-
$GLOBALS['errorHandler'] = $GLOBALS['containerBuilder']->get('error_handler');
115+
/** @var ErrorHandler $errorHandler */
116+
$errorHandler = $GLOBALS['containerBuilder']->get('error_handler');
117+
$GLOBALS['errorHandler'] = $errorHandler;
118118

119119
self::checkRequiredPhpExtensions();
120120
self::configurePhpSettings();
@@ -127,17 +127,15 @@ public static function run(): void
127127

128128
register_shutdown_function([Config::class, 'fatalErrorHandler']);
129129

130-
/**
131-
* Force reading of config file, because we removed sensitive values
132-
* in the previous iteration.
133-
*/
134-
$GLOBALS['config'] = $GLOBALS['containerBuilder']->get('config');
130+
/** @var Config $config */
131+
$config = $GLOBALS['containerBuilder']->get('config');
132+
$GLOBALS['config'] = $config;
135133

136134
/**
137135
* include session handling after the globals, to prevent overwriting
138136
*/
139137
if (! defined('PMA_NO_SESSION')) {
140-
Session::setUp($GLOBALS['config'], $GLOBALS['errorHandler']);
138+
Session::setUp($config, $errorHandler);
141139
}
142140

143141
$request = Core::populateRequestWithEncryptedQueryParams($request);
@@ -154,7 +152,7 @@ public static function run(): void
154152
$GLOBALS['urlParams'] = [];
155153
$GLOBALS['containerBuilder']->setParameter('url_params', $GLOBALS['urlParams']);
156154

157-
self::setGotoAndBackGlobals($GLOBALS['containerBuilder'], $GLOBALS['config']);
155+
self::setGotoAndBackGlobals($GLOBALS['containerBuilder'], $config);
158156
self::checkTokenRequestParam();
159157
self::setDatabaseAndTableFromRequest($GLOBALS['containerBuilder'], $request);
160158

@@ -189,27 +187,27 @@ public static function run(): void
189187
* check for errors occurred while loading configuration
190188
* this check is done here after loading language files to present errors in locale
191189
*/
192-
$GLOBALS['config']->checkPermissions();
193-
$GLOBALS['config']->checkErrors();
190+
$config->checkPermissions();
191+
$config->checkErrors();
194192

195193
self::checkServerConfiguration();
196194
self::checkRequest();
197195

198196
/* setup servers LABEL_setup_servers */
199197

200-
$GLOBALS['config']->checkServers();
198+
$config->checkServers();
201199

202200
/**
203201
* current server
204202
*
205203
* @global integer $server
206204
*/
207-
$GLOBALS['server'] = $GLOBALS['config']->selectServer();
205+
$GLOBALS['server'] = $config->selectServer();
208206
$GLOBALS['urlParams']['server'] = $GLOBALS['server'];
209207
$GLOBALS['containerBuilder']->setParameter('server', $GLOBALS['server']);
210208
$GLOBALS['containerBuilder']->setParameter('url_params', $GLOBALS['urlParams']);
211209

212-
$GLOBALS['cfg'] = $GLOBALS['config']->settings;
210+
$GLOBALS['cfg'] = $config->settings;
213211

214212
/* setup themes LABEL_theme_setup */
215213

@@ -218,7 +216,7 @@ public static function run(): void
218216
$GLOBALS['dbi'] = null;
219217

220218
if (isset($GLOBALS['isMinimumCommon'])) {
221-
$GLOBALS['config']->loadUserPreferences();
219+
$config->loadUserPreferences();
222220
$GLOBALS['containerBuilder']->set('theme_manager', ThemeManager::getInstance());
223221
Tracker::enable();
224222

@@ -231,10 +229,8 @@ public static function run(): void
231229

232230
/**
233231
* save some settings in cookies
234-
*
235-
* @todo should be done in PhpMyAdmin\Config
236232
*/
237-
$GLOBALS['config']->setCookie('pma_lang', (string) $GLOBALS['lang']);
233+
$config->setCookie('pma_lang', (string) $GLOBALS['lang']);
238234

239235
ThemeManager::getInstance()->setThemeCookie();
240236

@@ -243,7 +239,7 @@ public static function run(): void
243239
$GLOBALS['containerBuilder']->setAlias('dbi', DatabaseInterface::class);
244240

245241
if (! empty($GLOBALS['cfg']['Server'])) {
246-
$GLOBALS['config']->getLoginCookieValidityFromCache($GLOBALS['server']);
242+
$config->getLoginCookieValidityFromCache($GLOBALS['server']);
247243

248244
$GLOBALS['auth_plugin'] = Plugins::getAuthPlugin();
249245
$GLOBALS['auth_plugin']->authenticate();
@@ -309,7 +305,7 @@ public static function run(): void
309305
$GLOBALS['containerBuilder']->set('response', ResponseRenderer::getInstance());
310306

311307
// load user preferences
312-
$GLOBALS['config']->loadUserPreferences();
308+
$config->loadUserPreferences();
313309

314310
$GLOBALS['containerBuilder']->set('theme_manager', ThemeManager::getInstance());
315311

psalm-baseline.xml

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,13 @@
222222
</NonInvariantDocblockPropertyType>
223223
</file>
224224
<file src="libraries/classes/Common.php">
225-
<ArgumentTypeCoercion occurrences="3">
226-
<code>$GLOBALS['config']</code>
227-
<code>$GLOBALS['config']</code>
228-
<code>$GLOBALS['errorHandler']</code>
229-
</ArgumentTypeCoercion>
230225
<InvalidArrayOffset occurrences="1">
231226
<code>$GLOBALS['cfg']['Server']['controluser']</code>
232227
</InvalidArrayOffset>
233-
<MixedArgument occurrences="8">
228+
<MixedArgument occurrences="7">
234229
<code>$GLOBALS['back']</code>
235230
<code>$GLOBALS['cfg']['Server']['user']</code>
236231
<code>$GLOBALS['goto']</code>
237-
<code>$GLOBALS['server']</code>
238232
<code>$_REQUEST['back']</code>
239233
<code>$_REQUEST['goto']</code>
240234
<code>$_SESSION[' PMA_token ']</code>
@@ -245,50 +239,19 @@
245239
<code>$GLOBALS['cfg']['MysqlMinVersion']['internal']</code>
246240
<code>$GLOBALS['cfg']['Server']['user']</code>
247241
</MixedArrayAccess>
248-
<MixedAssignment occurrences="14">
242+
<MixedAssignment occurrences="11">
249243
<code>$GLOBALS['auth_plugin']</code>
250244
<code>$GLOBALS['back']</code>
251245
<code>$GLOBALS['back']</code>
252-
<code>$GLOBALS['cfg']</code>
253246
<code>$GLOBALS['goto']</code>
254247
<code>$GLOBALS['isConfigLoading']</code>
255-
<code>$GLOBALS['server']</code>
256248
<code>$GLOBALS['sql_query']</code>
257249
<code>$GLOBALS['theme']</code>
258250
<code>$GLOBALS['urlParams']['goto']</code>
259-
<code>$GLOBALS['urlParams']['server']</code>
260251
<code>$controlLink</code>
261252
<code>$sqlDelimiter</code>
262253
<code>$userLink</code>
263254
</MixedAssignment>
264-
<MixedMethodCall occurrences="8">
265-
<code>checkErrors</code>
266-
<code>checkPermissions</code>
267-
<code>checkServers</code>
268-
<code>getLoginCookieValidityFromCache</code>
269-
<code>loadUserPreferences</code>
270-
<code>loadUserPreferences</code>
271-
<code>selectServer</code>
272-
<code>setCookie</code>
273-
</MixedMethodCall>
274-
<PossiblyNullArgument occurrences="3">
275-
<code>$GLOBALS['config']</code>
276-
<code>$GLOBALS['config']</code>
277-
<code>$GLOBALS['errorHandler']</code>
278-
</PossiblyNullArgument>
279-
<PossiblyNullPropertyFetch occurrences="1">
280-
<code>$GLOBALS['config']-&gt;settings</code>
281-
</PossiblyNullPropertyFetch>
282-
<PossiblyNullReference occurrences="8">
283-
<code>checkErrors</code>
284-
<code>checkPermissions</code>
285-
<code>checkServers</code>
286-
<code>getLoginCookieValidityFromCache</code>
287-
<code>loadUserPreferences</code>
288-
<code>loadUserPreferences</code>
289-
<code>selectServer</code>
290-
<code>setCookie</code>
291-
</PossiblyNullReference>
292255
</file>
293256
<file src="libraries/classes/Config.php">
294257
<InvalidArgument occurrences="1">

0 commit comments

Comments
 (0)