Skip to content

Commit

Permalink
Merge pull request #15255 from Tithugues/feature/replace-class-name-a…
Browse files Browse the repository at this point in the history
…s-string

Replace class name as string by ":class"
  • Loading branch information
MauricioFauth committed May 8, 2019
2 parents 4adc7a2 + 4b628b6 commit 5b9ad4e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
3 changes: 2 additions & 1 deletion libraries/classes/Config.php
Expand Up @@ -18,6 +18,7 @@
use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\HttpRequest;
use PhpMyAdmin\Config;

/**
* Indication for error handler (see end of this file).
Expand Down Expand Up @@ -1750,5 +1751,5 @@ public function checkServers(): void
}

if (! defined('TESTSUITE')) {
register_shutdown_function(['PhpMyAdmin\Config', 'fatalErrorHandler']);
register_shutdown_function([Config::class, 'fatalErrorHandler']);
}
6 changes: 3 additions & 3 deletions libraries/classes/Database/Qbe.php
Expand Up @@ -1512,8 +1512,8 @@ private function _getFromClause(array $formColumns)
if (empty($from_clause)) {
// Create cartesian product
$from_clause = implode(
", ",
array_map(['PhpMyAdmin\Util', 'backquote'], $search_tables)
', ',
array_map([Util::class, 'backquote'], $search_tables)
);
}

Expand Down Expand Up @@ -1622,7 +1622,7 @@ private function _getJoinForFromClause(array $searchTables, array $searchColumns
// Add these tables as cartesian product before joined tables
$join .= implode(
', ',
array_map(['PhpMyAdmin\Util', 'backquote'], $unfinalized)
array_map([Util::class, 'backquote'], $unfinalized)
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions libraries/classes/Display/Results.php
Expand Up @@ -27,6 +27,9 @@
use PhpMyAdmin\Util;
use \stdClass;
use PhpMyAdmin\Plugins\TransformationsPlugin;
use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Json;
use PhpMyAdmin\Plugins\Transformations\Output\Text_Octetstream_Sql;
use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Sql;

/**
* Handle all the functionalities related to displaying results
Expand Down Expand Up @@ -262,22 +265,22 @@ private function _setDefaultTransformations()
{
$json_highlighting_data = [
'libraries/classes/Plugins/Transformations/Output/Text_Plain_Json.php',
'PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Json',
Text_Plain_Json::class,
'Text_Plain',
];
$sql_highlighting_data = [
'libraries/classes/Plugins/Transformations/Output/Text_Plain_Sql.php',
'PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_Sql',
Text_Plain_Sql::class,
'Text_Plain',
];
$blob_sql_highlighting_data = [
'libraries/classes/Plugins/Transformations/Output/Text_Octetstream_Sql.php',
'PhpMyAdmin\Plugins\Transformations\Output\Text_Octetstream_Sql',
Text_Octetstream_Sql::class,
'Text_Octetstream',
];
$link_data = [
'libraries/classes/Plugins/Transformations/Text_Plain_Link.php',
'PhpMyAdmin\Plugins\Transformations\Text_Plain_Link',
Text_Plain_Link::class,
'Text_Plain',
];
$this->transformation_info = [
Expand Down
9 changes: 5 additions & 4 deletions libraries/classes/Navigation/NavigationTree.php
Expand Up @@ -21,6 +21,7 @@
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use PhpMyAdmin\Url;
use PhpMyAdmin\Navigation\NavigationTree;

/**
* Displays a collapsible of database objects in the navigation frame
Expand Down Expand Up @@ -880,7 +881,7 @@ public function renderState()
$this->groupTree();
$children = $this->_tree->children;
usort($children, [
'PhpMyAdmin\\Navigation\\NavigationTree',
NavigationTree::class,
'sortNode',
]);
$this->_setVisibility();
Expand Down Expand Up @@ -922,7 +923,7 @@ public function renderPath()
$listContent .= $this->_getPageSelector($node);
$children = $node->children;
usort($children, [
'PhpMyAdmin\\Navigation\\NavigationTree',
NavigationTree::class,
'sortNode',
]);

Expand Down Expand Up @@ -1228,7 +1229,7 @@ private function _renderNode($node, $recursive, $class = '')
usort(
$children,
[
'PhpMyAdmin\\Navigation\\NavigationTree',
NavigationTree::class,
'sortNode',
]
);
Expand Down Expand Up @@ -1314,7 +1315,7 @@ public function renderDbSelect()

$children = $this->_tree->children;
usort($children, [
'PhpMyAdmin\\Navigation\\NavigationTree',
NavigationTree::class,
'sortNode',
]);
$this->_setVisibility();
Expand Down
28 changes: 18 additions & 10 deletions libraries/classes/Plugins.php
Expand Up @@ -14,6 +14,14 @@
use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use PhpMyAdmin\Properties\Plugins\PluginPropertyItem;
use PhpMyAdmin\Properties\Plugins\SchemaPluginProperties;
use PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem;
use PhpMyAdmin\Properties\Options\Items\NumberPropertyItem;
use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem;
use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem;
use PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem;
use PhpMyAdmin\Properties\Options\Items\DocPropertyItem;
use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;

/**
* PhpMyAdmin\Plugins class
Expand Down Expand Up @@ -418,7 +426,7 @@ public static function getHtmlForProperty(
$ret = null;
$property_class = get_class($propertyItem);
switch ($property_class) {
case 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem':
case BoolPropertyItem::class:
$ret .= '<li>' . "\n";
$ret .= '<input type="checkbox" name="' . $plugin_name . '_'
. $propertyItem->getName() . '"'
Expand All @@ -445,10 +453,10 @@ public static function getHtmlForProperty(
. $propertyItem->getName() . '">'
. self::getString($propertyItem->getText()) . '</label>';
break;
case 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem':
echo 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem';
case DocPropertyItem::class:
echo DocPropertyItem::class;
break;
case 'PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem':
case HiddenPropertyItem::class:
$ret .= '<li><input type="hidden" name="' . $plugin_name . '_'
. $propertyItem->getName() . '"'
. ' value="' . self::getDefault(
Expand All @@ -457,11 +465,11 @@ public static function getHtmlForProperty(
)
. '"' . '></li>';
break;
case 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem':
case MessageOnlyPropertyItem::class:
$ret .= '<li>' . "\n";
$ret .= '<p>' . self::getString($propertyItem->getText()) . '</p>';
break;
case 'PhpMyAdmin\Properties\Options\Items\RadioPropertyItem':
case RadioPropertyItem::class:
/**
* @var \PhpMyAdmin\Properties\Options\Items\RadioPropertyItem $pitem
*/
Expand All @@ -485,7 +493,7 @@ public static function getHtmlForProperty(
. self::getString($val) . '</label></li>';
}
break;
case 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem':
case SelectPropertyItem::class:
/**
* @var \PhpMyAdmin\Properties\Options\Items\SelectPropertyItem $pitem
*/
Expand All @@ -512,7 +520,7 @@ public static function getHtmlForProperty(

$ret .= '</select>';
break;
case 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem':
case TextPropertyItem::class:
/**
* @var \PhpMyAdmin\Properties\Options\Items\TextPropertyItem $pitem
*/
Expand All @@ -537,7 +545,7 @@ public static function getHtmlForProperty(
: '')
. '>';
break;
case 'PhpMyAdmin\Properties\Options\Items\NumberPropertyItem':
case NumberPropertyItem::class:
$ret .= '<li>' . "\n";
$ret .= '<label for="number_' . $plugin_name . '_'
. $propertyItem->getName() . '" class="desc">'
Expand Down Expand Up @@ -600,7 +608,7 @@ public static function getOptions($section, array $list)
// check for hidden properties
$no_options = true;
foreach ($propertyMainGroup->getProperties() as $propertyItem) {
if (strcmp('PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem', get_class($propertyItem))) {
if (strcmp(HiddenPropertyItem::class, get_class($propertyItem))) {
$no_options = false;
break;
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Plugins/Auth/AuthenticationCookie.php
Expand Up @@ -23,6 +23,7 @@
use PhpMyAdmin\Url;
use phpseclib\Crypt;
use ReCaptcha;
use phpseclib\Crypt\Random;

/**
* Remember where to redirect the user
Expand Down Expand Up @@ -57,7 +58,7 @@ class AuthenticationCookie extends AuthenticationPlugin
public function __construct()
{
parent::__construct();
$this->_use_openssl = ! class_exists('phpseclib\Crypt\Random');
$this->_use_openssl = ! class_exists(Random::class);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions libraries/classes/TwoFactor.php
Expand Up @@ -10,6 +10,10 @@
namespace PhpMyAdmin;

use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\Plugins\TwoFactor\Invalid;
use PhpMyAdmin\Plugins\TwoFactorPlugin;
use Samyoul\U2F\U2FServer\U2FServer;
use PragmaRX\Google2FAQRCode\Google2FA;

/**
* Two factor authentication wrapper class
Expand Down Expand Up @@ -118,10 +122,10 @@ public function getAvailable()
if ($GLOBALS['cfg']['DBG']['simple2fa']) {
$result[] = 'simple';
}
if (class_exists('PragmaRX\Google2FAQRCode\Google2FA')) {
if (class_exists(Google2FA::class)) {
$result[] = 'application';
}
if (class_exists('Samyoul\U2F\U2FServer\U2FServer')) {
if (class_exists(U2FServer::class)) {
$result[] = 'key';
}
return $result;
Expand All @@ -135,7 +139,7 @@ public function getAvailable()
public function getMissingDeps()
{
$result = [];
if (! class_exists('PragmaRX\Google2FAQRCode\Google2FA')) {
if (! class_exists(Google2FA::class)) {
$result[] = [
'class' => \PhpMyAdmin\Plugins\TwoFactor\Application::getName(),
'dep' => 'pragmarx/google2fa-qrcode',
Expand All @@ -147,7 +151,7 @@ public function getMissingDeps()
'dep' => 'bacon/bacon-qr-code',
];
}
if (! class_exists('Samyoul\U2F\U2FServer\U2FServer')) {
if (! class_exists(U2FServer::class)) {
$result[] = [
'class' => \PhpMyAdmin\Plugins\TwoFactor\Key::getName(),
'dep' => 'samyoul/u2f-php-server',
Expand All @@ -165,11 +169,11 @@ public function getMissingDeps()
*/
public function getBackendClass($name)
{
$result = 'PhpMyAdmin\\Plugins\\TwoFactorPlugin';
$result = TwoFactorPlugin::class;
if (in_array($name, $this->_available)) {
$result = 'PhpMyAdmin\\Plugins\\TwoFactor\\' . ucfirst($name);
} elseif (! empty($name)) {
$result = 'PhpMyAdmin\\Plugins\\TwoFactor\\Invalid';
$result = Invalid::class;
}
return $result;
}
Expand Down
5 changes: 3 additions & 2 deletions libraries/classes/Util.php
Expand Up @@ -25,6 +25,7 @@
use PhpMyAdmin\Url;
use Williamdes\MariaDBMySQLKBS\Search as KBSearch;
use Williamdes\MariaDBMySQLKBS\KBException;
use phpseclib\Crypt\Random;

/**
* Misc functions used all over the scripts.
Expand Down Expand Up @@ -4797,9 +4798,9 @@ public static function requestString($value)
public static function generateRandom($length)
{
$result = '';
if (class_exists('phpseclib\\Crypt\\Random')) {
if (class_exists(Random::class)) {
$random_func = [
'phpseclib\\Crypt\\Random',
Random::class,
'string',
];
} else {
Expand Down

0 comments on commit 5b9ad4e

Please sign in to comment.