summaryrefslogtreecommitdiffstats
path: root/src/Utils/Query.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils/Query.php')
-rw-r--r--src/Utils/Query.php70
1 files changed, 33 insertions, 37 deletions
diff --git a/src/Utils/Query.php b/src/Utils/Query.php
index 2e623aa..837e8f7 100644
--- a/src/Utils/Query.php
+++ b/src/Utils/Query.php
@@ -1,8 +1,8 @@
<?php
-
/**
* Statement utilities.
*/
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Utils;
@@ -35,10 +35,6 @@ use PhpMyAdmin\SqlParser\TokensList;
/**
* Statement utilities.
- *
- * @category Statement
- *
- * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Query
{
@@ -47,7 +43,7 @@ class Query
*
* @var array
*/
- public static $FUNCTIONS = array(
+ public static $FUNCTIONS = [
'SUM',
'AVG',
'STD',
@@ -55,10 +51,10 @@ class Query
'MIN',
'MAX',
'BIT_OR',
- 'BIT_AND'
- );
+ 'BIT_AND',
+ ];
- public static $ALLFLAGS = array(
+ public static $ALLFLAGS = [
/*
* select ... DISTINCT ...
*/
@@ -211,8 +207,8 @@ class Query
/*
* ... UNION ...
*/
- 'union' => false
- );
+ 'union' => false,
+ ];
/**
* Gets an array with flags select statement has.
@@ -300,7 +296,7 @@ class Query
*/
public static function getFlags($statement, $all = false)
{
- $flags = array('querytype' => false);
+ $flags = ['querytype' => false];
if ($all) {
$flags = self::$ALLFLAGS;
}
@@ -416,18 +412,18 @@ class Query
$ret['statement'] = $statement;
if ($statement instanceof SelectStatement) {
- $ret['select_tables'] = array();
- $ret['select_expr'] = array();
+ $ret['select_tables'] = [];
+ $ret['select_expr'] = [];
// Finding tables' aliases and their associated real names.
- $tableAliases = array();
+ $tableAliases = [];
foreach ($statement->from as $expr) {
if (isset($expr->table, $expr->alias) && ($expr->table !== '') && ($expr->alias !== '')
) {
- $tableAliases[$expr->alias] = array(
+ $tableAliases[$expr->alias] = [
$expr->table,
- isset($expr->database) ? $expr->database : null
- );
+ isset($expr->database) ? $expr->database : null,
+ ];
}
}
@@ -439,11 +435,11 @@ class Query
if (isset($tableAliases[$expr->table])) {
$arr = $tableAliases[$expr->table];
} else {
- $arr = array(
+ $arr = [
$expr->table,
- (isset($expr->database) && ($expr->database !== '')) ?
- $expr->database : null
- );
+ isset($expr->database) && ($expr->database !== '') ?
+ $expr->database : null,
+ ];
}
if (! in_array($arr, $ret['select_tables'])) {
$ret['select_tables'][] = $arr;
@@ -459,11 +455,11 @@ class Query
if (empty($ret['select_tables'])) {
foreach ($statement->from as $expr) {
if (isset($expr->table) && ($expr->table !== '')) {
- $arr = array(
+ $arr = [
$expr->table,
- (isset($expr->database) && ($expr->database !== '')) ?
- $expr->database : null
- );
+ isset($expr->database) && ($expr->database !== '') ?
+ $expr->database : null,
+ ];
if (! in_array($arr, $ret['select_tables'])) {
$ret['select_tables'][] = $arr;
}
@@ -484,12 +480,12 @@ class Query
*/
public static function getTables($statement)
{
- $expressions = array();
+ $expressions = [];
if (($statement instanceof InsertStatement)
|| ($statement instanceof ReplaceStatement)
) {
- $expressions = array($statement->into->dest);
+ $expressions = [$statement->into->dest];
} elseif ($statement instanceof UpdateStatement) {
$expressions = $statement->tables;
} elseif (($statement instanceof SelectStatement)
@@ -499,11 +495,11 @@ class Query
} elseif (($statement instanceof AlterStatement)
|| ($statement instanceof TruncateStatement)
) {
- $expressions = array($statement->table);
+ $expressions = [$statement->table];
} elseif ($statement instanceof DropStatement) {
if (! $statement->options->has('TABLE')) {
// No tables are dropped.
- return array();
+ return [];
}
$expressions = $statement->fields;
} elseif ($statement instanceof RenameStatement) {
@@ -512,7 +508,7 @@ class Query
}
}
- $ret = array();
+ $ret = [];
foreach ($expressions as $expr) {
if (! empty($expr->table)) {
$expr->expr = null; // Force rebuild.
@@ -796,11 +792,11 @@ class Query
// No statement was found so we return the entire query as being the
// remaining part.
if (! $fullStatement) {
- return array(
+ return [
null,
$query,
- $delimiter
- );
+ $delimiter,
+ ];
}
// At least one query was found so we have to build the rest of the
@@ -810,11 +806,11 @@ class Query
$query .= $list->tokens[$list->idx]->token;
}
- return array(
+ return [
trim($statement),
$query,
- $delimiter
- );
+ $delimiter,
+ ];
}
/**