summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauriciofauth@gmail.com>2019-01-08 21:32:02 -0200
committerMaurício Meneghini Fauth <mauriciofauth@gmail.com>2019-01-16 17:21:25 -0200
commit86c5baebda24c1721fb6881df8671a3c7df60e8b (patch)
tree0a76d58ea229d1008e169b1c5b25ce90dde91808
parent28427543566b6dd32fe44db704ea41368ba55c0e (diff)
downloadsql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.zip
sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.gz
sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.bz2
Apply phpmyadmin/coding-standard
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
-rw-r--r--.gitignore1
-rw-r--r--.php_cs29
-rw-r--r--composer.json3
-rw-r--r--phpcs.xml.dist39
-rw-r--r--src/Component.php4
-rw-r--r--src/Components/AlterOperation.php104
-rw-r--r--src/Components/Array2d.php6
-rw-r--r--src/Components/ArrayObj.php16
-rw-r--r--src/Components/CaseExpression.php30
-rw-r--r--src/Components/Condition.php30
-rw-r--r--src/Components/CreateDefinition.php61
-rw-r--r--src/Components/DataType.php31
-rw-r--r--src/Components/Expression.php64
-rw-r--r--src/Components/ExpressionArray.php8
-rw-r--r--src/Components/FunctionCall.php4
-rw-r--r--src/Components/GroupKeyword.php10
-rw-r--r--src/Components/IndexHint.php12
-rw-r--r--src/Components/IntoKeyword.php45
-rw-r--r--src/Components/JoinKeyword.php32
-rw-r--r--src/Components/Key.php40
-rw-r--r--src/Components/Limit.php4
-rw-r--r--src/Components/LockExpression.php13
-rw-r--r--src/Components/OptionsArray.php38
-rw-r--r--src/Components/OrderKeyword.php10
-rw-r--r--src/Components/ParameterDefinition.php8
-rw-r--r--src/Components/PartitionDefinition.php63
-rw-r--r--src/Components/Reference.php29
-rw-r--r--src/Components/RenameOperation.php16
-rw-r--r--src/Components/SetOperation.php10
-rw-r--r--src/Components/UnionKeyword.php4
-rw-r--r--src/Context.php44
-rw-r--r--src/Contexts/ContextMariaDb100000.php4
-rw-r--r--src/Contexts/ContextMariaDb100100.php4
-rw-r--r--src/Contexts/ContextMariaDb100200.php4
-rw-r--r--src/Contexts/ContextMariaDb100300.php4
-rw-r--r--src/Contexts/ContextMySql50000.php4
-rw-r--r--src/Contexts/ContextMySql50100.php4
-rw-r--r--src/Contexts/ContextMySql50500.php4
-rw-r--r--src/Contexts/ContextMySql50600.php4
-rw-r--r--src/Contexts/ContextMySql50700.php4
-rw-r--r--src/Contexts/ContextMySql80000.php4
-rw-r--r--src/Core.php2
-rw-r--r--src/Exceptions/LoaderException.php2
-rw-r--r--src/Lexer.php53
-rw-r--r--src/Parser.php262
-rw-r--r--src/Statement.php30
-rw-r--r--src/Statements/AlterStatement.php14
-rw-r--r--src/Statements/AnalyzeStatement.php4
-rw-r--r--src/Statements/BackupStatement.php9
-rw-r--r--src/Statements/CheckStatement.php4
-rw-r--r--src/Statements/ChecksumStatement.php4
-rw-r--r--src/Statements/CreateStatement.php240
-rw-r--r--src/Statements/DeleteStatement.php85
-rw-r--r--src/Statements/DropStatement.php28
-rw-r--r--src/Statements/InsertStatement.php14
-rw-r--r--src/Statements/LoadStatement.php45
-rw-r--r--src/Statements/LockStatement.php4
-rw-r--r--src/Statements/NotImplementedStatement.php2
-rw-r--r--src/Statements/OptimizeStatement.php4
-rw-r--r--src/Statements/PurgeStatement.php8
-rw-r--r--src/Statements/RepairStatement.php4
-rw-r--r--src/Statements/ReplaceStatement.php12
-rw-r--r--src/Statements/RestoreStatement.php9
-rw-r--r--src/Statements/SelectStatement.php194
-rw-r--r--src/Statements/SetStatement.php49
-rw-r--r--src/Statements/ShowStatement.php4
-rw-r--r--src/Statements/TransactionStatement.php4
-rw-r--r--src/Statements/TruncateStatement.php4
-rw-r--r--src/Statements/UpdateStatement.php43
-rw-r--r--src/Token.php16
-rw-r--r--src/TokensList.php6
-rw-r--r--src/Translator.php2
-rw-r--r--src/UtfString.php2
-rw-r--r--src/Utils/BufferedQuery.php17
-rw-r--r--src/Utils/CLI.php35
-rw-r--r--src/Utils/Error.php12
-rw-r--r--src/Utils/Formatter.php166
-rw-r--r--src/Utils/Misc.php34
-rw-r--r--src/Utils/Query.php103
-rw-r--r--src/Utils/Routine.php50
-rw-r--r--src/Utils/Table.php28
-rw-r--r--src/Utils/Tokens.php6
-rw-r--r--tests/Builder/CreateStatementTest.php30
-rw-r--r--tests/Builder/StatementTest.php2
-rw-r--r--tests/Components/Array2dTest.php5
-rw-r--r--tests/Components/ArrayObjTest.php20
-rw-r--r--tests/Components/CaseExpressionTest.php18
-rw-r--r--tests/Components/ExpressionArrayTest.php10
-rw-r--r--tests/Components/ExpressionTest.php24
-rw-r--r--tests/Components/FunctionCallTest.php4
-rw-r--r--tests/Components/GroupKeywordTest.php4
-rw-r--r--tests/Components/JoinKeywordTest.php2
-rw-r--r--tests/Components/LimitTest.php8
-rw-r--r--tests/Components/LockExpressionTest.php20
-rw-r--r--tests/Components/OptionsArrayTest.php68
-rw-r--r--tests/Components/OrderKeywordTest.php4
-rw-r--r--tests/Components/ReferenceTest.php4
-rw-r--r--tests/Lexer/ContextTest.php70
-rw-r--r--tests/Lexer/LexerTest.php60
-rw-r--r--tests/Lexer/TokensListTest.php4
-rw-r--r--tests/Misc/BugsTest.php20
-rw-r--r--tests/Misc/ParameterTest.php6
-rw-r--r--tests/Misc/UtfStringTest.php40
-rw-r--r--tests/Parser/AlterStatementTest.php24
-rw-r--r--tests/Parser/CallStatementTest.php10
-rw-r--r--tests/Parser/CreateStatementTest.php62
-rw-r--r--tests/Parser/DeleteStatementTest.php54
-rw-r--r--tests/Parser/ExplainStatement.php6
-rw-r--r--tests/Parser/InsertStatementTest.php22
-rw-r--r--tests/Parser/LoadStatementTest.php28
-rw-r--r--tests/Parser/LockStatementTest.php38
-rw-r--r--tests/Parser/ParserTest.php14
-rw-r--r--tests/Parser/PurgeStatementTest.php18
-rw-r--r--tests/Parser/RenameStatementTest.php18
-rw-r--r--tests/Parser/ReplaceStatementTest.php22
-rw-r--r--tests/Parser/RestoreStatementTest.php6
-rw-r--r--tests/Parser/SelectStatementTest.php118
-rw-r--r--tests/Parser/SetStatementTest.php18
-rw-r--r--tests/Parser/TransactionStatementTest.php12
-rw-r--r--tests/Parser/UpdateStatementTest.php12
-rw-r--r--tests/TestCase.php21
-rw-r--r--tests/Utils/BufferedQueryTest.php90
-rw-r--r--tests/Utils/CLITest.php135
-rw-r--r--tests/Utils/ErrorTest.php24
-rw-r--r--tests/Utils/FormatterTest.php249
-rw-r--r--tests/Utils/MiscTest.php130
-rw-r--r--tests/Utils/QueryTest.php395
-rw-r--r--tests/Utils/RoutineTest.php326
-rw-r--r--tests/Utils/TableTest.php138
-rw-r--r--tests/Utils/TokensTest.php90
-rw-r--r--tools/ContextGenerator.php38
-rw-r--r--tools/TestGenerator.php49
132 files changed, 2958 insertions, 2094 deletions
diff --git a/.gitignore b/.gitignore
index b4122b6..05e6fc2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ coverage.xml
.php_cs.cache
*sw[op]
phpunit.xml
+phpcs.xml
diff --git a/.php_cs b/.php_cs
deleted file mode 100644
index 1364d57..0000000
--- a/.php_cs
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer
-
-$finder = PhpCsFixer\Finder::create()
- ->in(array(__DIR__ . '/bin', __DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/tools'))
-;
-
-return PhpCsFixer\Config::create()
- ->setRules(array(
- '@PSR1' => true,
- '@PSR2' => true,
- '@Symfony' => true,
- 'array_syntax' => array('syntax' => 'long'),
- 'concat_space' => array('spacing' => 'one'),
- 'ordered_imports' => true,
- 'no_trailing_whitespace' => true,
- 'no_useless_return' => true,
- 'no_useless_else' => true,
- 'phpdoc_add_missing_param_annotation' => true,
- 'phpdoc_order' => true,
- 'yoda_style' => array(
- 'equal' => false,
- 'identical' => false,
- 'less_and_greater' => false,
- )
- ))
- ->setFinder($finder)
-;
diff --git a/composer.json b/composer.json
index 3ed7107..59f71ce 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,8 @@
"require-dev": {
"sami/sami": "^4.0",
"phpunit/php-code-coverage": "*",
- "phpunit/phpunit": "^7.4"
+ "phpunit/phpunit": "^7.4",
+ "phpmyadmin/coding-standard": "^1.0"
},
"conflict": {
"phpmyadmin/motranslator": "<3.0"
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 0000000..81b5c0c
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<ruleset
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ name="phpMyAdmin"
+ xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
+>
+ <rule ref="./vendor/phpmyadmin/coding-standard/PhpMyAdmin/ruleset.xml">
+ <exclude name="PEAR.Commenting.FileComment"/>
+ <exclude name="PEAR.Commenting.ClassComment"/>
+ <exclude name="PEAR.Commenting.FunctionComment"/>
+ </rule>
+
+ <rule ref="Squiz.Arrays.ArrayDeclaration.IndexNoNewline">
+ <exclude-pattern>*/src/Contexts/*</exclude-pattern>
+ </rule>
+
+ <rule ref="Generic.Files.LineLength.TooLong">
+ <severity>4</severity>
+ </rule>
+ <rule ref="Generic.Metrics.NestingLevel.TooHigh">
+ <severity>4</severity>
+ </rule>
+ <rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
+ <severity>4</severity>
+ </rule>
+ <rule ref="Squiz.NamingConventions.ValidVariableName">
+ <severity>4</severity>
+ </rule>
+
+ <arg value="sp"/>
+ <arg name="colors"/>
+ <arg name="extensions" value="php"/>
+
+ <exclude-pattern>*/tools/sami-config.php</exclude-pattern>
+
+ <file>src</file>
+ <file>tests</file>
+ <file>tools</file>
+</ruleset>
diff --git a/src/Component.php b/src/Component.php
index bb230c2..d121e9b 100644
--- a/src/Component.php
+++ b/src/Component.php
@@ -36,7 +36,7 @@ abstract class Component
public static function parse(
Parser $parser,
TokensList $list,
- array $options = array()
+ array $options = []
) {
// This method should be abstract, but it can't be both static and
// abstract.
@@ -56,7 +56,7 @@ abstract class Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
// This method should be abstract, but it can't be both static and
// abstract.
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php
index e3893f7..25a62a5 100644
--- a/src/Components/AlterOperation.php
+++ b/src/Components/AlterOperation.php
@@ -25,28 +25,67 @@ class AlterOperation extends Component
*
* @var array
*/
- public static $DB_OPTIONS = array(
- 'CHARACTER SET' => array(1, 'var'),
- 'CHARSET' => array(1, 'var'),
- 'DEFAULT CHARACTER SET' => array(1, 'var'),
- 'DEFAULT CHARSET' => array(1, 'var'),
- 'UPGRADE' => array(1, 'var'),
- 'COLLATE' => array(2, 'var'),
- 'DEFAULT COLLATE' => array(2, 'var'),
- );
+ public static $DB_OPTIONS = [
+ 'CHARACTER SET' => [
+ 1,
+ 'var',
+ ],
+ 'CHARSET' => [
+ 1,
+ 'var',
+ ],
+ 'DEFAULT CHARACTER SET' => [
+ 1,
+ 'var',
+ ],
+ 'DEFAULT CHARSET' => [
+ 1,
+ 'var',
+ ],
+ 'UPGRADE' => [
+ 1,
+ 'var',
+ ],
+ 'COLLATE' => [
+ 2,
+ 'var',
+ ],
+ 'DEFAULT COLLATE' => [
+ 2,
+ 'var',
+ ],
+ ];
/**
* All table options.
*
* @var array
*/
- public static $TABLE_OPTIONS = array(
- 'ENGINE' => array(1, 'var='),
- 'AUTO_INCREMENT' => array(1, 'var='),
- 'AVG_ROW_LENGTH' => array(1, 'var'),
- 'MAX_ROWS' => array(1, 'var'),
- 'ROW_FORMAT' => array(1, 'var'),
- 'COMMENT' => array(1, 'var'),
+ public static $TABLE_OPTIONS = [
+ 'ENGINE' => [
+ 1,
+ 'var=',
+ ],
+ 'AUTO_INCREMENT' => [
+ 1,
+ 'var=',
+ ],
+ 'AVG_ROW_LENGTH' => [
+ 1,
+ 'var',
+ ],
+ 'MAX_ROWS' => [
+ 1,
+ 'var',
+ ],
+ 'ROW_FORMAT' => [
+ 1,
+ 'var',
+ ],
+ 'COMMENT' => [
+ 1,
+ 'var',
+ ],
'ADD' => 1,
'ALTER' => 1,
'ANALYZE' => 1,
@@ -84,16 +123,16 @@ class AlterOperation extends Component
'SPATIAL' => 2,
'TABLESPACE' => 2,
'INDEX' => 2,
- );
+ ];
/**
* All view options.
*
* @var array
*/
- public static $VIEW_OPTIONS = array(
+ public static $VIEW_OPTIONS = [
'AS' => 1,
- );
+ ];
/**
* Options of this operation.
@@ -114,7 +153,7 @@ class AlterOperation extends Component
*
* @var Token[]|string
*/
- public $unknown = array();
+ public $unknown = [];
/**
* Constructor.
@@ -126,7 +165,7 @@ class AlterOperation extends Component
public function __construct(
$options = null,
$field = null,
- $unknown = array()
+ $unknown = []
) {
$this->options = $options;
$this->field = $field;
@@ -140,7 +179,7 @@ class AlterOperation extends Component
*
* @return AlterOperation
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -212,10 +251,10 @@ class AlterOperation extends Component
$ret->field = Expression::parse(
$parser,
$list,
- array(
+ [
'breakOnAlias' => true,
'parseField' => 'column',
- )
+ ]
);
if ($ret->field === null) {
// No field was read. We go back one token so the next
@@ -232,11 +271,11 @@ class AlterOperation extends Component
} elseif (($token->value === ',') && ($brackets === 0)) {
break;
}
- } elseif (!empty(Parser::$STATEMENT_PARSERS[$token->value])) {
+ } elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them
- if (!($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
+ if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
@@ -245,7 +284,7 @@ class AlterOperation extends Component
}
} elseif (array_key_exists($token->value, self::$DB_OPTIONS)
|| (array_key_exists($token->value, self::$TABLE_OPTIONS)
- && !self::checkIfColumnDefinitionKeyword($token->value))
+ && ! self::checkIfColumnDefinitionKeyword($token->value))
) {
// This alter operation has finished, which means a comma was missing before start of new alter operation
$parser->error(
@@ -276,7 +315,7 @@ class AlterOperation extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
$ret = $component->options . ' ';
if ((isset($component->field)) && ($component->field !== '')) {
@@ -293,8 +332,13 @@ class AlterOperation extends Component
*
* @param string $tokenValue Value of current token
*/
- private static function checkIfColumnDefinitionKeyword($tokenValue) {
- $common_options = array('AUTO_INCREMENT', 'COMMENT', 'DEFAULT');
+ private static function checkIfColumnDefinitionKeyword($tokenValue)
+ {
+ $common_options = [
+ 'AUTO_INCREMENT',
+ 'COMMENT',
+ 'DEFAULT',
+ ];
// Since AUTO_INCREMENT and COMMENT can be used for
// both table as well as a specific column in the table
return in_array($tokenValue, $common_options);
diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php
index 984179c..ced529a 100644
--- a/src/Components/Array2d.php
+++ b/src/Components/Array2d.php
@@ -28,9 +28,9 @@ class Array2d extends Component
*
* @return ArrayObj[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
/**
* The number of values in each set.
@@ -124,7 +124,7 @@ class Array2d extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
return ArrayObj::build($component);
}
diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php
index e86ddfd..f968d87 100644
--- a/src/Components/ArrayObj.php
+++ b/src/Components/ArrayObj.php
@@ -25,14 +25,14 @@ class ArrayObj extends Component
*
* @var array
*/
- public $raw = array();
+ public $raw = [];
/**
* The array that contains the processed value of each token.
*
* @var array
*/
- public $values = array();
+ public $values = [];
/**
* Constructor.
@@ -40,7 +40,7 @@ class ArrayObj extends Component
* @param array $raw the unprocessed values
* @param array $values the processed values
*/
- public function __construct(array $raw = array(), array $values = array())
+ public function __construct(array $raw = [], array $values = [])
{
$this->raw = $raw;
$this->values = $values;
@@ -53,9 +53,9 @@ class ArrayObj extends Component
*
* @return ArrayObj|Component[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = empty($options['type']) ? new self() : array();
+ $ret = empty($options['type']) ? new self() : [];
/**
* The last raw expression.
@@ -144,7 +144,7 @@ class ArrayObj extends Component
$ret[] = $options['type']::parse(
$parser,
$list,
- empty($options['typeOptions']) ? array() : $options['typeOptions']
+ empty($options['typeOptions']) ? [] : $options['typeOptions']
);
}
}
@@ -176,11 +176,11 @@ class ArrayObj extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
- } elseif (!empty($component->raw)) {
+ } elseif (! empty($component->raw)) {
return '(' . implode(', ', $component->raw) . ')';
}
diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php
index ab90768..d66ddc3 100644
--- a/src/Components/CaseExpression.php
+++ b/src/Components/CaseExpression.php
@@ -84,7 +84,7 @@ class CaseExpression extends Component
*
* @return CaseExpression
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -121,26 +121,26 @@ class CaseExpression extends Component
if ($state === 0) {
if ($token->type === Token::TYPE_KEYWORD) {
- switch($token->keyword) {
+ switch ($token->keyword) {
case 'WHEN':
++$list->idx; // Skip 'WHEN'
$new_condition = Condition::parse($parser, $list);
$type = 1;
$state = 1;
$ret->conditions[] = $new_condition;
- break;
+ break;
case 'ELSE':
++$list->idx; // Skip 'ELSE'
$ret->else_result = Expression::parse($parser, $list);
$state = 0; // last clause of CASE expression
- break;
+ break;
case 'END':
$state = 3; // end of CASE expression
++$list->idx;
- break 2;
+ break 2;
default:
$parser->error('Unexpected keyword.', $token);
- break 2;
+ break 2;
}
} else {
$ret->value = Expression::parse($parser, $list);
@@ -150,25 +150,25 @@ class CaseExpression extends Component
} elseif ($state === 1) {
if ($type === 0) {
if ($token->type === Token::TYPE_KEYWORD) {
- switch($token->keyword) {
+ switch ($token->keyword) {
case 'WHEN':
++$list->idx; // Skip 'WHEN'
$new_value = Expression::parse($parser, $list);
$state = 2;
$ret->compare_values[] = $new_value;
- break;
+ break;
case 'ELSE':
++$list->idx; // Skip 'ELSE'
$ret->else_result = Expression::parse($parser, $list);
$state = 0; // last clause of CASE expression
- break;
+ break;
case 'END':
$state = 3; // end of CASE expression
++$list->idx;
- break 2;
+ break 2;
default:
$parser->error('Unexpected keyword.', $token);
- break 2;
+ break 2;
}
}
} else {
@@ -227,7 +227,7 @@ class CaseExpression extends Component
// Handle optional AS keyword before alias
if ($token->type === Token::TYPE_KEYWORD
&& $token->keyword === 'AS') {
- if ($asFound || !empty($ret->alias)) {
+ if ($asFound || ! empty($ret->alias)) {
$parser->error('Potential duplicate alias of CASE expression.', $token);
break;
}
@@ -245,11 +245,11 @@ class CaseExpression extends Component
if ($asFound
|| $token->type === Token::TYPE_STRING
- || ($token->type === Token::TYPE_SYMBOL && !$token->flags & Token::FLAG_SYMBOL_VARIABLE)
+ || ($token->type === Token::TYPE_SYMBOL && ! $token->flags & Token::FLAG_SYMBOL_VARIABLE)
|| $token->type === Token::TYPE_NONE
) {
// An alias is expected (the keyword `AS` was previously found).
- if (!empty($ret->alias)) {
+ if (! empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
break;
}
@@ -279,7 +279,7 @@ class CaseExpression extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
$ret = 'CASE ';
if (isset($component->value)) {
diff --git a/src/Components/Condition.php b/src/Components/Condition.php
index 2be0abd..83b80b2 100644
--- a/src/Components/Condition.php
+++ b/src/Components/Condition.php
@@ -25,14 +25,20 @@ class Condition extends Component
*
* @var array
*/
- public static $DELIMITERS = array('&&', '||', 'AND', 'OR', 'XOR');
+ public static $DELIMITERS = [
+ '&&',
+ '||',
+ 'AND',
+ 'OR',
+ 'XOR',
+ ];
/**
* List of allowed reserved keywords in conditions.
*
* @var array
*/
- public static $ALLOWED_KEYWORDS = array(
+ public static $ALLOWED_KEYWORDS = [
'ALL' => 1,
'AND' => 1,
'BETWEEN' => 1,
@@ -51,14 +57,14 @@ class Condition extends Component
'REGEXP' => 1,
'RLIKE' => 1,
'XOR' => 1,
- );
+ ];
/**
* Identifiers recognized.
*
* @var array
*/
- public $identifiers = array();
+ public $identifiers = [];
/**
* Whether this component is an operator.
@@ -91,9 +97,9 @@ class Condition extends Component
*
* @return Condition[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -148,7 +154,7 @@ class Condition extends Component
} else {
// The expression ended.
$expr->expr = trim($expr->expr);
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
@@ -165,7 +171,7 @@ class Condition extends Component
if (($token->type === Token::TYPE_KEYWORD)
&& ($token->flags & Token::FLAG_KEYWORD_RESERVED)
- && !($token->flags & Token::FLAG_KEYWORD_FUNCTION)
+ && ! ($token->flags & Token::FLAG_KEYWORD_FUNCTION)
) {
if ($token->value === 'BETWEEN') {
$betweenBefore = true;
@@ -189,11 +195,11 @@ class Condition extends Component
$expr->expr .= $token->token;
if (($token->type === Token::TYPE_NONE)
|| (($token->type === Token::TYPE_KEYWORD)
- && (!($token->flags & Token::FLAG_KEYWORD_RESERVED)))
+ && (! ($token->flags & Token::FLAG_KEYWORD_RESERVED)))
|| ($token->type === Token::TYPE_STRING)
|| ($token->type === Token::TYPE_SYMBOL)
) {
- if (!in_array($token->value, $expr->identifiers)) {
+ if (! in_array($token->value, $expr->identifiers)) {
$expr->identifiers[] = $token->value;
}
}
@@ -201,7 +207,7 @@ class Condition extends Component
// Last iteration was not processed.
$expr->expr = trim($expr->expr);
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
@@ -216,7 +222,7 @@ class Condition extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(' ', $component);
diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php
index 21ddae9..ccf8497 100644
--- a/src/Components/CreateDefinition.php
+++ b/src/Components/CreateDefinition.php
@@ -30,30 +30,53 @@ class CreateDefinition extends Component
*
* @var array
*/
- public static $FIELD_OPTIONS = array(
+ public static $FIELD_OPTIONS = [
// Tells the `OptionsArray` to not sort the options.
// See the note below.
'_UNSORTED' => true,
'NOT NULL' => 1,
'NULL' => 1,
- 'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)),
+ 'DEFAULT' => [
+ 2,
+ 'expr',
+ ['breakOnAlias' => true],
+ ],
/* Following are not according to grammar, but MySQL happily accepts
* these at any location */
- 'CHARSET' => array(2, 'var'),
- 'COLLATE' => array(3, 'var'),
+ 'CHARSET' => [
+ 2,
+ 'var',
+ ],
+ 'COLLATE' => [
+ 3,
+ 'var',
+ ],
'AUTO_INCREMENT' => 3,
'PRIMARY' => 4,
'PRIMARY KEY' => 4,
'UNIQUE' => 4,
'UNIQUE KEY' => 4,
- 'COMMENT' => array(5, 'var'),
- 'COLUMN_FORMAT' => array(6, 'var'),
- 'ON UPDATE' => array(7, 'expr'),
+ 'COMMENT' => [
+ 5,
+ 'var',
+ ],
+ 'COLUMN_FORMAT' => [
+ 6,
+ 'var',
+ ],
+ 'ON UPDATE' => [
+ 7,
+ 'expr',
+ ],
// Generated columns options.
'GENERATED ALWAYS' => 8,
- 'AS' => array(9, 'expr', array('parenthesesDelimited' => true)),
+ 'AS' => [
+ 9,
+ 'expr',
+ ['parenthesesDelimited' => true],
+ ],
'VIRTUAL' => 10,
'PERSISTENT' => 11,
'STORED' => 11,
@@ -71,7 +94,7 @@ class CreateDefinition extends Component
// 'NULL' => 1,
// 'PRIMARY' => 4,
// 'PRIMARY KEY' => 4,
- );
+ ];
/**
* The name of the new column.
@@ -149,9 +172,9 @@ class CreateDefinition extends Component
*
* @return CreateDefinition[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -216,7 +239,7 @@ class CreateDefinition extends Component
$state = 4;
} elseif ($token->type === Token::TYPE_SYMBOL || $token->type === Token::TYPE_NONE) {
$expr->name = $token->value;
- if (!$expr->isConstraint) {
+ if (! $expr->isConstraint) {
$state = 2;
}
} elseif ($token->type === Token::TYPE_KEYWORD) {
@@ -259,7 +282,7 @@ class CreateDefinition extends Component
}
$state = 5;
} elseif ($state === 5) {
- if (!empty($expr->type) || !empty($expr->key)) {
+ if (! empty($expr->type) || ! empty($expr->key)) {
$ret[] = $expr;
}
$expr = new self();
@@ -281,7 +304,7 @@ class CreateDefinition extends Component
}
// Last iteration was not saved.
- if (!empty($expr->type) || !empty($expr->key)) {
+ if (! empty($expr->type) || ! empty($expr->key)) {
$ret[] = $expr;
}
@@ -303,7 +326,7 @@ class CreateDefinition extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return "(\n " . implode(",\n ", $component) . "\n)";
@@ -319,18 +342,18 @@ class CreateDefinition extends Component
$tmp .= Context::escape($component->name) . ' ';
}
- if (!empty($component->type)) {
+ if (! empty($component->type)) {
$tmp .= DataType::build(
$component->type,
- array('lowercase' => true)
+ ['lowercase' => true]
) . ' ';
}
- if (!empty($component->key)) {
+ if (! empty($component->key)) {
$tmp .= $component->key . ' ';
}
- if (!empty($component->references)) {
+ if (! empty($component->references)) {
$tmp .= 'REFERENCES ' . $component->references . ' ';
}
diff --git a/src/Components/DataType.php b/src/Components/DataType.php
index 51f04fa..47fffba 100644
--- a/src/Components/DataType.php
+++ b/src/Components/DataType.php
@@ -25,14 +25,23 @@ class DataType extends Component
*
* @var array
*/
- public static $DATA_TYPE_OPTIONS = array(
+ public static $DATA_TYPE_OPTIONS = [
'BINARY' => 1,
- 'CHARACTER SET' => array(2, 'var'),
- 'CHARSET' => array(2, 'var'),
- 'COLLATE' => array(3, 'var'),
+ 'CHARACTER SET' => [
+ 2,
+ 'var',
+ ],
+ 'CHARSET' => [
+ 2,
+ 'var',
+ ],
+ 'COLLATE' => [
+ 3,
+ 'var',
+ ],
'UNSIGNED' => 4,
'ZEROFILL' => 5,
- );
+ ];
/**
* The name of the data type.
@@ -54,7 +63,7 @@ class DataType extends Component
*
* @var array
*/
- public $parameters = array();
+ public $parameters = [];
/**
* The options of this data type.
@@ -72,7 +81,7 @@ class DataType extends Component
*/
public function __construct(
$name = null,
- array $parameters = array(),
+ array $parameters = [],
$options = null
) {
$this->name = $name;
@@ -87,7 +96,7 @@ class DataType extends Component
*
* @return DataType
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -119,7 +128,7 @@ class DataType extends Component
if ($state === 0) {
$ret->name = strtoupper($token->value);
- if (($token->type !== Token::TYPE_KEYWORD) || (!($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) {
+ if (($token->type !== Token::TYPE_KEYWORD) || (! ($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) {
$parser->error('Unrecognized data type.', $token);
}
$state = 1;
@@ -151,13 +160,13 @@ class DataType extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
$name = empty($options['lowercase']) ?
$component->name : strtolower($component->name);
$parameters = '';
- if (!empty($component->parameters)) {
+ if (! empty($component->parameters)) {
$parameters = '(' . implode(',', $component->parameters) . ')';
}
diff --git a/src/Components/Expression.php b/src/Components/Expression.php
index 5350e36..7383275 100644
--- a/src/Components/Expression.php
+++ b/src/Components/Expression.php
@@ -28,10 +28,19 @@ class Expression extends Component
*
* @var array
*/
- private static $ALLOWED_KEYWORDS = array(
- 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, 'REGEXP' => 1, 'CASE' => 1,
- 'DIV' => 1, 'AND' => 1, 'OR' => 1, 'XOR' => 1, 'NOT' => 1, 'MOD' => 1,
- );
+ private static $ALLOWED_KEYWORDS = [
+ 'AS' => 1,
+ 'DUAL' => 1,
+ 'NULL' => 1,
+ 'REGEXP' => 1,
+ 'CASE' => 1,
+ 'DIV' => 1,
+ 'AND' => 1,
+ 'OR' => 1,
+ 'XOR' => 1,
+ 'NOT' => 1,
+ 'MOD' => 1,
+ ];
/**
* The name of this database.
@@ -146,7 +155,7 @@ class Expression extends Component
*
* @return Expression
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -183,10 +192,13 @@ class Expression extends Component
*
* @var Token[]
*/
- $prev = array(null, null);
+ $prev = [
+ null,
+ null,
+ ];
// When a field is parsed, no parentheses are expected.
- if (!empty($options['parseField'])) {
+ if (! empty($options['parseField'])) {
$options['breakOnParentheses'] = true;
$options['field'] = $options['parseField'];
}
@@ -216,14 +228,14 @@ class Expression extends Component
if ($token->type === Token::TYPE_KEYWORD) {
if (($brackets > 0) && empty($ret->subquery)
- && !empty(Parser::$STATEMENT_PARSERS[$token->keyword])
+ && ! empty(Parser::$STATEMENT_PARSERS[$token->keyword])
) {
// A `(` was previously found and this keyword is the
// beginning of a statement, so this is a subquery.
$ret->subquery = $token->keyword;
} elseif (($token->flags & Token::FLAG_KEYWORD_FUNCTION)
&& (empty($options['parseField'])
- && !$alias)
+ && ! $alias)
) {
$isExpr = true;
} elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED)
@@ -236,7 +248,7 @@ class Expression extends Component
break;
}
if ($token->keyword === 'AS') {
- if (!empty($options['breakOnAlias'])) {
+ if (! empty($options['breakOnAlias'])) {
break;
}
if ($alias) {
@@ -257,7 +269,7 @@ class Expression extends Component
continue;
}
$isExpr = true;
- } elseif ($brackets === 0 && strlen($ret->expr) > 0 && !$alias) {
+ } elseif ($brackets === 0 && strlen($ret->expr) > 0 && ! $alias) {
/* End of expression */
break;
}
@@ -272,7 +284,7 @@ class Expression extends Component
|| (($token->type === Token::TYPE_OPERATOR)
&& ($token->value !== '.'))
) {
- if (!empty($options['parseField'])) {
+ if (! empty($options['parseField'])) {
break;
}
@@ -282,7 +294,7 @@ class Expression extends Component
}
if ($token->type === Token::TYPE_OPERATOR) {
- if (!empty($options['breakOnParentheses'])
+ if (! empty($options['breakOnParentheses'])
&& (($token->value === '(') || ($token->value === ')'))
) {
// No brackets were expected.
@@ -305,7 +317,7 @@ class Expression extends Component
} else {
--$brackets;
if ($brackets === 0) {
- if (!empty($options['parenthesesDelimited'])) {
+ if (! empty($options['parenthesesDelimited'])) {
// The current token is the last bracket, the next
// one will be outside the expression.
$ret->expr .= $token->token;
@@ -332,7 +344,7 @@ class Expression extends Component
if ($alias) {
// An alias is expected (the keyword `AS` was previously found).
- if (!empty($ret->alias)) {
+ if (! empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
break;
}
@@ -345,13 +357,13 @@ class Expression extends Component
|| ((($prev[0]->type !== Token::TYPE_OPERATOR)
|| ($prev[0]->token === ')'))
&& (($prev[0]->type !== Token::TYPE_KEYWORD)
- || (!($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED)))))
+ || (! ($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED)))))
&& (($prev[1]->type === Token::TYPE_STRING)
|| (($prev[1]->type === Token::TYPE_SYMBOL)
- && (!($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)))
+ && (! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)))
|| ($prev[1]->type === Token::TYPE_NONE))
) {
- if (!empty($ret->alias)) {
+ if (! empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
break;
}
@@ -359,12 +371,12 @@ class Expression extends Component
} else {
$ret->expr .= $token->token;
}
- } elseif (!$isExpr) {
+ } elseif (! $isExpr) {
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '.')) {
// Found a `.` which means we expect a column name and
// the column name we parsed is actually the table name
// and the table name is actually a database name.
- if (!empty($ret->database) || $dot) {
+ if (! empty($ret->database) || $dot) {
$parser->error('Unexpected dot.', $token);
}
$ret->database = $ret->table;
@@ -380,10 +392,10 @@ class Expression extends Component
$dot = false;
} else {
// No alias is expected.
- if (!empty($options['breakOnAlias'])) {
+ if (! empty($options['breakOnAlias'])) {
break;
}
- if (!empty($ret->alias)) {
+ if (! empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
break;
}
@@ -418,16 +430,16 @@ class Expression extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode($component, ', ');
}
- if ($component->expr !== '' && !is_null($component->expr)) {
+ if ($component->expr !== '' && ! is_null($component->expr)) {
$ret = $component->expr;
} else {
- $fields = array();
+ $fields = [];
if (isset($component->database) && ($component->database !== '')) {
$fields[] = $component->database;
}
@@ -440,7 +452,7 @@ class Expression extends Component
$ret = implode('.', Context::escape($fields));
}
- if (!empty($component->alias)) {
+ if (! empty($component->alias)) {
$ret .= ' AS ' . Context::escape($component->alias);
}
diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php
index ab6988d..5d94681 100644
--- a/src/Components/ExpressionArray.php
+++ b/src/Components/ExpressionArray.php
@@ -27,9 +27,9 @@ class ExpressionArray extends Component
*
* @return Expression[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
/**
* The state of the parser.
@@ -115,9 +115,9 @@ class ExpressionArray extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
- $ret = array();
+ $ret = [];
foreach ($component as $frag) {
$ret[] = $frag::build($frag);
}
diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php
index 8334676..067987f 100644
--- a/src/Components/FunctionCall.php
+++ b/src/Components/FunctionCall.php
@@ -57,7 +57,7 @@ class FunctionCall extends Component
*
* @return FunctionCall
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -112,7 +112,7 @@ class FunctionCall extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
return $component->name . $component->parameters;
}
diff --git a/src/Components/GroupKeyword.php b/src/Components/GroupKeyword.php
index 314201b..86de663 100644
--- a/src/Components/GroupKeyword.php
+++ b/src/Components/GroupKeyword.php
@@ -44,9 +44,9 @@ class GroupKeyword extends Component
*
* @return GroupKeyword[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -93,7 +93,7 @@ class GroupKeyword extends Component
} elseif (($token->type === Token::TYPE_OPERATOR)
&& ($token->value === ',')
) {
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
$expr = new self();
@@ -105,7 +105,7 @@ class GroupKeyword extends Component
}
// Last iteration was not processed.
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
@@ -120,7 +120,7 @@ class GroupKeyword extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
diff --git a/src/Components/IndexHint.php b/src/Components/IndexHint.php
index 9534d2d..12edda7 100644
--- a/src/Components/IndexHint.php
+++ b/src/Components/IndexHint.php
@@ -44,9 +44,9 @@ class IndexHint extends Component
/**
* List of indexes in this hint
*
- * @var array
+ * @var array
*/
- public $indexes = array();
+ public $indexes = [];
/**
* Constructor.
@@ -56,7 +56,7 @@ class IndexHint extends Component
* @param string $for the clause for which this hint is (JOIN/ORDER BY/GROUP BY)
* @param string $indexes List of indexes in this hint
*/
- public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = array())
+ public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = [])
{
$this->type = $type;
$this->indexOrKey = $indexOrKey;
@@ -71,9 +71,9 @@ class IndexHint extends Component
*
* @return IndexHint|Component[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
$expr->type = isset($options['type']) ? $options['type'] : null;
/**
@@ -178,7 +178,7 @@ class IndexHint extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(' ', $component);
diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php
index c0fa390..524d94c 100644
--- a/src/Components/IntoKeyword.php
+++ b/src/Components/IntoKeyword.php
@@ -25,22 +25,37 @@ class IntoKeyword extends Component
*
* @var array
*/
- public static $FIELDS_OPTIONS = array(
- 'TERMINATED BY' => array(1, 'expr'),
+ public static $FIELDS_OPTIONS = [
+ 'TERMINATED BY' => [
+ 1,
+ 'expr',
+ ],
'OPTIONALLY' => 2,
- 'ENCLOSED BY' => array(3, 'expr'),
- 'ESCAPED BY' => array(4, 'expr'),
- );
+ 'ENCLOSED BY' => [
+ 3,
+ 'expr',
+ ],
+ 'ESCAPED BY' => [
+ 4,
+ 'expr',
+ ],
+ ];
/**
* LINES Options for `SELECT...INTO` statements.
*
* @var array
*/
- public static $LINES_OPTIONS = array(
- 'STARTING BY' => array(1, 'expr'),
- 'TERMINATED BY' => array(2, 'expr'),
- );
+ public static $LINES_OPTIONS = [
+ 'STARTING BY' => [
+ 1,
+ 'expr',
+ ],
+ 'TERMINATED BY' => [
+ 2,
+ 'expr',
+ ],
+ ];
/**
* Type of target (OUTFILE or SYMBOL).
@@ -128,7 +143,7 @@ class IntoKeyword extends Component
*
* @return IntoKeyword
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -188,10 +203,10 @@ class IntoKeyword extends Component
$ret->dest = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
} else {
$ret->values = ExpressionArray::parse($parser, $list);
@@ -254,10 +269,10 @@ class IntoKeyword extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if ($component->dest instanceof Expression) {
- $columns = !empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : '';
+ $columns = ! empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : '';
return $component->dest . $columns;
} elseif (isset($component->values)) {
@@ -272,7 +287,7 @@ class IntoKeyword extends Component
$ret .= ' ' . $fields_options_str;
}
- $lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true));
+ $lines_options_str = OptionsArray::build($component->lines_options, ['expr' => true]);
if (trim($lines_options_str) !== '') {
$ret .= ' LINES ' . $lines_options_str;
}
diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php
index 786092d..6a13177 100644
--- a/src/Components/JoinKeyword.php
+++ b/src/Components/JoinKeyword.php
@@ -25,7 +25,7 @@ class JoinKeyword extends Component
*
* @var array
*/
- public static $JOINS = array(
+ public static $JOINS = [
'CROSS JOIN' => 'CROSS',
'FULL JOIN' => 'FULL',
'FULL OUTER JOIN' => 'FULL',
@@ -41,7 +41,7 @@ class JoinKeyword extends Component
'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER',
'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER',
'STRAIGHT_JOIN' => 'STRAIGHT',
- );
+ ];
/**
* Type of this join.
@@ -98,9 +98,9 @@ class JoinKeyword extends Component
*
* @return JoinKeyword[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -151,7 +151,7 @@ class JoinKeyword extends Component
if ($state === 0) {
if (($token->type === Token::TYPE_KEYWORD)
- && !empty(static::$JOINS[$token->keyword])
+ && ! empty(static::$JOINS[$token->keyword])
) {
$expr->type = static::$JOINS[$token->keyword];
$state = 1;
@@ -159,19 +159,19 @@ class JoinKeyword extends Component
break;
}
} elseif ($state === 1) {
- $expr->expr = Expression::parse($parser, $list, array('field' => 'table'));
+ $expr->expr = Expression::parse($parser, $list, ['field' => 'table']);
$state = 2;
} elseif ($state === 2) {
if ($token->type === Token::TYPE_KEYWORD) {
- switch($token->keyword) {
+ switch ($token->keyword) {
case 'ON':
$state = 3;
- break;
+ break;
case 'USING':
$state = 4;
- break;
+ break;
default:
- if (!empty(static::$JOINS[$token->keyword])
+ if (! empty(static::$JOINS[$token->keyword])
) {
$ret[] = $expr;
$expr = new self();
@@ -181,7 +181,7 @@ class JoinKeyword extends Component
/* Next clause is starting */
break 2;
}
- break;
+ break;
}
}
} elseif ($state === 3) {
@@ -197,7 +197,7 @@ class JoinKeyword extends Component
}
}
- if (!empty($expr->type)) {
+ if (! empty($expr->type)) {
$ret[] = $expr;
}
@@ -212,14 +212,14 @@ class JoinKeyword extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
- $ret = array();
+ $ret = [];
foreach ($component as $c) {
$ret[] = array_search($c->type, static::$JOINS) . ' ' . $c->expr
- . (!empty($c->on)
+ . (! empty($c->on)
? ' ON ' . Condition::build($c->on) : '')
- . (!empty($c->using)
+ . (! empty($c->using)
? ' USING ' . ArrayObj::build($c->using) : '');
}
diff --git a/src/Components/Key.php b/src/Components/Key.php
index bd3bbd1..3093f01 100644
--- a/src/Components/Key.php
+++ b/src/Components/Key.php
@@ -28,12 +28,24 @@ class Key extends Component
*
* @var array
*/
- public static $KEY_OPTIONS = array(
- 'KEY_BLOCK_SIZE' => array(1, 'var'),
- 'USING' => array(2, 'var'),
- 'WITH PARSER' => array(3, 'var'),
- 'COMMENT' => array(4, 'var='),
- );
+ public static $KEY_OPTIONS = [
+ 'KEY_BLOCK_SIZE' => [
+ 1,
+ 'var',
+ ],
+ 'USING' => [
+ 2,
+ 'var',
+ ],
+ 'WITH PARSER' => [
+ 3,
+ 'var',
+ ],
+ 'COMMENT' => [
+ 4,
+ 'var=',
+ ],
+ ];
/**
* The name of this key.
@@ -73,7 +85,7 @@ class Key extends Component
*/
public function __construct(
$name = null,
- array $columns = array(),
+ array $columns = [],
$type = null,
$options = null
) {
@@ -90,7 +102,7 @@ class Key extends Component
*
* @return Key
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -99,7 +111,7 @@ class Key extends Component
*
* @var array
*/
- $lastColumn = array();
+ $lastColumn = [];
/**
* The state of the parser.
@@ -150,9 +162,9 @@ class Key extends Component
$state = 3;
} elseif (($token->value === ',') || ($token->value === ')')) {
$state = ($token->value === ',') ? 2 : 4;
- if (!empty($lastColumn)) {
+ if (! empty($lastColumn)) {
$ret->columns[] = $lastColumn;
- $lastColumn = array();
+ $lastColumn = [];
}
}
} else {
@@ -182,14 +194,14 @@ class Key extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
$ret = $component->type . ' ';
- if (!empty($component->name)) {
+ if (! empty($component->name)) {
$ret .= Context::escape($component->name) . ' ';
}
- $columns = array();
+ $columns = [];
foreach ($component->columns as $column) {
$tmp = Context::escape($column['name']);
if (isset($column['length'])) {
diff --git a/src/Components/Limit.php b/src/Components/Limit.php
index 17423e2..d02ce49 100644
--- a/src/Components/Limit.php
+++ b/src/Components/Limit.php
@@ -53,7 +53,7 @@ class Limit extends Component
*
* @return Limit
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -121,7 +121,7 @@ class Limit extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
return $component->offset . ', ' . $component->rowCount;
}
diff --git a/src/Components/LockExpression.php b/src/Components/LockExpression.php
index 644e3ca..7cbfa72 100644
--- a/src/Components/LockExpression.php
+++ b/src/Components/LockExpression.php
@@ -35,13 +35,13 @@ class LockExpression extends Component
public $type;
/**
- * @param Parser $parser the parser that serves as context
- * @param TokensList $list the list of tokens that are being parsed
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
* @param array $options parameters for parsing
*
* @return CaseExpression
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -77,7 +77,7 @@ class LockExpression extends Component
}
if ($state === 0) {
- $ret->table = Expression::parse($parser, $list, array('parseField' => 'table'));
+ $ret->table = Expression::parse($parser, $list, ['parseField' => 'table']);
$state = 1;
} elseif ($state === 1) {
// parse lock type
@@ -103,7 +103,7 @@ class LockExpression extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
@@ -112,7 +112,8 @@ class LockExpression extends Component
return $component->table . ' ' . $component->type;
}
- private static function parseLockType(Parser $parser, TokensList $list) {
+ private static function parseLockType(Parser $parser, TokensList $list)
+ {
$lockType = '';
/**
diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php
index fd02d22..2b17cdd 100644
--- a/src/Components/OptionsArray.php
+++ b/src/Components/OptionsArray.php
@@ -26,7 +26,7 @@ class OptionsArray extends Component
*
* @var array
*/
- public $options = array();
+ public $options = [];
/**
* Constructor.
@@ -35,7 +35,7 @@ class OptionsArray extends Component
* must be an array with at least two keys `name` and
* `expr` or `value`.
*/
- public function __construct(array $options = array())
+ public function __construct(array $options = [])
{
$this->options = $options;
}
@@ -47,7 +47,7 @@ class OptionsArray extends Component
*
* @return OptionsArray
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -156,7 +156,7 @@ class OptionsArray extends Component
}
if ($state === 0) {
- if (!is_array($lastOption)) {
+ if (! is_array($lastOption)) {
// This is a just keyword option without any value.
// This is the beginning and the end of it.
$ret->options[$lastOptionId] = $token->value;
@@ -167,7 +167,7 @@ class OptionsArray extends Component
// This is only the beginning. The value is parsed in state
// 1 and 2. State 1 is used to skip the first equals sign
// and state 2 to parse the actual value.
- $ret->options[$lastOptionId] = array(
+ $ret->options[$lastOptionId] = [
// @var string The name of the option.
'name' => $token->value,
// @var bool Whether it contains an equal sign.
@@ -177,7 +177,7 @@ class OptionsArray extends Component
'expr' => '',
// @var string Processed value.
'value' => '',
- );
+ ];
$state = 1;
} elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') {
// This is a keyword that is followed by an expression.
@@ -185,7 +185,7 @@ class OptionsArray extends Component
// Skipping this option in order to parse the expression.
++$list->idx;
- $ret->options[$lastOptionId] = array(
+ $ret->options[$lastOptionId] = [
// @var string The name of the option.
'name' => $token->value,
// @var bool Whether it contains an equal sign.
@@ -193,7 +193,7 @@ class OptionsArray extends Component
'equals' => $lastOption[1] === 'expr=',
// @var Expression The parsed expression.
'expr' => '',
- );
+ ];
$state = 1;
}
} elseif ($state === 1) {
@@ -211,7 +211,7 @@ class OptionsArray extends Component
$ret->options[$lastOptionId]['expr'] = Expression::parse(
$parser,
$list,
- empty($lastOption[2]) ? array() : $lastOption[2]
+ empty($lastOption[2]) ? [] : $lastOption[2]
);
$ret->options[$lastOptionId]['value']
= $ret->options[$lastOptionId]['expr']->expr;
@@ -226,7 +226,7 @@ class OptionsArray extends Component
$ret->options[$lastOptionId]['expr'] .= $token->token;
- if (!((($token->token === '(') && ($brackets === 1))
+ if (! ((($token->token === '(') && ($brackets === 1))
|| (($token->token === ')') && ($brackets === 0)))
) {
// First pair of brackets is being skipped.
@@ -276,20 +276,20 @@ class OptionsArray extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (empty($component->options)) {
return '';
}
- $options = array();
+ $options = [];
foreach ($component->options as $option) {
- if (!is_array($option)) {
+ if (! is_array($option)) {
$options[] = $option;
} else {
$options[] = $option['name']
- . ((!empty($option['equals']) && $option['equals']) ? '=' : ' ')
- . (!empty($option['expr']) ? $option['expr'] : $option['value']);
+ . ((! empty($option['equals']) && $option['equals']) ? '=' : ' ')
+ . (! empty($option['expr']) ? $option['expr'] : $option['value']);
}
}
@@ -309,10 +309,10 @@ class OptionsArray extends Component
{
foreach ($this->options as $option) {
if (is_array($option)) {
- if (!strcasecmp($key, $option['name'])) {
+ if (! strcasecmp($key, $option['name'])) {
return $getExpr ? $option['expr'] : $option['value'];
}
- } elseif (!strcasecmp($key, $option)) {
+ } elseif (! strcasecmp($key, $option)) {
return true;
}
}
@@ -331,12 +331,12 @@ class OptionsArray extends Component
{
foreach ($this->options as $idx => $option) {
if (is_array($option)) {
- if (!strcasecmp($key, $option['name'])) {
+ if (! strcasecmp($key, $option['name'])) {
unset($this->options[$idx]);
return true;
}
- } elseif (!strcasecmp($key, $option)) {
+ } elseif (! strcasecmp($key, $option)) {
unset($this->options[$idx]);
return true;
diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php
index 77d5a3d..f6d60eb 100644
--- a/src/Components/OrderKeyword.php
+++ b/src/Components/OrderKeyword.php
@@ -53,9 +53,9 @@ class OrderKeyword extends Component
*
* @return OrderKeyword[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -102,7 +102,7 @@ class OrderKeyword extends Component
} elseif (($token->type === Token::TYPE_OPERATOR)
&& ($token->value === ',')
) {
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
$expr = new self();
@@ -114,7 +114,7 @@ class OrderKeyword extends Component
}
// Last iteration was not processed.
- if (!empty($expr->expr)) {
+ if (! empty($expr->expr)) {
$ret[] = $expr;
}
@@ -129,7 +129,7 @@ class OrderKeyword extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php
index 1f810f5..f45d6ac 100644
--- a/src/Components/ParameterDefinition.php
+++ b/src/Components/ParameterDefinition.php
@@ -63,9 +63,9 @@ class ParameterDefinition extends Component
*
* @return ParameterDefinition[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -153,14 +153,14 @@ class ParameterDefinition extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return '(' . implode(', ', $component) . ')';
}
$tmp = '';
- if (!empty($component->inOut)) {
+ if (! empty($component->inOut)) {
$tmp .= $component->inOut . ' ';
}
diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php
index 2fc769e..03f4aa6 100644
--- a/src/Components/PartitionDefinition.php
+++ b/src/Components/PartitionDefinition.php
@@ -29,17 +29,44 @@ class PartitionDefinition extends Component
*
* @var array
*/
- public static $OPTIONS = array(
- 'STORAGE ENGINE' => array(1, 'var'),
- 'ENGINE' => array(1, 'var'),
- 'COMMENT' => array(2, 'var'),
- 'DATA DIRECTORY' => array(3, 'var'),
- 'INDEX DIRECTORY' => array(4, 'var'),
- 'MAX_ROWS' => array(5, 'var'),
- 'MIN_ROWS' => array(6, 'var'),
- 'TABLESPACE' => array(7, 'var'),
- 'NODEGROUP' => array(8, 'var'),
- );
+ public static $OPTIONS = [
+ 'STORAGE ENGINE' => [
+ 1,
+ 'var',
+ ],
+ 'ENGINE' => [
+ 1,
+ 'var',
+ ],
+ 'COMMENT' => [
+ 2,
+ 'var',
+ ],
+ 'DATA DIRECTORY' => [
+ 3,
+ 'var',
+ ],
+ 'INDEX DIRECTORY' => [
+ 4,
+ 'var',
+ ],
+ 'MAX_ROWS' => [
+ 5,
+ 'var',
+ ],
+ 'MIN_ROWS' => [
+ 6,
+ 'var',
+ ],
+ 'TABLESPACE' => [
+ 7,
+ 'var',
+ ],
+ 'NODEGROUP' => [
+ 8,
+ 'var',
+ ],
+ ];
/**
* Whether this entry is a subpartition or a partition.
@@ -90,7 +117,7 @@ class PartitionDefinition extends Component
*
* @return PartitionDefinition
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -163,10 +190,10 @@ class PartitionDefinition extends Component
$ret->expr = Expression::parse(
$parser,
$list,
- array(
+ [
'parenthesesDelimited' => true,
'breakOnAlias' => true,
- )
+ ]
);
}
$state = 5;
@@ -178,9 +205,9 @@ class PartitionDefinition extends Component
$ret->subpartitions = ArrayObj::parse(
$parser,
$list,
- array(
+ [
'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition',
- )
+ ]
);
++$list->idx;
}
@@ -199,7 +226,7 @@ class PartitionDefinition extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return "(\n" . implode(",\n", $component) . "\n)";
@@ -214,7 +241,7 @@ class PartitionDefinition extends Component
return trim(
'PARTITION ' . $component->name
. (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ')
- . ((!empty($component->options) && !empty($component->type)) ? '' : ' ') . $component->options . $subpartitions
+ . ((! empty($component->options) && ! empty($component->type)) ? '' : ' ') . $component->options . $subpartitions
);
}
}
diff --git a/src/Components/Reference.php b/src/Components/Reference.php
index 798eb68..3f8e453 100644
--- a/src/Components/Reference.php
+++ b/src/Components/Reference.php
@@ -26,11 +26,20 @@ class Reference extends Component
*
* @var array
*/
- public static $REFERENCES_OPTIONS = array(
- 'MATCH' => array(1, 'var'),
- 'ON DELETE' => array(2, 'var'),
- 'ON UPDATE' => array(3, 'var'),
- );
+ public static $REFERENCES_OPTIONS = [
+ 'MATCH' => [
+ 1,
+ 'var',
+ ],
+ 'ON DELETE' => [
+ 2,
+ 'var',
+ ],
+ 'ON UPDATE' => [
+ 3,
+ 'var',
+ ],
+ ];
/**
* The referenced table.
@@ -60,7 +69,7 @@ class Reference extends Component
* @param array $columns the columns referenced
* @param OptionsArray $options the options
*/
- public function __construct($table = null, array $columns = array(), $options = null)
+ public function __construct($table = null, array $columns = [], $options = null)
{
$this->table = $table;
$this->columns = $columns;
@@ -74,7 +83,7 @@ class Reference extends Component
*
* @return Reference
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
$ret = new self();
@@ -115,10 +124,10 @@ class Reference extends Component
$ret->table = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
$state = 1;
} elseif ($state === 1) {
@@ -142,7 +151,7 @@ class Reference extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
return trim(
$component->table
diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php
index e9bd9ce..4bdb67e 100644
--- a/src/Components/RenameOperation.php
+++ b/src/Components/RenameOperation.php
@@ -53,9 +53,9 @@ class RenameOperation extends Component
*
* @return RenameOperation[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -99,10 +99,10 @@ class RenameOperation extends Component
$expr->old = Expression::parse(
$parser,
$list,
- array(
+ [
'breakOnAlias' => true,
'parseField' => 'table',
- )
+ ]
);
if (empty($expr->old)) {
$parser->error(
@@ -125,10 +125,10 @@ class RenameOperation extends Component
$expr->new = Expression::parse(
$parser,
$list,
- array(
+ [
'breakOnAlias' => true,
'parseField' => 'table',
- )
+ ]
);
if (empty($expr->new)) {
$parser->error(
@@ -156,7 +156,7 @@ class RenameOperation extends Component
}
// Last iteration was not saved.
- if (!empty($expr->old)) {
+ if (! empty($expr->old)) {
$ret[] = $expr;
}
@@ -171,7 +171,7 @@ class RenameOperation extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php
index 2945a8e..68f2297 100644
--- a/src/Components/SetOperation.php
+++ b/src/Components/SetOperation.php
@@ -53,9 +53,9 @@ class SetOperation extends Component
*
* @return SetOperation[]
*/
- public static function parse(Parser $parser, TokensList $list, array $options = array())
+ public static function parse(Parser $parser, TokensList $list, array $options = [])
{
- $ret = array();
+ $ret = [];
$expr = new self();
@@ -118,9 +118,9 @@ class SetOperation extends Component
$tmp = Expression::parse(
$parser,
$list,
- array(
+ [
'breakOnAlias' => true,
- )
+ ]
);
if (is_null($tmp)) {
$parser->error('Missing expression.', $token);
@@ -150,7 +150,7 @@ class SetOperation extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
if (is_array($component)) {
return implode(', ', $component);
diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php
index 2de5126..220f86e 100644
--- a/src/Components/UnionKeyword.php
+++ b/src/Components/UnionKeyword.php
@@ -23,9 +23,9 @@ class UnionKeyword extends Component
*
* @return string
*/
- public static function build($component, array $options = array())
+ public static function build($component, array $options = [])
{
- $tmp = array();
+ $tmp = [];
foreach ($component as $componentPart) {
$tmp[] = $componentPart[0] . ' ' . $componentPart[1];
}
diff --git a/src/Context.php b/src/Context.php
index 869a9bb..646f373 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -86,14 +86,14 @@ abstract class Context
*
* @var array
*/
- public static $KEYWORDS = array();
+ public static $KEYWORDS = [];
/**
* List of operators and their flags.
*
* @var array
*/
- public static $OPERATORS = array(
+ public static $OPERATORS = [
// Some operators (*, =) may have ambiguous flags, because they depend on
// the context they are being used in.
// For example: 1. SELECT * FROM table; # SQL specific (wildcard)
@@ -102,23 +102,43 @@ abstract class Context
// SET @i = 0;
// @see Token::FLAG_OPERATOR_ARITHMETIC
- '%' => 1, '*' => 1, '+' => 1, '-' => 1, '/' => 1,
+ '%' => 1,
+ '*' => 1,
+ '+' => 1,
+ '-' => 1,
+ '/' => 1,
// @see Token::FLAG_OPERATOR_LOGICAL
- '!' => 2, '!=' => 2, '&&' => 2, '<' => 2, '<=' => 2,
- '<=>' => 2, '<>' => 2, '=' => 2, '>' => 2, '>=' => 2,
+ '!' => 2,
+ '!=' => 2,
+ '&&' => 2,
+ '<' => 2,
+ '<=' => 2,
+ '<=>' => 2,
+ '<>' => 2,
+ '=' => 2,
+ '>' => 2,
+ '>=' => 2,
'||' => 2,
// @see Token::FLAG_OPERATOR_BITWISE
- '&' => 4, '<<' => 4, '>>' => 4, '^' => 4, '|' => 4,
+ '&' => 4,
+ '<<' => 4,
+ '>>' => 4,
+ '^' => 4,
+ '|' => 4,
'~' => 4,
// @see Token::FLAG_OPERATOR_ASSIGNMENT
':=' => 8,
// @see Token::FLAG_OPERATOR_SQL
- '(' => 16, ')' => 16, '.' => 16, ',' => 16, ';' => 16,
- );
+ '(' => 16,
+ ')' => 16,
+ '.' => 16,
+ ',' => 16,
+ ';' => 16,
+ ];
/**
* The mode of the MySQL server that will be used in lexing, parsing and
@@ -255,7 +275,7 @@ abstract class Context
$str = strtoupper($str);
if (isset(static::$KEYWORDS[$str])) {
- if ($isReserved && !(static::$KEYWORDS[$str] & Token::FLAG_KEYWORD_RESERVED)) {
+ if ($isReserved && ! (static::$KEYWORDS[$str] & Token::FLAG_KEYWORD_RESERVED)) {
return null;
}
@@ -277,7 +297,7 @@ abstract class Context
*/
public static function isOperator($str)
{
- if (!isset(static::$OPERATORS[$str])) {
+ if (! isset(static::$OPERATORS[$str])) {
return null;
}
@@ -459,7 +479,7 @@ abstract class Context
// Short context name (must be formatted into class name).
$context = self::$contextPrefix . $context;
}
- if (!class_exists($context)) {
+ if (! class_exists($context)) {
throw @new LoaderException(
'Specified context ("' . $context . '") does not exist.',
$context
@@ -548,7 +568,7 @@ abstract class Context
}
if ((static::$MODE & self::SQL_MODE_NO_ENCLOSING_QUOTES)
- && (!static::isKeyword($str, true))
+ && (! static::isKeyword($str, true))
) {
return $str;
}
diff --git a/src/Contexts/ContextMariaDb100000.php b/src/Contexts/ContextMariaDb100000.php
index ed4aa81..a260083 100644
--- a/src/Contexts/ContextMariaDb100000.php
+++ b/src/Contexts/ContextMariaDb100000.php
@@ -33,7 +33,7 @@ class ContextMariaDb100000 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1,
@@ -312,5 +312,5 @@ class ContextMariaDb100000 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMariaDb100100.php b/src/Contexts/ContextMariaDb100100.php
index c9f38a1..0208084 100644
--- a/src/Contexts/ContextMariaDb100100.php
+++ b/src/Contexts/ContextMariaDb100100.php
@@ -33,7 +33,7 @@ class ContextMariaDb100100 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1, 'XID' => 1,
@@ -361,5 +361,5 @@ class ContextMariaDb100100 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMariaDb100200.php b/src/Contexts/ContextMariaDb100200.php
index 66f7d57..f2f7334 100644
--- a/src/Contexts/ContextMariaDb100200.php
+++ b/src/Contexts/ContextMariaDb100200.php
@@ -33,7 +33,7 @@ class ContextMariaDb100200 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1, 'XID' => 1,
@@ -361,5 +361,5 @@ class ContextMariaDb100200 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMariaDb100300.php b/src/Contexts/ContextMariaDb100300.php
index 73f729b..c2a3847 100644
--- a/src/Contexts/ContextMariaDb100300.php
+++ b/src/Contexts/ContextMariaDb100300.php
@@ -33,7 +33,7 @@ class ContextMariaDb100300 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1, 'XID' => 1,
@@ -361,5 +361,5 @@ class ContextMariaDb100300 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql50000.php b/src/Contexts/ContextMySql50000.php
index c07334c..649a731 100644
--- a/src/Contexts/ContextMySql50000.php
+++ b/src/Contexts/ContextMySql50000.php
@@ -33,7 +33,7 @@ class ContextMySql50000 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1,
'NEW' => 1, 'ONE' => 1, 'ROW' => 1,
@@ -282,5 +282,5 @@ class ContextMySql50000 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql50100.php b/src/Contexts/ContextMySql50100.php
index 35a0b73..2531f2c 100644
--- a/src/Contexts/ContextMySql50100.php
+++ b/src/Contexts/ContextMySql50100.php
@@ -33,7 +33,7 @@ class ContextMySql50100 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1,
'NEW' => 1, 'ONE' => 1, 'ROW' => 1,
@@ -307,5 +307,5 @@ class ContextMySql50100 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql50500.php b/src/Contexts/ContextMySql50500.php
index 8ff3d71..9587116 100644
--- a/src/Contexts/ContextMySql50500.php
+++ b/src/Contexts/ContextMySql50500.php
@@ -33,7 +33,7 @@ class ContextMySql50500 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1,
@@ -312,5 +312,5 @@ class ContextMySql50500 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql50600.php b/src/Contexts/ContextMySql50600.php
index b8fe2ec..0720957 100644
--- a/src/Contexts/ContextMySql50600.php
+++ b/src/Contexts/ContextMySql50600.php
@@ -33,7 +33,7 @@ class ContextMySql50600 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1,
@@ -341,5 +341,5 @@ class ContextMySql50600 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql50700.php b/src/Contexts/ContextMySql50700.php
index 1899882..b87affa 100644
--- a/src/Contexts/ContextMySql50700.php
+++ b/src/Contexts/ContextMySql50700.php
@@ -33,7 +33,7 @@ class ContextMySql50700 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1, 'XID' => 1,
@@ -361,5 +361,5 @@ class ContextMySql50700 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Contexts/ContextMySql80000.php b/src/Contexts/ContextMySql80000.php
index 23f33c7..35ac008 100644
--- a/src/Contexts/ContextMySql80000.php
+++ b/src/Contexts/ContextMySql80000.php
@@ -33,7 +33,7 @@ class ContextMySql80000 extends Context
*
* @var array
*/
- public static $KEYWORDS = array(
+ public static $KEYWORDS = [
'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1,
'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1,
'ONE' => 1, 'ROW' => 1, 'XID' => 1,
@@ -361,5 +361,5 @@ class ContextMySql80000 extends Context
'CHAR' => 43,
'BINARY' => 43,
'INTERVAL' => 43,
- );
+ ];
}
diff --git a/src/Core.php b/src/Core.php
index 052ac5e..5672b99 100644
--- a/src/Core.php
+++ b/src/Core.php
@@ -28,7 +28,7 @@ class Core
*
* @see Core::error()
*/
- public $errors = array();
+ public $errors = [];
/**
* Creates a new error log.
diff --git a/src/Exceptions/LoaderException.php b/src/Exceptions/LoaderException.php
index ce962f0..bfbd4c3 100644
--- a/src/Exceptions/LoaderException.php
+++ b/src/Exceptions/LoaderException.php
@@ -26,7 +26,7 @@ class LoaderException extends \Exception
* Constructor.
*
* @param string $msg the message of this exception
- * @param string $name the character that produced this exception
+ * @param string $name the character that produced this exception
* @param int $code the code of this error
*/
public function __construct($msg = '', $name = '', $code = 0)
diff --git a/src/Lexer.php b/src/Lexer.php
index ef1ca68..13796cd 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -12,7 +12,7 @@ namespace PhpMyAdmin\SqlParser;
use PhpMyAdmin\SqlParser\Exceptions\LexerException;
-if (!defined('USE_UTF_STRINGS')) {
+if (! defined('USE_UTF_STRINGS')) {
// NOTE: In previous versions of PHP (5.5 and older) the default
// internal encoding is "ISO-8859-1".
// All `mb_` functions must specify the correct encoding, which is
@@ -46,7 +46,7 @@ class Lexer extends Core
*
* @var array
*/
- public static $PARSER_METHODS = array(
+ public static $PARSER_METHODS = [
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
@@ -70,10 +70,18 @@ class Lexer extends Core
// They fight over words. `parseUnknown` does not know about
// keywords.
- 'parseDelimiter', 'parseWhitespace', 'parseNumber',
- 'parseComment', 'parseOperator', 'parseBool', 'parseString',
- 'parseSymbol', 'parseKeyword', 'parseLabel', 'parseUnknown',
- );
+ 'parseDelimiter',
+ 'parseWhitespace',
+ 'parseNumber',
+ 'parseComment',
+ 'parseOperator',
+ 'parseBool',
+ 'parseString',
+ 'parseSymbol',
+ 'parseKeyword',
+ 'parseLabel',
+ 'parseUnknown',
+ ];
/**
* The string to be parsed.
@@ -165,7 +173,7 @@ class Lexer extends Core
// For multi-byte strings, a new instance of `UtfString` is
// initialized (only if `UtfString` usage is forced.
- if (!$str instanceof UtfString && USE_UTF_STRINGS && $len !== mb_strlen($str, 'UTF-8')) {
+ if (! $str instanceof UtfString && USE_UTF_STRINGS && $len !== mb_strlen($str, 'UTF-8')) {
$str = new UtfString($str);
}
@@ -176,7 +184,7 @@ class Lexer extends Core
// Setting the delimiter.
$this->setDelimiter(
- !empty($delimiter) ? $delimiter : static::$DEFAULT_DELIMITER
+ ! empty($delimiter) ? $delimiter : static::$DEFAULT_DELIMITER
);
$this->lex();
@@ -304,7 +312,7 @@ class Lexer extends Core
// Parsing the delimiter.
$this->delimiter = null;
$delimiterLen = 0;
- while (++$this->last < $this->len && !Context::isWhitespace($this->str[$this->last]) && $delimiterLen < 15) {
+ while (++$this->last < $this->len && ! Context::isWhitespace($this->str[$this->last]) && $delimiterLen < 15) {
$this->delimiter .= $this->str[$this->last];
++$delimiterLen;
}
@@ -351,7 +359,9 @@ class Lexer extends Core
{
$error = new LexerException(
Translator::gettext($msg),
- $str, $pos, $code
+ $str,
+ $pos,
+ $code
);
parent::error($error);
}
@@ -507,7 +517,7 @@ class Lexer extends Core
{
$token = $this->str[$this->last];
- if (!Context::isWhitespace($token)) {
+ if (! Context::isWhitespace($token)) {
return null;
}
@@ -532,8 +542,7 @@ class Lexer extends Core
// Bash style comments. (#comment\n)
if (Context::isComment($token)) {
- while (
- ++$this->last < $this->len
+ while (++$this->last < $this->len
&& $this->str[$this->last] !== "\n"
) {
$token .= $this->str[$this->last];
@@ -565,8 +574,7 @@ class Lexer extends Core
$flags |= Token::FLAG_COMMENT_MYSQL_CMD;
$token .= $this->str[++$this->last];
- while (
- ++$this->last < $this->len
+ while (++$this->last < $this->len
&& $this->str[$this->last] >= '0'
&& $this->str[$this->last] <= '9'
) {
@@ -580,8 +588,7 @@ class Lexer extends Core
}
// Parsing the comment.
- while (
- ++$this->last < $this->len
+ while (++$this->last < $this->len
&& (
$this->str[$this->last - 1] !== '*'
|| $this->str[$this->last] !== '/'
@@ -610,8 +617,7 @@ class Lexer extends Core
if (Context::isComment($token, $end)) {
// Checking if this comment did not end already (```--\n```).
if ($this->str[$this->last] !== "\n") {
- while (
- ++$this->last < $this->len
+ while (++$this->last < $this->len
&& $this->str[$this->last] !== "\n"
) {
$token .= $this->str[$this->last];
@@ -733,8 +739,7 @@ class Lexer extends Core
}
} elseif ($state === 2) {
$flags |= Token::FLAG_NUMBER_HEX;
- if (
- !(
+ if (! (
($this->str[$this->last] >= '0' && $this->str[$this->last] <= '9')
|| ($this->str[$this->last] >= 'A' && $this->str[$this->last] <= 'F')
|| ($this->str[$this->last] >= 'a' && $this->str[$this->last] <= 'f')
@@ -816,7 +821,7 @@ class Lexer extends Core
public function parseString($quote = '')
{
$token = $this->str[$this->last];
- if (!($flags = Context::isString($token)) && $token !== $quote) {
+ if (! ($flags = Context::isString($token)) && $token !== $quote) {
return null;
}
$quote = $token;
@@ -861,7 +866,7 @@ class Lexer extends Core
public function parseSymbol()
{
$token = $this->str[$this->last];
- if (!($flags = Context::isSymbol($token))) {
+ if (! ($flags = Context::isSymbol($token))) {
return null;
}
@@ -912,7 +917,7 @@ class Lexer extends Core
return null;
}
- while (++$this->last < $this->len && !Context::isSeparator($this->str[$this->last])) {
+ while (++$this->last < $this->len && ! Context::isSeparator($this->str[$this->last])) {
$token .= $this->str[$this->last];
}
--$this->last;
diff --git a/src/Parser.php b/src/Parser.php
index ec8637a..c0e755a 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -27,7 +27,7 @@ class Parser extends Core
*
* @var array
*/
- public static $STATEMENT_PARSERS = array(
+ public static $STATEMENT_PARSERS = [
// MySQL Utility Statements
'DESCRIBE' => 'PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement',
'DESC' => 'PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement',
@@ -93,246 +93,246 @@ class Parser extends Core
// https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html
'LOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement',
'UNLOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement',
- );
+ ];
/**
* Array of classes that are used in parsing SQL components.
*
* @var array
*/
- public static $KEYWORD_PARSERS = array(
+ public static $KEYWORD_PARSERS = [
// This is not a proper keyword and was added here to help the
// formatter.
- 'PARTITION BY' => array(),
- 'SUBPARTITION BY' => array(),
+ 'PARTITION BY' => [],
+ 'SUBPARTITION BY' => [],
// This is not a proper keyword and was added here to help the
// builder.
- '_OPTIONS' => array(
+ '_OPTIONS' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\OptionsArray',
'field' => 'options',
- ),
- '_END_OPTIONS' => array(
+ ],
+ '_END_OPTIONS' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\OptionsArray',
'field' => 'end_options',
- ),
+ ],
- 'INTERSECT' => array(
+ 'INTERSECT' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
- ),
- 'EXCEPT' => array(
+ ],
+ 'EXCEPT' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
- ),
- 'UNION' => array(
+ ],
+ 'UNION' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
- ),
- 'UNION ALL' => array(
+ ],
+ 'UNION ALL' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
- ),
- 'UNION DISTINCT' => array(
+ ],
+ 'UNION DISTINCT' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
- ),
+ ],
// Actual clause parsers.
- 'ALTER' => array(
+ 'ALTER' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'ANALYZE' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'ANALYZE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'BACKUP' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'BACKUP' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CALL' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'CALL' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\FunctionCall',
'field' => 'call',
- ),
- 'CHECK' => array(
+ ],
+ 'CHECK' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CHECKSUM' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'CHECKSUM' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CROSS JOIN' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'CROSS JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'DROP' => array(
+ ],
+ 'DROP' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'fields',
- 'options' => array('parseField' => 'table'),
- ),
- 'FORCE' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'FORCE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint',
'field' => 'index_hints',
- ),
- 'FROM' => array(
+ ],
+ 'FROM' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'from',
- 'options' => array('field' => 'table'),
- ),
- 'GROUP BY' => array(
+ 'options' => ['field' => 'table'],
+ ],
+ 'GROUP BY' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\GroupKeyword',
'field' => 'group',
- ),
- 'HAVING' => array(
+ ],
+ 'HAVING' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Condition',
'field' => 'having',
- ),
- 'IGNORE' => array(
+ ],
+ 'IGNORE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint',
'field' => 'index_hints',
- ),
- 'INTO' => array(
+ ],
+ 'INTO' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\IntoKeyword',
'field' => 'into',
- ),
- 'JOIN' => array(
+ ],
+ 'JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'LEFT JOIN' => array(
+ ],
+ 'LEFT JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'LEFT OUTER JOIN' => array(
+ ],
+ 'LEFT OUTER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'ON' => array(
+ ],
+ 'ON' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'RIGHT JOIN' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'RIGHT JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'RIGHT OUTER JOIN' => array(
+ ],
+ 'RIGHT OUTER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'INNER JOIN' => array(
+ ],
+ 'INNER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'FULL JOIN' => array(
+ ],
+ 'FULL JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'FULL OUTER JOIN' => array(
+ ],
+ 'FULL OUTER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'NATURAL JOIN' => array(
+ ],
+ 'NATURAL JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'NATURAL LEFT JOIN' => array(
+ ],
+ 'NATURAL LEFT JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'NATURAL RIGHT JOIN' => array(
+ ],
+ 'NATURAL RIGHT JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'NATURAL LEFT OUTER JOIN' => array(
+ ],
+ 'NATURAL LEFT OUTER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'NATURAL RIGHT OUTER JOIN' => array(
+ ],
+ 'NATURAL RIGHT OUTER JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'STRAIGHT_JOIN' => array(
+ ],
+ 'STRAIGHT_JOIN' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword',
'field' => 'join',
- ),
- 'LIMIT' => array(
+ ],
+ 'LIMIT' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Limit',
'field' => 'limit',
- ),
- 'OPTIMIZE' => array(
+ ],
+ 'OPTIMIZE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'ORDER BY' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'ORDER BY' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\OrderKeyword',
'field' => 'order',
- ),
- 'PARTITION' => array(
+ ],
+ 'PARTITION' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ArrayObj',
'field' => 'partition',
- ),
- 'PROCEDURE' => array(
+ ],
+ 'PROCEDURE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\FunctionCall',
'field' => 'procedure',
- ),
- 'RENAME' => array(
+ ],
+ 'RENAME' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\RenameOperation',
'field' => 'renames',
- ),
- 'REPAIR' => array(
+ ],
+ 'REPAIR' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'RESTORE' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'RESTORE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'SET' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'SET' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\SetOperation',
'field' => 'set',
- ),
- 'SELECT' => array(
+ ],
+ 'SELECT' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'expr',
- ),
- 'TRUNCATE' => array(
+ ],
+ 'TRUNCATE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'UPDATE' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'UPDATE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray',
'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'USE' => array(
+ 'options' => ['parseField' => 'table'],
+ ],
+ 'USE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint',
'field' => 'index_hints',
- ),
- 'VALUE' => array(
+ ],
+ 'VALUE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Array2d',
'field' => 'values',
- ),
- 'VALUES' => array(
+ ],
+ 'VALUES' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Array2d',
'field' => 'values',
- ),
- 'WHERE' => array(
+ ],
+ 'WHERE' => [
'class' => 'PhpMyAdmin\\SqlParser\\Components\\Condition',
'field' => 'where',
- ),
- );
+ ],
+ ];
/**
* The list of tokens that are parsed.
@@ -346,7 +346,7 @@ class Parser extends Core
*
* @var Statement[]
*/
- public $statements = array();
+ public $statements = [];
/**
* The number of opened brackets.
@@ -470,7 +470,7 @@ class Parser extends Core
// Checking if it is a known statement that can be parsed.
if (empty(static::$STATEMENT_PARSERS[$token->keyword])) {
- if (!isset(static::$STATEMENT_PARSERS[$token->keyword])) {
+ if (! isset(static::$STATEMENT_PARSERS[$token->keyword])) {
// A statement is considered recognized if the parser
// is aware that it is a statement, but it does not have
// a parser for it yet.
@@ -511,7 +511,7 @@ class Parser extends Core
$prevLastIdx = $list->idx;
// Handles unions.
- if (!empty($unionType)
+ if (! empty($unionType)
&& ($lastStatement instanceof SelectStatement)
&& ($statement instanceof SelectStatement)
) {
@@ -526,13 +526,16 @@ class Parser extends Core
*
* @var SelectStatement $lastStatement
*/
- $lastStatement->union[] = array($unionType, $statement);
+ $lastStatement->union[] = [
+ $unionType,
+ $statement,
+ ];
// if there are no no delimiting brackets, the `ORDER` and
// `LIMIT` keywords actually belong to the first statement.
$lastStatement->order = $statement->order;
$lastStatement->limit = $statement->limit;
- $statement->order = array();
+ $statement->order = [];
$statement->limit = null;
// The statement actually ends where the last statement in
@@ -600,7 +603,8 @@ class Parser extends Core
{
$error = new ParserException(
Translator::gettext($msg),
- $token, $code
+ $token,
+ $code
);
parent::error($error);
}
diff --git a/src/Statement.php b/src/Statement.php
index 6eb42c7..281701c 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -39,7 +39,7 @@ abstract class Statement
*
* @var array
*/
- public static $OPTIONS = array();
+ public static $OPTIONS = [];
/**
* The clauses of this statement, in order.
@@ -53,7 +53,7 @@ abstract class Statement
*
* @var array
*/
- public static $CLAUSES = array();
+ public static $CLAUSES = [];
/**
* The options of this query.
@@ -117,7 +117,7 @@ abstract class Statement
*
* @var array
*/
- $built = array();
+ $built = [];
/**
* Statement's clauses.
@@ -165,7 +165,7 @@ abstract class Statement
// Checking if this field was already built.
if ($type & 1) {
- if (!empty($built[$field])) {
+ if (! empty($built[$field])) {
continue;
}
$built[$field] = true;
@@ -199,7 +199,7 @@ abstract class Statement
*
* @var array
*/
- $parsedClauses = array();
+ $parsedClauses = [];
// This may be corrected by the parser.
$this->first = $list->idx;
@@ -300,13 +300,13 @@ abstract class Statement
*
* @var array
*/
- $options = array();
+ $options = [];
// Looking for duplicated clauses.
- if (!empty(Parser::$KEYWORD_PARSERS[$token->value])
- || !empty(Parser::$STATEMENT_PARSERS[$token->value])
+ if (! empty(Parser::$KEYWORD_PARSERS[$token->value])
+ || ! empty(Parser::$STATEMENT_PARSERS[$token->value])
) {
- if (!empty($parsedClauses[$token->value])) {
+ if (! empty($parsedClauses[$token->value])) {
$parser->error(
'This type of clause was previously parsed.',
$token
@@ -317,17 +317,17 @@ abstract class Statement
}
// Checking if this is the beginning of a clause.
- if (!empty(Parser::$KEYWORD_PARSERS[$token->value]) && $list->idx < $list->count) {
+ if (! empty(Parser::$KEYWORD_PARSERS[$token->value]) && $list->idx < $list->count) {
$class = Parser::$KEYWORD_PARSERS[$token->value]['class'];
$field = Parser::$KEYWORD_PARSERS[$token->value]['field'];
- if (!empty(Parser::$KEYWORD_PARSERS[$token->value]['options'])) {
+ if (! empty(Parser::$KEYWORD_PARSERS[$token->value]['options'])) {
$options = Parser::$KEYWORD_PARSERS[$token->value]['options'];
}
}
// Checking if this is the beginning of the statement.
- if (!empty(Parser::$STATEMENT_PARSERS[$token->keyword])) {
- if (!empty(static::$CLAUSES) // Undefined for some statements.
+ if (! empty(Parser::$STATEMENT_PARSERS[$token->keyword])) {
+ if (! empty(static::$CLAUSES) // Undefined for some statements.
&& empty(static::$CLAUSES[$token->value])
) {
// Some keywords (e.g. `SET`) may be the beginning of a
@@ -341,7 +341,7 @@ abstract class Statement
);
break;
}
- if (!$parsedOptions) {
+ if (! $parsedOptions) {
if (empty(static::$OPTIONS[$token->value])) {
// Skipping keyword because if it is not a option.
++$list->idx;
@@ -513,7 +513,7 @@ abstract class Statement
if ($minJoin === 0 && stripos($clauseType, 'JOIN')) {
// First JOIN clause is detected
$minJoin = $maxJoin = $clauseStartIdx;
- } elseif ($minJoin !== 0 && !stripos($clauseType, 'JOIN')) {
+ } elseif ($minJoin !== 0 && ! stripos($clauseType, 'JOIN')) {
// After a previous JOIN clause, a non-JOIN clause has been detected
$maxJoin = $lastIdx;
} elseif ($maxJoin < $clauseStartIdx && stripos($clauseType, 'JOIN')) {
diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php
index e1c3f83..3909c42 100644
--- a/src/Statements/AlterStatement.php
+++ b/src/Statements/AlterStatement.php
@@ -35,14 +35,14 @@ class AlterStatement extends Statement
*
* @var AlterOperation[]
*/
- public $altered = array();
+ public $altered = [];
/**
* Options of this statement.
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'ONLINE' => 1,
'OFFLINE' => 1,
'IGNORE' => 2,
@@ -55,7 +55,7 @@ class AlterStatement extends Statement
'TABLE' => 3,
'TABLESPACE' => 3,
'VIEW' => 3,
- );
+ ];
/**
* @param Parser $parser the instance that requests parsing
@@ -75,10 +75,10 @@ class AlterStatement extends Statement
$this->table = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
++$list->idx; // Skipping field.
@@ -114,7 +114,7 @@ class AlterStatement extends Statement
}
if ($state === 0) {
- $options = array();
+ $options = [];
if ($this->options->has('DATABASE')) {
$options = AlterOperation::$DB_OPTIONS;
} elseif ($this->options->has('TABLE')) {
@@ -138,7 +138,7 @@ class AlterStatement extends Statement
*/
public function build()
{
- $tmp = array();
+ $tmp = [];
foreach ($this->altered as $altered) {
$tmp[] = $altered::build($altered);
}
diff --git a/src/Statements/AnalyzeStatement.php b/src/Statements/AnalyzeStatement.php
index 0efbbde..4166bdb 100644
--- a/src/Statements/AnalyzeStatement.php
+++ b/src/Statements/AnalyzeStatement.php
@@ -26,12 +26,12 @@ class AnalyzeStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'NO_WRITE_TO_BINLOG' => 2,
'LOCAL' => 3,
- );
+ ];
/**
* Analyzed tables.
diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php
index bef39d4..0c8c314 100644
--- a/src/Statements/BackupStatement.php
+++ b/src/Statements/BackupStatement.php
@@ -22,12 +22,15 @@ class BackupStatement extends MaintenanceStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'NO_WRITE_TO_BINLOG' => 2,
'LOCAL' => 3,
- 'TO' => array(4, 'var'),
- );
+ 'TO' => [
+ 4,
+ 'var',
+ ],
+ ];
}
diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php
index dd4b134..690818c 100644
--- a/src/Statements/CheckStatement.php
+++ b/src/Statements/CheckStatement.php
@@ -22,7 +22,7 @@ class CheckStatement extends MaintenanceStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'FOR UPGRADE' => 2,
@@ -31,5 +31,5 @@ class CheckStatement extends MaintenanceStatement
'MEDIUM' => 5,
'EXTENDED' => 6,
'CHANGED' => 7,
- );
+ ];
}
diff --git a/src/Statements/ChecksumStatement.php b/src/Statements/ChecksumStatement.php
index b400e48..3ddca9a 100644
--- a/src/Statements/ChecksumStatement.php
+++ b/src/Statements/ChecksumStatement.php
@@ -22,10 +22,10 @@ class ChecksumStatement extends MaintenanceStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'QUICK' => 2,
'EXTENDED' => 3,
- );
+ ];
}
diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php
index 65cdbbb..61ffac2 100644
--- a/src/Statements/CreateStatement.php
+++ b/src/Statements/CreateStatement.php
@@ -32,16 +32,25 @@ class CreateStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
// CREATE TABLE
'TEMPORARY' => 1,
// CREATE VIEW
'OR REPLACE' => 2,
- 'ALGORITHM' => array(3, 'var='),
+ 'ALGORITHM' => [
+ 3,
+ 'var=',
+ ],
// `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE`
- 'DEFINER' => array(4, 'expr='),
- 'SQL SECURITY' => array(5, 'var'),
+ 'DEFINER' => [
+ 4,
+ 'expr=',
+ ],
+ 'SQL SECURITY' => [
+ 5,
+ 'var',
+ ],
'DATABASE' => 6,
'EVENT' => 6,
@@ -60,62 +69,158 @@ class CreateStatement extends Statement
// CREATE TABLE
'IF NOT EXISTS' => 7,
- );
+ ];
/**
* All database options.
*
* @var array
*/
- public static $DB_OPTIONS = array(
- 'CHARACTER SET' => array(1, 'var='),
- 'CHARSET' => array(1, 'var='),
- 'DEFAULT CHARACTER SET' => array(1, 'var='),
- 'DEFAULT CHARSET' => array(1, 'var='),
- 'DEFAULT COLLATE' => array(2, 'var='),
- 'COLLATE' => array(2, 'var='),
- );
+ public static $DB_OPTIONS = [
+ 'CHARACTER SET' => [
+ 1,
+ 'var=',
+ ],
+ 'CHARSET' => [
+ 1,
+ 'var=',
+ ],
+ 'DEFAULT CHARACTER SET' => [
+ 1,
+ 'var=',
+ ],
+ 'DEFAULT CHARSET' => [
+ 1,
+ 'var=',
+ ],
+ 'DEFAULT COLLATE' => [
+ 2,
+ 'var=',
+ ],
+ 'COLLATE' => [
+ 2,
+ 'var=',
+ ],
+ ];
/**
* All table options.
*
* @var array
*/
- public static $TABLE_OPTIONS = array(
- 'ENGINE' => array(1, 'var='),
- 'AUTO_INCREMENT' => array(2, 'var='),
- 'AVG_ROW_LENGTH' => array(3, 'var'),
- 'CHARACTER SET' => array(4, 'var='),
- 'CHARSET' => array(4, 'var='),
- 'DEFAULT CHARACTER SET' => array(4, 'var='),
- 'DEFAULT CHARSET' => array(4, 'var='),
- 'CHECKSUM' => array(5, 'var'),
- 'DEFAULT COLLATE' => array(6, 'var='),
- 'COLLATE' => array(6, 'var='),
- 'COMMENT' => array(7, 'var='),
- 'CONNECTION' => array(8, 'var'),
- 'DATA DIRECTORY' => array(9, 'var'),
- 'DELAY_KEY_WRITE' => array(10, 'var'),
- 'INDEX DIRECTORY' => array(11, 'var'),
- 'INSERT_METHOD' => array(12, 'var'),
- 'KEY_BLOCK_SIZE' => array(13, 'var'),
- 'MAX_ROWS' => array(14, 'var'),
- 'MIN_ROWS' => array(15, 'var'),
- 'PACK_KEYS' => array(16, 'var'),
- 'PASSWORD' => array(17, 'var'),
- 'ROW_FORMAT' => array(18, 'var'),
- 'TABLESPACE' => array(19, 'var'),
- 'STORAGE' => array(20, 'var'),
- 'UNION' => array(21, 'var'),
- );
+ public static $TABLE_OPTIONS = [
+ 'ENGINE' => [
+ 1,
+ 'var=',
+ ],
+ 'AUTO_INCREMENT' => [
+ 2,
+ 'var=',
+ ],
+ 'AVG_ROW_LENGTH' => [
+ 3,
+ 'var',
+ ],
+ 'CHARACTER SET' => [
+ 4,
+ 'var=',
+ ],
+ 'CHARSET' => [
+ 4,
+ 'var=',
+ ],
+ 'DEFAULT CHARACTER SET' => [
+ 4,
+ 'var=',
+ ],
+ 'DEFAULT CHARSET' => [
+ 4,
+ 'var=',
+ ],
+ 'CHECKSUM' => [
+ 5,
+ 'var',
+ ],
+ 'DEFAULT COLLATE' => [
+ 6,
+ 'var=',
+ ],
+ 'COLLATE' => [
+ 6,
+ 'var=',
+ ],
+ 'COMMENT' => [
+ 7,
+ 'var=',
+ ],
+ 'CONNECTION' => [
+ 8,
+ 'var',
+ ],
+ 'DATA DIRECTORY' => [
+ 9,
+ 'var',
+ ],
+ 'DELAY_KEY_WRITE' => [
+ 10,
+ 'var',
+ ],
+ 'INDEX DIRECTORY' => [
+ 11,
+ 'var',
+ ],
+ 'INSERT_METHOD' => [
+ 12,
+ 'var',
+ ],
+ 'KEY_BLOCK_SIZE' => [
+ 13,
+ 'var',
+ ],
+ 'MAX_ROWS' => [
+ 14,
+ 'var',
+ ],
+ 'MIN_ROWS' => [
+ 15,
+ 'var',
+ ],
+ 'PACK_KEYS' => [
+ 16,
+ 'var',
+ ],
+ 'PASSWORD' => [
+ 17,
+ 'var',
+ ],
+ 'ROW_FORMAT' => [
+ 18,
+ 'var',
+ ],
+ 'TABLESPACE' => [
+ 19,
+ 'var',
+ ],
+ 'STORAGE' => [
+ 20,
+ 'var',
+ ],
+ 'UNION' => [
+ 21,
+ 'var',
+ ],
+ ];
/**
* All function options.
*
* @var array
*/
- public static $FUNC_OPTIONS = array(
- 'COMMENT' => array(1, 'var='),
+ public static $FUNC_OPTIONS = [
+ 'COMMENT' => [
+ 1,
+ 'var=',
+ ],
'LANGUAGE SQL' => 2,
'DETERMINISTIC' => 3,
'NOT DETERMINISTIC' => 3,
@@ -123,21 +228,24 @@ class CreateStatement extends Statement
'NO SQL' => 4,
'READS SQL DATA' => 4,
'MODIFIES SQL DATA' => 4,
- 'SQL SECURITY DEFINER' => array(5, 'var'),
- );
+ 'SQL SECURITY DEFINER' => [
+ 5,
+ 'var',
+ ],
+ ];
/**
* All trigger options.
*
* @var array
*/
- public static $TRIGGER_OPTIONS = array(
+ public static $TRIGGER_OPTIONS = [
'BEFORE' => 1,
'AFTER' => 1,
'INSERT' => 2,
'UPDATE' => 2,
'DELETE' => 2,
- );
+ ];
/**
* The name of the entity that is created.
@@ -259,7 +367,7 @@ class CreateStatement extends Statement
*
* @var Token[]|string
*/
- public $body = array();
+ public $body = [];
/**
* @return string
@@ -267,7 +375,7 @@ class CreateStatement extends Statement
public function build()
{
$fields = '';
- if (!empty($this->fields)) {
+ if (! empty($this->fields)) {
if (is_array($this->fields)) {
$fields = CreateDefinition::build($this->fields) . ' ';
} elseif ($this->fields instanceof ArrayObj) {
@@ -280,12 +388,12 @@ class CreateStatement extends Statement
. Expression::build($this->name) . ' '
. OptionsArray::build($this->entityOptions);
} elseif ($this->options->has('TABLE')) {
- if (!is_null($this->select)) {
+ if (! is_null($this->select)) {
return 'CREATE '
. OptionsArray::build($this->options) . ' '
. Expression::build($this->name) . ' '
. $this->select->build();
- } elseif (!is_null($this->like)) {
+ } elseif (! is_null($this->like)) {
return 'CREATE '
. OptionsArray::build($this->options) . ' '
. Expression::build($this->name) . ' LIKE '
@@ -293,19 +401,19 @@ class CreateStatement extends Statement
} else {
$partition = '';
- if (!empty($this->partitionBy)) {
+ if (! empty($this->partitionBy)) {
$partition .= "\nPARTITION BY " . $this->partitionBy;
}
- if (!empty($this->partitionsNum)) {
+ if (! empty($this->partitionsNum)) {
$partition .= "\nPARTITIONS " . $this->partitionsNum;
}
- if (!empty($this->subpartitionBy)) {
+ if (! empty($this->subpartitionBy)) {
$partition .= "\nSUBPARTITION BY " . $this->subpartitionBy;
}
- if (!empty($this->subpartitionsNum)) {
+ if (! empty($this->subpartitionsNum)) {
$partition .= "\nSUBPARTITIONS " . $this->subpartitionsNum;
}
- if (!empty($this->partitions)) {
+ if (! empty($this->partitions)) {
$partition .= "\n" . PartitionDefinition::build($this->partitions);
}
@@ -366,13 +474,13 @@ class CreateStatement extends Statement
$this->name = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
- if (!isset($this->name) || ($this->name === '')) {
+ if (! isset($this->name) || ($this->name === '')) {
$parser->error(
'The name of the entity was expected.',
$list->tokens[$list->idx]
@@ -416,10 +524,10 @@ class CreateStatement extends Statement
$this->like = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
// The 'LIKE' keyword was found, but no table_name was found next to it
if (is_null($this->like)) {
@@ -496,7 +604,7 @@ class CreateStatement extends Statement
$token = $list->getNextOfType(Token::TYPE_NUMBER);
--$list->idx; // `getNextOfType` also advances one position.
$this->subpartitionsNum = $token->value;
- } elseif (!empty($field)) {
+ } elseif (! empty($field)) {
/*
* Handling the content of `PARTITION BY` and `SUBPARTITION BY`.
*/
@@ -525,13 +633,13 @@ class CreateStatement extends Statement
$field = null;
}
} elseif (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
- if (!empty($this->partitionBy)) {
+ if (! empty($this->partitionBy)) {
$this->partitions = ArrayObj::parse(
$parser,
$list,
- array(
+ [
'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition',
- )
+ ]
);
}
break;
@@ -606,10 +714,10 @@ class CreateStatement extends Statement
$this->table = Expression::parse(
$parser,
$list,
- array(
+ [
'parseField' => 'table',
'breakOnAlias' => true,
- )
+ ]
);
++$list->idx;
diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php
index 7ff0025..879fe2e 100644
--- a/src/Statements/DeleteStatement.php
+++ b/src/Statements/DeleteStatement.php
@@ -54,11 +54,11 @@ class DeleteStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'LOW_PRIORITY' => 1,
'QUICK' => 2,
'IGNORE' => 3,
- );
+ ];
/**
* The clauses of this statement, in order.
@@ -67,17 +67,41 @@ class DeleteStatement extends Statement
*
* @var array
*/
- public static $CLAUSES = array(
- 'DELETE' => array('DELETE', 2),
+ public static $CLAUSES = [
+ 'DELETE' => [
+ 'DELETE',
+ 2,
+ ],
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
- 'FROM' => array('FROM', 3),
- 'PARTITION' => array('PARTITION', 3),
- 'USING' => array('USING', 3),
- 'WHERE' => array('WHERE', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
- );
+ '_OPTIONS' => [
+ '_OPTIONS',
+ 1,
+ ],
+ 'FROM' => [
+ 'FROM',
+ 3,
+ ],
+ 'PARTITION' => [
+ 'PARTITION',
+ 3,
+ ],
+ 'USING' => [
+ 'USING',
+ 3,
+ ],
+ 'WHERE' => [
+ 'WHERE',
+ 3,
+ ],
+ 'ORDER BY' => [
+ 'ORDER BY',
+ 3,
+ ],
+ 'LIMIT' => [
+ 'LIMIT',
+ 3,
+ ],
+ ];
/**
* Table(s) used as sources for this statement.
@@ -142,25 +166,25 @@ class DeleteStatement extends Statement
{
$ret = 'DELETE ' . OptionsArray::build($this->options);
- if (!is_null($this->columns) && count($this->columns) > 0) {
+ if (! is_null($this->columns) && count($this->columns) > 0) {
$ret .= ' ' . ExpressionArray::build($this->columns);
}
- if (!is_null($this->from) && count($this->from) > 0) {
+ if (! is_null($this->from) && count($this->from) > 0) {
$ret .= ' FROM ' . ExpressionArray::build($this->from);
}
- if (!is_null($this->join) && count($this->join) > 0) {
+ if (! is_null($this->join) && count($this->join) > 0) {
$ret .= ' ' . JoinKeyword::build($this->join);
}
- if (!is_null($this->using) && count($this->using) > 0) {
+ if (! is_null($this->using) && count($this->using) > 0) {
$ret .= ' USING ' . ExpressionArray::build($this->using);
}
- if (!is_null($this->where) && count($this->where) > 0) {
+ if (! is_null($this->where) && count($this->where) > 0) {
$ret .= ' WHERE ' . Condition::build($this->where);
}
- if (!is_null($this->order) && count($this->order) > 0) {
+ if (! is_null($this->order) && count($this->order) > 0) {
$ret .= ' ORDER BY ' . ExpressionArray::build($this->order);
}
- if (!is_null($this->limit) && strlen($this->limit) > 0) {
+ if (! is_null($this->limit) && strlen($this->limit) > 0) {
$ret .= ' LIMIT ' . Limit::build($this->limit);
}
@@ -257,34 +281,33 @@ class DeleteStatement extends Statement
$this->join = JoinKeyword::parse($parser, $list);
// remain in state = 2
- }
- else {
- switch($token->keyword) {
+ } else {
+ switch ($token->keyword) {
case 'USING':
++$list->idx; // Skip 'USING'
$this->using = ExpressionArray::parse($parser, $list);
$state = 3;
$multiTable = true;
- break;
+ break;
case 'WHERE':
++$list->idx; // Skip 'WHERE'
$this->where = Condition::parse($parser, $list);
$state = 4;
- break;
+ break;
case 'ORDER BY':
++$list->idx; // Skip 'ORDER BY'
$this->order = OrderKeyword::parse($parser, $list);
$state = 5;
- break;
+ break;
case 'LIMIT':
++$list->idx; // Skip 'LIMIT'
$this->limit = Limit::parse($parser, $list);
$state = 6;
- break;
+ break;
default:
$parser->error('Unexpected keyword.', $token);
- break 2;
+ break 2;
}
}
}
@@ -314,20 +337,20 @@ class DeleteStatement extends Statement
}
if ($token->type === Token::TYPE_KEYWORD) {
- switch($token->keyword) {
+ switch ($token->keyword) {
case 'ORDER BY':
++$list->idx; // Skip 'ORDER BY'
$this->order = OrderKeyword::parse($parser, $list);
$state = 5;
- break;
+ break;
case 'LIMIT':
++$list->idx; // Skip 'LIMIT'
$this->limit = Limit::parse($parser, $list);
$state = 6;
- break;
+ break;
default:
$parser->error('Unexpected keyword.', $token);
- break 2;
+ break 2;
}
}
} elseif ($state === 5) {
diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php
index 1572a55..1ec1c72 100644
--- a/src/Statements/DropStatement.php
+++ b/src/Statements/DropStatement.php
@@ -23,7 +23,7 @@ class DropStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'DATABASE' => 1,
'EVENT' => 1,
'FUNCTION' => 1,
@@ -39,7 +39,7 @@ class DropStatement extends Statement
'TEMPORARY' => 2,
'IF EXISTS' => 3,
- );
+ ];
/**
* The clauses of this statement, in order.
@@ -48,14 +48,26 @@ class DropStatement extends Statement
*
* @var array
*/
- public static $CLAUSES = array(
- 'DROP' => array('DROP', 2),
+ public static $CLAUSES = [
+ 'DROP' => [
+ 'DROP',
+ 2,
+ ],
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => [
+ '_OPTIONS',
+ 1,
+ ],
// Used for select expressions.
- 'DROP_' => array('DROP', 1),
- 'ON' => array('ON', 3),
- );
+ 'DROP_' => [
+ 'DROP',
+ 1,
+ ],
+ 'ON' => [
+ 'ON',
+ 3,
+ ],
+ ];
/**
* Dropped elements.
diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php
index 312b4e0..f2b6348 100644
--- a/src/Statements/InsertStatement.php
+++ b/src/Statements/InsertStatement.php
@@ -60,12 +60,12 @@ class InsertStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'LOW_PRIORITY' => 1,
'DELAYED' => 2,
'HIGH_PRIORITY' => 3,
'IGNORE' => 4,
- );
+ ];
/**
* Tables used as target for this statement.
@@ -113,15 +113,15 @@ class InsertStatement extends Statement
$ret = 'INSERT ' . $this->options
. ' INTO ' . $this->into;
- if (!is_null($this->values) && count($this->values) > 0) {
+ if (! is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif (!is_null($this->set) && count($this->set) > 0) {
+ } elseif (! is_null($this->set) && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif (!is_null($this->select) && strlen($this->select) > 0) {
+ } elseif (! is_null($this->select) && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
- if (!is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) {
+ if (! is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) {
$ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet);
}
@@ -195,7 +195,7 @@ class InsertStatement extends Statement
$this->into = IntoKeyword::parse(
$parser,
$list,
- array('fromInsert' => true)
+ ['fromInsert' => true]
);
$state = 1;
diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php
index 45ad05f..c9179aa 100644
--- a/src/Statements/LoadStatement.php
+++ b/src/Statements/LoadStatement.php
@@ -49,33 +49,48 @@ class LoadStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'LOW_PRIORITY' => 1,
'CONCURRENT' => 1,
'LOCAL' => 2,
- );
+ ];
/**
* FIELDS/COLUMNS Options for `LOAD DATA...INFILE` statements.
*
* @var array
*/
- public static $FIELDS_OPTIONS = array(
- 'TERMINATED BY' => array(1, 'expr'),
+ public static $FIELDS_OPTIONS = [
+ 'TERMINATED BY' => [
+ 1,
+ 'expr',
+ ],
'OPTIONALLY' => 2,
- 'ENCLOSED BY' => array(3, 'expr'),
- 'ESCAPED BY' => array(4, 'expr'),
- );
+ 'ENCLOSED BY' => [
+ 3,
+ 'expr',
+ ],
+ 'ESCAPED BY' => [
+ 4,
+ 'expr',
+ ],
+ ];
/**
* LINES Options for `LOAD DATA...INFILE` statements.
*
* @var array
*/
- public static $LINES_OPTIONS = array(
- 'STARTING BY' => array(1, 'expr'),
- 'TERMINATED BY' => array(2, 'expr'),
- );
+ public static $LINES_OPTIONS = [
+ 'STARTING BY' => [
+ 1,
+ 'expr',
+ ],
+ 'TERMINATED BY' => [
+ 2,
+ 'expr',
+ ],
+ ];
/**
* File name being used to load data.
@@ -266,7 +281,7 @@ class LoadStatement extends Statement
$this->file_name = Expression::parse(
$parser,
$list,
- array('parseField' => 'file')
+ ['parseField' => 'file']
);
$state = 1;
} elseif ($state === 1) {
@@ -283,7 +298,7 @@ class LoadStatement extends Statement
&& $token->keyword === 'TABLE'
) {
++$list->idx;
- $this->table = Expression::parse($parser, $list, array('parseField' => 'table'));
+ $this->table = Expression::parse($parser, $list, ['parseField' => 'table']);
$state = 3;
} else {
$parser->error('Unexpected token.', $token);
@@ -292,7 +307,9 @@ class LoadStatement extends Statement
} elseif ($state >= 3 && $state <= 7) {
if ($token->type === Token::TYPE_KEYWORD) {
$newState = $this->parseKeywordsAccordingToState(
- $parser, $list, $state
+ $parser,
+ $list,
+ $state
);
if ($newState === $state) {
// Avoid infinite loop
diff --git a/src/Statements/LockStatement.php b/src/Statements/LockStatement.php
index 2ba70c4..354d446 100644
--- a/src/Statements/LockStatement.php
+++ b/src/Statements/LockStatement.php
@@ -26,7 +26,7 @@ class LockStatement extends Statement
*
* @var LockExpression[]
*/
- public $locked = array();
+ public $locked = [];
/**
* Whether it's a LOCK statement
@@ -95,7 +95,7 @@ class LockStatement extends Statement
break;
}
} elseif ($state === 1) {
- if (!$this->isLock) {
+ if (! $this->isLock) {
// UNLOCK statement should not have any more tokens
$parser->error('Unexpected token.', $token);
break;
diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php
index e534cdf..f5da4a1 100644
--- a/src/Statements/NotImplementedStatement.php
+++ b/src/Statements/NotImplementedStatement.php
@@ -27,7 +27,7 @@ class NotImplementedStatement extends Statement
*
* @var Token[]
*/
- public $unknown = array();
+ public $unknown = [];
/**
* @return string
diff --git a/src/Statements/OptimizeStatement.php b/src/Statements/OptimizeStatement.php
index 0d88e76..19c95e5 100644
--- a/src/Statements/OptimizeStatement.php
+++ b/src/Statements/OptimizeStatement.php
@@ -26,12 +26,12 @@ class OptimizeStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'NO_WRITE_TO_BINLOG' => 2,
'LOCAL' => 3,
- );
+ ];
/**
* Optimized tables.
diff --git a/src/Statements/PurgeStatement.php b/src/Statements/PurgeStatement.php
index 0374813..79a684f 100644
--- a/src/Statements/PurgeStatement.php
+++ b/src/Statements/PurgeStatement.php
@@ -92,19 +92,19 @@ class PurgeStatement extends Statement
switch ($state) {
case 0:
// parse `{ BINARY | MASTER }`
- $this->log_type = self::parseExpectedKeyword($parser, $token, array('BINARY', 'MASTER'));
+ $this->log_type = self::parseExpectedKeyword($parser, $token, ['BINARY', 'MASTER']);
break;
case 1:
// parse `LOGS`
- self::parseExpectedKeyword($parser, $token, array('LOGS'));
+ self::parseExpectedKeyword($parser, $token, ['LOGS']);
break;
case 2:
// parse `{ TO | BEFORE }`
- $this->end_option = self::parseExpectedKeyword($parser, $token, array('TO', 'BEFORE'));
+ $this->end_option = self::parseExpectedKeyword($parser, $token, ['TO', 'BEFORE']);
break;
case 3:
// parse `expr`
- $this->end_expr = Expression::parse($parser, $list, array());
+ $this->end_expr = Expression::parse($parser, $list, []);
break;
default:
$parser->error('Unexpected token.', $token);
diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php
index c16d603..a9e058a 100644
--- a/src/Statements/RepairStatement.php
+++ b/src/Statements/RepairStatement.php
@@ -24,7 +24,7 @@ class RepairStatement extends MaintenanceStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
'NO_WRITE_TO_BINLOG' => 2,
@@ -33,5 +33,5 @@ class RepairStatement extends MaintenanceStatement
'QUICK' => 4,
'EXTENDED' => 5,
'USE_FRM' => 6,
- );
+ ];
}
diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php
index 40b1194..72e6841 100644
--- a/src/Statements/ReplaceStatement.php
+++ b/src/Statements/ReplaceStatement.php
@@ -47,10 +47,10 @@ class ReplaceStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'LOW_PRIORITY' => 1,
'DELAYED' => 1,
- );
+ ];
/**
* Tables used as target for this statement.
@@ -89,11 +89,11 @@ class ReplaceStatement extends Statement
{
$ret = 'REPLACE ' . $this->options . ' INTO ' . $this->into;
- if (!is_null($this->values) && count($this->values) > 0) {
+ if (! is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif (!is_null($this->set) && count($this->set) > 0) {
+ } elseif (! is_null($this->set) && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif (!is_null($this->select) && strlen($this->select) > 0) {
+ } elseif (! is_null($this->select) && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
@@ -159,7 +159,7 @@ class ReplaceStatement extends Statement
$this->into = IntoKeyword::parse(
$parser,
$list,
- array('fromReplace' => true)
+ ['fromReplace' => true]
);
$state = 1;
diff --git a/src/Statements/RestoreStatement.php b/src/Statements/RestoreStatement.php
index db07ac4..6a2b44f 100644
--- a/src/Statements/RestoreStatement.php
+++ b/src/Statements/RestoreStatement.php
@@ -22,9 +22,12 @@ class RestoreStatement extends MaintenanceStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
- 'FROM' => array(2, 'var'),
- );
+ 'FROM' => [
+ 2,
+ 'var',
+ ],
+ ];
}
diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php
index fbcae48..1bff148 100644
--- a/src/Statements/SelectStatement.php
+++ b/src/Statements/SelectStatement.php
@@ -56,12 +56,15 @@ class SelectStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'ALL' => 1,
'DISTINCT' => 1,
'DISTINCTROW' => 1,
'HIGH_PRIORITY' => 2,
- 'MAX_STATEMENT_TIME' => array(3, 'var='),
+ 'MAX_STATEMENT_TIME' => [
+ 3,
+ 'var=',
+ ],
'STRAIGHT_JOIN' => 4,
'SQL_SMALL_RESULT' => 5,
'SQL_BIG_RESULT' => 6,
@@ -69,12 +72,12 @@ class SelectStatement extends Statement
'SQL_CACHE' => 8,
'SQL_NO_CACHE' => 8,
'SQL_CALC_FOUND_ROWS' => 9,
- );
+ ];
- public static $END_OPTIONS = array(
+ public static $END_OPTIONS = [
'FOR UPDATE' => 1,
'LOCK IN SHARE MODE' => 1,
- );
+ ];
/**
* The clauses of this statement, in order.
@@ -83,60 +86,153 @@ class SelectStatement extends Statement
*
* @var array
*/
- public static $CLAUSES = array(
- 'SELECT' => array('SELECT', 2),
+ public static $CLAUSES = [
+ 'SELECT' => [
+ 'SELECT',
+ 2,
+ ],
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => [
+ '_OPTIONS',
+ 1,
+ ],
// Used for selected expressions.
- '_SELECT' => array('SELECT', 1),
- 'INTO' => array('INTO', 3),
- 'FROM' => array('FROM', 3),
- 'FORCE' => array('FORCE', 1),
- 'USE' => array('USE', 1),
- 'IGNORE' => array('IGNORE', 3),
- 'PARTITION' => array('PARTITION', 3),
-
- 'JOIN' => array('JOIN', 1),
- 'FULL JOIN' => array('FULL JOIN', 1),
- 'INNER JOIN' => array('INNER JOIN', 1),
- 'LEFT JOIN' => array('LEFT JOIN', 1),
- 'LEFT OUTER JOIN' => array('LEFT OUTER JOIN', 1),
- 'RIGHT JOIN' => array('RIGHT JOIN', 1),
- 'RIGHT OUTER JOIN' => array('RIGHT OUTER JOIN', 1),
- 'NATURAL JOIN' => array('NATURAL JOIN', 1),
- 'NATURAL LEFT JOIN' => array('NATURAL LEFT JOIN', 1),
- 'NATURAL RIGHT JOIN' => array('NATURAL RIGHT JOIN', 1),
- 'NATURAL LEFT OUTER JOIN' => array('NATURAL LEFT OUTER JOIN', 1),
- 'NATURAL RIGHT OUTER JOIN' => array('NATURAL RIGHT JOIN', 1),
-
- 'WHERE' => array('WHERE', 3),
- 'GROUP BY' => array('GROUP BY', 3),
- 'HAVING' => array('HAVING', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
- 'PROCEDURE' => array('PROCEDURE', 3),
- 'UNION' => array('UNION', 1),
- 'EXCEPT' => array('EXCEPT', 1),
- 'INTERSECT' => array('INTERSECT', 1),
- '_END_OPTIONS' => array('_END_OPTIONS', 1),
+ '_SELECT' => [
+ 'SELECT',
+ 1,
+ ],
+ 'INTO' => [
+ 'INTO',
+ 3,
+ ],
+ 'FROM' => [
+ 'FROM',
+ 3,
+ ],
+ 'FORCE' => [
+ 'FORCE',
+ 1,
+ ],
+ 'USE' => [
+ 'USE',
+ 1,
+ ],
+ 'IGNORE' => [
+ 'IGNORE',
+ 3,
+ ],
+ 'PARTITION' => [
+ 'PARTITION',
+ 3,
+ ],
+
+ 'JOIN' => [
+ 'JOIN',
+ 1,
+ ],
+ 'FULL JOIN' => [
+ 'FULL JOIN',
+ 1,
+ ],
+ 'INNER JOIN' => [
+ 'INNER JOIN',
+ 1,
+ ],
+ 'LEFT JOIN' => [
+ 'LEFT JOIN',
+ 1,
+ ],
+ 'LEFT OUTER JOIN' => [
+ 'LEFT OUTER JOIN',
+ 1,
+ ],
+ 'RIGHT JOIN' => [
+ 'RIGHT JOIN',
+ 1,
+ ],
+ 'RIGHT OUTER JOIN' => [
+ 'RIGHT OUTER JOIN',
+ 1,
+ ],
+ 'NATURAL JOIN' => [
+ 'NATURAL JOIN',
+ 1,
+ ],
+ 'NATURAL LEFT JOIN' => [
+ 'NATURAL LEFT JOIN',
+ 1,
+ ],
+ 'NATURAL RIGHT JOIN' => [
+ 'NATURAL RIGHT JOIN',
+ 1,
+ ],
+ 'NATURAL LEFT OUTER JOIN' => [
+ 'NATURAL LEFT OUTER JOIN',
+ 1,
+ ],
+ 'NATURAL RIGHT OUTER JOIN' => [
+ 'NATURAL RIGHT JOIN',
+ 1,
+ ],
+
+ 'WHERE' => [
+ 'WHERE',
+ 3,
+ ],
+ 'GROUP BY' => [
+ 'GROUP BY',
+ 3,
+ ],
+ 'HAVING' => [
+ 'HAVING',
+ 3,
+ ],
+ 'ORDER BY' => [
+ 'ORDER BY',
+ 3,
+ ],
+ 'LIMIT' => [
+ 'LIMIT',
+ 3,
+ ],
+ 'PROCEDURE' => [
+ 'PROCEDURE',
+ 3,
+ ],
+ 'UNION' => [
+ 'UNION',
+ 1,
+ ],
+ 'EXCEPT' => [
+ 'EXCEPT',
+ 1,
+ ],
+ 'INTERSECT' => [
+ 'INTERSECT',
+ 1,
+ ],
+ '_END_OPTIONS' => [
+ '_END_OPTIONS',
+ 1,
+ ],
// These are available only when `UNION` is present.
// 'ORDER BY' => array('ORDER BY', 3),
// 'LIMIT' => array('LIMIT', 3),
- );
+ ];
/**
* Expressions that are being selected by this statement.
*
* @var Expression[]
*/
- public $expr = array();
+ public $expr = [];
/**
* Tables used as sources for this statement.
*
* @var Expression[]
*/
- public $from = array();
+ public $from = [];
/**
* Index hints
@@ -213,7 +309,7 @@ class SelectStatement extends Statement
*
* @var SelectStatement[]
*/
- public $union = array();
+ public $union = [];
/**
* The end options of this query.
@@ -234,11 +330,17 @@ class SelectStatement extends Statement
// This is a cheap fix for `SELECT` statements that contain `UNION`.
// The `ORDER BY` and `LIMIT` clauses should be at the end of the
// statement.
- if (!empty($this->union)) {
+ if (! empty($this->union)) {
$clauses = static::$CLAUSES;
unset($clauses['ORDER BY'], $clauses['LIMIT']);
- $clauses['ORDER BY'] = array('ORDER BY', 3);
- $clauses['LIMIT'] = array('LIMIT', 3);
+ $clauses['ORDER BY'] = [
+ 'ORDER BY',
+ 3,
+ ];
+ $clauses['LIMIT'] = [
+ 'LIMIT',
+ 3,
+ ];
return $clauses;
}
diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php
index ef3a0c1..129cc14 100644
--- a/src/Statements/SetStatement.php
+++ b/src/Statements/SetStatement.php
@@ -26,27 +26,48 @@ class SetStatement extends Statement
*
* @var array
*/
- public static $CLAUSES = array(
- 'SET' => array('SET', 3),
- '_END_OPTIONS' => array('_END_OPTIONS', 1),
- );
+ public static $CLAUSES = [
+ 'SET' => [
+ 'SET',
+ 3,
+ ],
+ '_END_OPTIONS' => [
+ '_END_OPTIONS',
+ 1,
+ ],
+ ];
/**
* Possible exceptions in SET statment.
*
* @var array
*/
- public static $OPTIONS = array(
- 'CHARSET' => array(3, 'var'),
- 'CHARACTER SET' => array(3, 'var'),
- 'NAMES' => array(3, 'var'),
- 'PASSWORD' => array(3, 'expr'),
- );
+ public static $OPTIONS = [
+ 'CHARSET' => [
+ 3,
+ 'var',
+ ],
+ 'CHARACTER SET' => [
+ 3,
+ 'var',
+ ],
+ 'NAMES' => [
+ 3,
+ 'var',
+ ],
+ 'PASSWORD' => [
+ 3,
+ 'expr',
+ ],
+ ];
- public static $END_OPTIONS = array(
- 'COLLATE' => array(1, 'var'),
- 'DEFAULT' => 1
- );
+ public static $END_OPTIONS = [
+ 'COLLATE' => [
+ 1,
+ 'var',
+ ],
+ 'DEFAULT' => 1,
+ ];
/**
* Options used in current statement.
diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php
index 1568177..4205310 100644
--- a/src/Statements/ShowStatement.php
+++ b/src/Statements/ShowStatement.php
@@ -20,7 +20,7 @@ class ShowStatement extends NotImplementedStatement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'CREATE' => 1,
'AUTHORS' => 2,
'BINARY' => 2,
@@ -62,5 +62,5 @@ class ShowStatement extends NotImplementedStatement
'VARIABLES' => 2,
'VIEW' => 2,
'WARNINGS' => 2,
- );
+ ];
}
diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php
index cfdc25c..fae935a 100644
--- a/src/Statements/TransactionStatement.php
+++ b/src/Statements/TransactionStatement.php
@@ -60,7 +60,7 @@ class TransactionStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'START TRANSACTION' => 1,
'BEGIN' => 1,
'COMMIT' => 1,
@@ -71,7 +71,7 @@ class TransactionStatement extends Statement
'AND CHAIN' => 3,
'RELEASE' => 4,
'NO RELEASE' => 4,
- );
+ ];
/**
* @param Parser $parser the instance that requests parsing
diff --git a/src/Statements/TruncateStatement.php b/src/Statements/TruncateStatement.php
index b625bc6..c95dfd0 100644
--- a/src/Statements/TruncateStatement.php
+++ b/src/Statements/TruncateStatement.php
@@ -23,9 +23,9 @@ class TruncateStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'TABLE' => 1,
- );
+ ];
/**
* The name of the truncated table.
diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php
index b0aba01..2dee189 100644
--- a/src/Statements/UpdateStatement.php
+++ b/src/Statements/UpdateStatement.php
@@ -39,10 +39,10 @@ class UpdateStatement extends Statement
*
* @var array
*/
- public static $OPTIONS = array(
+ public static $OPTIONS = [
'LOW_PRIORITY' => 1,
'IGNORE' => 2,
- );
+ ];
/**
* The clauses of this statement, in order.
@@ -51,17 +51,38 @@ class UpdateStatement extends Statement
*
* @var array
*/
- public static $CLAUSES = array(
- 'UPDATE' => array('UPDATE', 2),
+ public static $CLAUSES = [
+ 'UPDATE' => [
+ 'UPDATE',
+ 2,
+ ],
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => [
+ '_OPTIONS',
+ 1,
+ ],
// Used for updated tables.
- '_UPDATE' => array('UPDATE', 1),
- 'SET' => array('SET', 3),
- 'WHERE' => array('WHERE', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
- );
+ '_UPDATE' => [
+ 'UPDATE',
+ 1,
+ ],
+ 'SET' => [
+ 'SET',
+ 3,
+ ],
+ 'WHERE' => [
+ 'WHERE',
+ 3,
+ ],
+ 'ORDER BY' => [
+ 'ORDER BY',
+ 3,
+ ],
+ 'LIMIT' => [
+ 'LIMIT',
+ 3,
+ ],
+ ];
/**
* Tables used as sources for this statement.
diff --git a/src/Token.php b/src/Token.php
index 077c2c2..1965f8b 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -242,7 +242,7 @@ class Token
switch ($this->type) {
case self::TYPE_KEYWORD:
$this->keyword = strtoupper($this->token);
- if (!($this->flags & self::FLAG_KEYWORD_RESERVED)) {
+ if (! ($this->flags & self::FLAG_KEYWORD_RESERVED)) {
// Unreserved keywords should stay the way they are because they
// might represent field names.
return $this->token;
@@ -300,7 +300,7 @@ class Token
// in PHP 5.3- the `null` parameter isn't handled correctly.
$str = mb_substr(
$str,
- (!empty($str[1]) && ($str[1] === '@')) ? 2 : 1,
+ (! empty($str[1]) && ($str[1] === '@')) ? 2 : 1,
mb_strlen($str),
'UTF-8'
);
@@ -330,8 +330,16 @@ class Token
public function getInlineToken()
{
return str_replace(
- array("\r", "\n", "\t"),
- array('\r', '\n', '\t'),
+ [
+ "\r",
+ "\n",
+ "\t",
+ ],
+ [
+ '\r',
+ '\n',
+ '\t',
+ ],
$this->token
);
}
diff --git a/src/TokensList.php b/src/TokensList.php
index 6ddce49..8d711f8 100644
--- a/src/TokensList.php
+++ b/src/TokensList.php
@@ -20,7 +20,7 @@ class TokensList implements \ArrayAccess
*
* @var array
*/
- public $tokens = array();
+ public $tokens = [];
/**
* The count of tokens.
@@ -42,9 +42,9 @@ class TokensList implements \ArrayAccess
* @param array $tokens the initial array of tokens
* @param int $count the count of tokens in the initial array
*/
- public function __construct(array $tokens = array(), $count = -1)
+ public function __construct(array $tokens = [], $count = -1)
{
- if (!empty($tokens)) {
+ if (! empty($tokens)) {
$this->tokens = $tokens;
if ($count === -1) {
$this->count = count($tokens);
diff --git a/src/Translator.php b/src/Translator.php
index bb5df34..622bec9 100644
--- a/src/Translator.php
+++ b/src/Translator.php
@@ -58,7 +58,7 @@ class Translator
*/
public static function gettext($msgid)
{
- if (!class_exists('\PhpMyAdmin\MoTranslator\Loader', true)) {
+ if (! class_exists('\PhpMyAdmin\MoTranslator\Loader', true)) {
return $msgid;
}
diff --git a/src/UtfString.php b/src/UtfString.php
index 9ae70f6..58905f3 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -75,7 +75,7 @@ class UtfString implements \ArrayAccess
$this->byteIdx = 0;
$this->charIdx = 0;
$this->byteLen = mb_strlen($str, '8bit');
- if (!mb_check_encoding($str, 'UTF-8')) {
+ if (! mb_check_encoding($str, 'UTF-8')) {
$this->charLen = 0;
} else {
$this->charLen = mb_strlen($str, 'UTF-8');
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php
index ee0dca4..5edf903 100644
--- a/src/Utils/BufferedQuery.php
+++ b/src/Utils/BufferedQuery.php
@@ -49,7 +49,7 @@ class BufferedQuery
*
* @var array
*/
- public $options = array();
+ public $options = [];
/**
* The last delimiter used.
@@ -85,11 +85,11 @@ class BufferedQuery
* @param string $query the query to be parsed
* @param array $options the options of this parser
*/
- public function __construct($query = '', array $options = array())
+ public function __construct($query = '', array $options = [])
{
// Merges specified options with defaults.
$this->options = array_merge(
- array(
+ [
/*
* The starting delimiter.
*
@@ -111,7 +111,7 @@ class BufferedQuery
* @var bool
*/
'add_delimiter' => false,
- ),
+ ],
$options
);
@@ -268,8 +268,7 @@ class BufferedQuery
$this->status = static::STATUS_COMMENT_SQL;
$this->current .= $this->query[$i];
continue;
- }
- elseif (($this->query[$i] === '/')
+ } elseif (($this->query[$i] === '/')
&& ($this->query[$i + 1] === '*')
&& ($this->query[$i + 2] !== '!')) {
$this->status = static::STATUS_COMMENT_C;
@@ -314,7 +313,7 @@ class BufferedQuery
// Parsing the delimiter.
$delimiter = '';
- while (($i < $len) && (!Context::isWhitespace($this->query[$i]))) {
+ while (($i < $len) && (! Context::isWhitespace($this->query[$i]))) {
$delimiter .= $this->query[$i++];
}
@@ -328,7 +327,7 @@ class BufferedQuery
// Whether this statement should be returned or not.
$ret = '';
- if (!empty($this->options['parse_delimiter'])) {
+ if (! empty($this->options['parse_delimiter'])) {
// Appending the `DELIMITER` statement that was just
// found to the current statement.
$ret = trim(
@@ -370,7 +369,7 @@ class BufferedQuery
$ret = $this->current;
// If needed, adds a delimiter at the end of the statement.
- if (!empty($this->options['add_delimiter'])) {
+ if (! empty($this->options['add_delimiter'])) {
$ret .= $this->delimiter;
}
diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php
index 3dc48a6..d2c27f2 100644
--- a/src/Utils/CLI.php
+++ b/src/Utils/CLI.php
@@ -41,18 +41,23 @@ class CLI
public function parseHighlight()
{
- $longopts = array('help', 'query:', 'format:');
+ $longopts = [
+ 'help',
+ 'query:',
+ 'format:',
+ ];
$params = $this->getopt(
- 'hq:f:', $longopts
+ 'hq:f:',
+ $longopts
);
if ($params === false) {
return false;
}
$this->mergeLongOpts($params, $longopts);
- if (!isset($params['f'])) {
+ if (! isset($params['f'])) {
$params['f'] = 'cli';
}
- if (!in_array($params['f'], array('html', 'cli', 'text'))) {
+ if (! in_array($params['f'], ['html', 'cli', 'text'])) {
echo "ERROR: Invalid value for format!\n";
return false;
@@ -74,7 +79,8 @@ class CLI
}
if (isset($params['q'])) {
echo Formatter::format(
- $params['q'], array('type' => $params['f'])
+ $params['q'],
+ ['type' => $params['f']]
);
echo "\n";
@@ -93,9 +99,14 @@ class CLI
public function parseLint()
{
- $longopts = array('help', 'query:', 'context:');
+ $longopts = [
+ 'help',
+ 'query:',
+ 'context:',
+ ];
$params = $this->getopt(
- 'hq:c:', $longopts
+ 'hq:c:',
+ $longopts
);
$this->mergeLongOpts($params, $longopts);
@@ -119,7 +130,7 @@ class CLI
if (isset($params['q'])) {
$lexer = new Lexer($params['q'], false);
$parser = new Parser($lexer->list);
- $errors = Error::get(array($lexer, $parser));
+ $errors = Error::get([$lexer, $parser]);
if (count($errors) === 0) {
return 0;
}
@@ -142,9 +153,13 @@ class CLI
public function parseTokenize()
{
- $longopts = array('help', 'query:');
+ $longopts = [
+ 'help',
+ 'query:',
+ ];
$params = $this->getopt(
- 'hq:', $longopts
+ 'hq:',
+ $longopts
);
$this->mergeLongOpts($params, $longopts);
diff --git a/src/Utils/Error.php b/src/Utils/Error.php
index f80daa3..af9706f 100644
--- a/src/Utils/Error.php
+++ b/src/Utils/Error.php
@@ -32,26 +32,26 @@ class Error
*/
public static function get($objs)
{
- $ret = array();
+ $ret = [];
foreach ($objs as $obj) {
if ($obj instanceof Lexer) {
foreach ($obj->errors as $err) {
- $ret[] = array(
+ $ret[] = [
$err->getMessage(),
$err->getCode(),
$err->ch,
$err->pos,
- );
+ ];
}
} elseif ($obj instanceof Parser) {
foreach ($obj->errors as $err) {
- $ret[] = array(
+ $ret[] = [
$err->getMessage(),
$err->getCode(),
$err->token->token,
$err->token->position,
- );
+ ];
}
}
}
@@ -77,7 +77,7 @@ class Error
$errors,
$format = '#%1$d: %2$s (near "%4$s" at position %5$d)'
) {
- $ret = array();
+ $ret = [];
$i = 0;
foreach ($errors as $key => $err) {
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index c41c69c..2d2ca40 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -46,10 +46,10 @@ class Formatter
*
* @var array
*/
- public static $SHORT_CLAUSES = array(
+ public static $SHORT_CLAUSES = [
'CREATE' => true,
'INSERT' => true,
- );
+ ];
/**
* Clauses that must be inlined.
@@ -58,7 +58,7 @@ class Formatter
*
* @var array
*/
- public static $INLINE_CLAUSES = array(
+ public static $INLINE_CLAUSES = [
'CREATE' => true,
'INTO' => true,
'LIMIT' => true,
@@ -67,14 +67,14 @@ class Formatter
'PROCEDURE' => true,
'SUBPARTITION BY' => true,
'VALUES' => true,
- );
+ ];
/**
* Constructor.
*
* @param array $options the formatting options
*/
- public function __construct(array $options = array())
+ public function __construct(array $options = [])
{
$this->options = $this->getMergedOptions($options);
}
@@ -120,7 +120,7 @@ class Formatter
*/
protected function getDefaultOptions()
{
- return array(
+ return [
/*
* The format of the result.
*
@@ -171,7 +171,7 @@ class Formatter
* @var bool
*/
'indent_parts' => true,
- );
+ ];
}
/**
@@ -182,74 +182,81 @@ class Formatter
*/
protected function getDefaultFormats()
{
- return array(
- array(
+ return [
+ [
'type' => Token::TYPE_KEYWORD,
'flags' => Token::FLAG_KEYWORD_RESERVED,
'html' => 'class="sql-reserved"',
'cli' => "\x1b[35m",
'function' => 'strtoupper',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_KEYWORD,
'flags' => 0,
'html' => 'class="sql-keyword"',
'cli' => "\x1b[95m",
'function' => 'strtoupper',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_COMMENT,
'flags' => 0,
'html' => 'class="sql-comment"',
'cli' => "\x1b[37m",
'function' => '',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_BOOL,
'flags' => 0,
'html' => 'class="sql-atom"',
'cli' => "\x1b[36m",
'function' => 'strtoupper',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_NUMBER,
'flags' => 0,
'html' => 'class="sql-number"',
'cli' => "\x1b[92m",
'function' => 'strtolower',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_STRING,
'flags' => 0,
'html' => 'class="sql-string"',
'cli' => "\x1b[91m",
'function' => '',
- ),
- array(
+ ],
+ [
'type' => Token::TYPE_SYMBOL,
'flags' => 0,
'html' => 'class="sql-variable"',
'cli' => "\x1b[36m",
'function' => '',
- ),
- );
+ ],
+ ];
}
private static function mergeFormats(array $formats, array $newFormats)
{
- $added = array();
- $integers = array('flags', 'type');
- $strings = array('html', 'cli', 'function');
+ $added = [];
+ $integers = [
+ 'flags',
+ 'type',
+ ];
+ $strings = [
+ 'html',
+ 'cli',
+ 'function',
+ ];
/* Sanitize the array so that we do not have to care later */
foreach ($newFormats as $j => $new) {
foreach ($integers as $name) {
- if (!isset($new[$name])) {
+ if (! isset($new[$name])) {
$newFormats[$j][$name] = 0;
}
}
foreach ($strings as $name) {
- if (!isset($new[$name])) {
+ if (! isset($new[$name])) {
$newFormats[$j][$name] = '';
}
}
@@ -269,7 +276,7 @@ class Formatter
/* Add not already handled formats */
foreach ($newFormats as $j => $new) {
- if (!in_array($j, $added)) {
+ if (! in_array($j, $added)) {
$formats[] = $new;
}
}
@@ -327,7 +334,7 @@ class Formatter
*
* @var array
*/
- $blocksIndentation = array();
+ $blocksIndentation = [];
/**
* A stack that keeps track of the line endings every time a new block
@@ -335,7 +342,7 @@ class Formatter
*
* @var array
*/
- $blocksLineEndings = array();
+ $blocksLineEndings = [];
/**
* Whether clause's options were formatted.
@@ -396,7 +403,7 @@ class Formatter
// The options of a clause should stay on the same line and everything that follows.
if ($this->options['parts_newline']
- && !$formattedOptions
+ && ! $formattedOptions
&& empty(self::$INLINE_CLAUSES[$lastClause])
&& (
$curr->type !== Token::TYPE_KEYWORD
@@ -423,7 +430,7 @@ class Formatter
// Inline JOINs
if (($prev->type === Token::TYPE_KEYWORD && isset(JoinKeyword::$JOINS[$prev->value]))
- || (in_array($curr->value, array('ON', 'USING'), true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value]))
+ || (in_array($curr->value, ['ON', 'USING'], true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value]))
|| isset($list->tokens[$list->idx - 4], JoinKeyword::$JOINS[$list->tokens[$list->idx - 4]->value])
|| isset($list->tokens[$list->idx - 6], JoinKeyword::$JOINS[$list->tokens[$list->idx - 6]->value])
) {
@@ -448,7 +455,7 @@ class Formatter
if (end($blocksLineEndings) === true
|| (
empty(self::$INLINE_CLAUSES[$lastClause])
- && !$shortGroup
+ && ! $shortGroup
&& $this->options['parts_newline']
)
) {
@@ -486,10 +493,9 @@ class Formatter
} else {
// If the line ended there is no point in adding whitespaces.
// Also, some tokens do not have spaces before or after them.
- if (
- // A space after delimiters that are longer than 2 characters.
+ if (// A space after delimiters that are longer than 2 characters.
$prev->keyword === 'DELIMITER'
- || !(
+ || ! (
($prev->type === Token::TYPE_OPERATOR && ($prev->value === '.' || $prev->value === '('))
// No space after . (
|| ($curr->type === Token::TYPE_OPERATOR && ($curr->value === '.' || $curr->value === ',' || $curr->value === '(' || $curr->value === ')'))
@@ -516,14 +522,74 @@ class Formatter
public function escapeConsole($string)
{
return str_replace(
- array(
- "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F",
- "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F",
- ),
- array(
- '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F',
- '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F',
- ),
+ [
+ "\x00",
+ "\x01",
+ "\x02",
+ "\x03",
+ "\x04",
+ "\x05",
+ "\x06",
+ "\x07",
+ "\x08",
+ "\x09",
+ "\x0A",
+ "\x0B",
+ "\x0C",
+ "\x0D",
+ "\x0E",
+ "\x0F",
+ "\x10",
+ "\x11",
+ "\x12",
+ "\x13",
+ "\x14",
+ "\x15",
+ "\x16",
+ "\x17",
+ "\x18",
+ "\x19",
+ "\x1A",
+ "\x1B",
+ "\x1C",
+ "\x1D",
+ "\x1E",
+ "\x1F",
+ ],
+ [
+ '\x00',
+ '\x01',
+ '\x02',
+ '\x03',
+ '\x04',
+ '\x05',
+ '\x06',
+ '\x07',
+ '\x08',
+ '\x09',
+ '\x0A',
+ '\x0B',
+ '\x0C',
+ '\x0D',
+ '\x0E',
+ '\x0F',
+ '\x10',
+ '\x11',
+ '\x12',
+ '\x13',
+ '\x14',
+ '\x15',
+ '\x16',
+ '\x17',
+ '\x18',
+ '\x19',
+ '\x1A',
+ '\x1B',
+ '\x1C',
+ '\x1D',
+ '\x1E',
+ '\x1F',
+ ],
$string
);
}
@@ -545,7 +611,7 @@ class Formatter
&& ($token->flags & $format['flags']) === $format['flags']
) {
// Running transformation function.
- if (!empty($format['function'])) {
+ if (! empty($format['function'])) {
$func = $format['function'];
$text = $func($text);
}
@@ -590,7 +656,7 @@ class Formatter
*
* @return string the formatted string
*/
- public static function format($query, array $options = array())
+ public static function format($query, array $options = [])
{
$lexer = new Lexer($query);
$formatter = new self($options);
@@ -655,13 +721,11 @@ class Formatter
*/
public static function isClause($token)
{
- if (
- ($token->type === Token::TYPE_KEYWORD && isset(Parser::$STATEMENT_PARSERS[$token->keyword]))
+ if (($token->type === Token::TYPE_KEYWORD && isset(Parser::$STATEMENT_PARSERS[$token->keyword]))
|| ($token->type === Token::TYPE_NONE && strtoupper($token->token) === 'DELIMITER')
) {
return 2;
- } elseif (
- $token->type === Token::TYPE_KEYWORD && isset(Parser::$KEYWORD_PARSERS[$token->keyword])
+ } elseif ($token->type === Token::TYPE_KEYWORD && isset(Parser::$KEYWORD_PARSERS[$token->keyword])
) {
return 1;
}
diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php
index 387600f..aa9e13a 100644
--- a/src/Utils/Misc.php
+++ b/src/Utils/Misc.php
@@ -28,16 +28,16 @@ class Misc
*/
public static function getAliases($statement, $database)
{
- if (!($statement instanceof SelectStatement)
+ if (! ($statement instanceof SelectStatement)
|| empty($statement->expr)
|| empty($statement->from)
) {
- return array();
+ return [];
}
- $retval = array();
+ $retval = [];
- $tables = array();
+ $tables = [];
/**
* Expressions that may contain aliases.
@@ -48,43 +48,43 @@ class Misc
$expressions = $statement->from;
// Adding expressions from JOIN.
- if (!empty($statement->join)) {
+ if (! empty($statement->join)) {
foreach ($statement->join as $join) {
$expressions[] = $join->expr;
}
}
foreach ($expressions as $expr) {
- if (!isset($expr->table) || ($expr->table === '')) {
+ if (! isset($expr->table) || ($expr->table === '')) {
continue;
}
$thisDb = (isset($expr->database) && ($expr->database !== '')) ?
$expr->database : $database;
- if (!isset($retval[$thisDb])) {
- $retval[$thisDb] = array(
+ if (! isset($retval[$thisDb])) {
+ $retval[$thisDb] = [
'alias' => null,
- 'tables' => array(),
- );
+ 'tables' => [],
+ ];
}
- if (!isset($retval[$thisDb]['tables'][$expr->table])) {
- $retval[$thisDb]['tables'][$expr->table] = array(
+ if (! isset($retval[$thisDb]['tables'][$expr->table])) {
+ $retval[$thisDb]['tables'][$expr->table] = [
'alias' => (isset($expr->alias) && ($expr->alias !== '')) ?
$expr->alias : null,
- 'columns' => array(),
- );
+ 'columns' => [],
+ ];
}
- if (!isset($tables[$thisDb])) {
- $tables[$thisDb] = array();
+ if (! isset($tables[$thisDb])) {
+ $tables[$thisDb] = [];
}
$tables[$thisDb][$expr->alias] = $expr->table;
}
foreach ($statement->expr as $expr) {
- if (!isset($expr->column, $expr->alias) || ($expr->column === '') || ($expr->alias === '')
+ if (! isset($expr->column, $expr->alias) || ($expr->column === '') || ($expr->alias === '')
) {
continue;
}
diff --git a/src/Utils/Query.php b/src/Utils/Query.php
index b43a35e..1416629 100644
--- a/src/Utils/Query.php
+++ b/src/Utils/Query.php
@@ -47,11 +47,18 @@ class Query
*
* @var array
*/
- public static $FUNCTIONS = array(
- 'SUM', 'AVG', 'STD', 'STDDEV', 'MIN', 'MAX', 'BIT_OR', 'BIT_AND',
- );
-
- public static $ALLFLAGS = array(
+ public static $FUNCTIONS = [
+ 'SUM',
+ 'AVG',
+ 'STD',
+ 'STDDEV',
+ 'MIN',
+ 'MAX',
+ 'BIT_OR',
+ 'BIT_AND',
+ ];
+
+ public static $ALLFLAGS = [
/*
* select ... DISTINCT ...
*/
@@ -205,7 +212,7 @@ class Query
* ... UNION ...
*/
'union' => false,
- );
+ ];
/**
* Gets an array with flags select statement has.
@@ -215,12 +222,12 @@ class Query
*
* @return array
*/
- private static function _getFlagsSelect($statement, $flags)
+ private static function getFlagsSelect($statement, $flags)
{
$flags['querytype'] = 'SELECT';
$flags['is_select'] = true;
- if (!empty($statement->from)) {
+ if (! empty($statement->from)) {
$flags['select_from'] = true;
}
@@ -228,55 +235,55 @@ class Query
$flags['distinct'] = true;
}
- if (!empty($statement->group) || !empty($statement->having)) {
+ if (! empty($statement->group) || ! empty($statement->having)) {
$flags['is_group'] = true;
}
- if (!empty($statement->into)
+ if (! empty($statement->into)
&& ($statement->into->type === 'OUTFILE')
) {
$flags['is_export'] = true;
}
$expressions = $statement->expr;
- if (!empty($statement->join)) {
+ if (! empty($statement->join)) {
foreach ($statement->join as $join) {
$expressions[] = $join->expr;
}
}
foreach ($expressions as $expr) {
- if (!empty($expr->function)) {
+ if (! empty($expr->function)) {
if ($expr->function === 'COUNT') {
$flags['is_count'] = true;
} elseif (in_array($expr->function, static::$FUNCTIONS)) {
$flags['is_func'] = true;
}
}
- if (!empty($expr->subquery)) {
+ if (! empty($expr->subquery)) {
$flags['is_subquery'] = true;
}
}
- if (!empty($statement->procedure)
+ if (! empty($statement->procedure)
&& ($statement->procedure->name === 'ANALYSE')
) {
$flags['is_analyse'] = true;
}
- if (!empty($statement->group)) {
+ if (! empty($statement->group)) {
$flags['group'] = true;
}
- if (!empty($statement->having)) {
+ if (! empty($statement->having)) {
$flags['having'] = true;
}
- if (!empty($statement->union)) {
+ if (! empty($statement->union)) {
$flags['union'] = true;
}
- if (!empty($statement->join)) {
+ if (! empty($statement->join)) {
$flags['join'] = true;
}
@@ -293,7 +300,7 @@ class Query
*/
public static function getFlags($statement, $all = false)
{
- $flags = array('querytype' => false);
+ $flags = ['querytype' => false];
if ($all) {
$flags = self::$ALLFLAGS;
}
@@ -352,7 +359,7 @@ class Query
$flags['is_replace'] = true;
$flags['is_insert'] = true;
} elseif ($statement instanceof SelectStatement) {
- $flags = self::_getFlagsSelect($statement, $flags);
+ $flags = self::getFlagsSelect($statement, $flags);
} elseif ($statement instanceof ShowStatement) {
$flags['querytype'] = 'SHOW';
$flags['is_show'] = true;
@@ -367,10 +374,10 @@ class Query
|| ($statement instanceof UpdateStatement)
|| ($statement instanceof DeleteStatement)
) {
- if (!empty($statement->limit)) {
+ if (! empty($statement->limit)) {
$flags['limit'] = true;
}
- if (!empty($statement->order)) {
+ if (! empty($statement->order)) {
$flags['order'] = true;
}
}
@@ -409,18 +416,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,
- );
+ ];
}
}
@@ -432,13 +439,13 @@ 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,
- );
+ ];
}
- if (!in_array($arr, $ret['select_tables'])) {
+ if (! in_array($arr, $ret['select_tables'])) {
$ret['select_tables'][] = $arr;
}
} else {
@@ -452,12 +459,12 @@ 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,
- );
- if (!in_array($arr, $ret['select_tables'])) {
+ ];
+ if (! in_array($arr, $ret['select_tables'])) {
$ret['select_tables'][] = $arr;
}
}
@@ -477,12 +484,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)
@@ -492,11 +499,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')) {
+ if (! $statement->options->has('TABLE')) {
// No tables are dropped.
- return array();
+ return [];
}
$expressions = $statement->fields;
} elseif ($statement instanceof RenameStatement) {
@@ -505,9 +512,9 @@ class Query
}
}
- $ret = array();
+ $ret = [];
foreach ($expressions as $expr) {
- if (!empty($expr->table)) {
+ if (! empty($expr->table)) {
$expr->expr = null; // Force rebuild.
$expr->alias = null; // Aliases are not required.
$ret[] = Expression::build($expr);
@@ -779,7 +786,7 @@ class Query
$statement .= $token->token;
- if (($token->type === Token::TYPE_DELIMITER) && !empty($token->token)) {
+ if (($token->type === Token::TYPE_DELIMITER) && ! empty($token->token)) {
$delimiter = $token->token;
$fullStatement = true;
break;
@@ -788,8 +795,12 @@ class Query
// No statement was found so we return the entire query as being the
// remaining part.
- if (!$fullStatement) {
- return array(null, $query, $delimiter);
+ if (! $fullStatement) {
+ return [
+ null,
+ $query,
+ $delimiter,
+ ];
}
// At least one query was found so we have to build the rest of the
@@ -799,7 +810,11 @@ class Query
$query .= $list->tokens[$list->idx]->token;
}
- return array(trim($statement), $query, $delimiter);
+ return [
+ trim($statement),
+ $query,
+ $delimiter,
+ ];
}
/**
diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php
index 127d37b..50f319a 100644
--- a/src/Utils/Routine.php
+++ b/src/Utils/Routine.php
@@ -36,21 +36,27 @@ class Routine
$type = DataType::parse(new Parser(), $lexer->list);
if ($type === null) {
- return array('', '', '', '', '');
+ return [
+ '',
+ '',
+ '',
+ '',
+ '',
+ ];
}
- $options = array();
+ $options = [];
foreach ($type->options->options as $opt) {
$options[] = is_string($opt) ? $opt : $opt['value'];
}
- return array(
+ return [
'',
'',
$type->name,
implode(',', $type->parameters),
implode(' ', $options),
- );
+ ];
}
/**
@@ -68,23 +74,29 @@ class Routine
$param = ParameterDefinition::parse(new Parser(), $lexer->list);
if (empty($param[0])) {
- return array('', '', '', '', '');
+ return [
+ '',
+ '',
+ '',
+ '',
+ '',
+ ];
}
$param = $param[0];
- $options = array();
+ $options = [];
foreach ($param->type->options->options as $opt) {
$options[] = is_string($opt) ? $opt : $opt['value'];
}
- return array(
+ return [
empty($param->inOut) ? '' : $param->inOut,
$param->name,
$param->type->name,
implode(',', $param->type->parameters),
implode(' ', $options),
- );
+ ];
}
/**
@@ -96,17 +108,17 @@ class Routine
*/
public static function getParameters($statement)
{
- $retval = array(
+ $retval = [
'num' => 0,
- 'dir' => array(),
- 'name' => array(),
- 'type' => array(),
- 'length' => array(),
- 'length_arr' => array(),
- 'opts' => array(),
- );
-
- if (!empty($statement->parameters)) {
+ 'dir' => [],
+ 'name' => [],
+ 'type' => [],
+ 'length' => [],
+ 'length_arr' => [],
+ 'opts' => [],
+ ];
+
+ if (! empty($statement->parameters)) {
$idx = 0;
foreach ($statement->parameters as $param) {
$retval['dir'][$idx] = $param->inOut;
@@ -114,7 +126,7 @@ class Routine
$retval['type'][$idx] = $param->type->name;
$retval['length'][$idx] = implode(',', $param->type->parameters);
$retval['length_arr'][$idx] = $param->type->parameters;
- $retval['opts'][$idx] = array();
+ $retval['opts'][$idx] = [];
foreach ($param->type->options->options as $opt) {
$retval['opts'][$idx][] = is_string($opt) ?
$opt : $opt['value'];
diff --git a/src/Utils/Table.php b/src/Utils/Table.php
index b90c17a..49e3f35 100644
--- a/src/Utils/Table.php
+++ b/src/Utils/Table.php
@@ -27,30 +27,30 @@ class Table
public static function getForeignKeys($statement)
{
if (empty($statement->fields)
- || (!is_array($statement->fields))
- || (!$statement->options->has('TABLE'))
+ || (! is_array($statement->fields))
+ || (! $statement->options->has('TABLE'))
) {
- return array();
+ return [];
}
- $ret = array();
+ $ret = [];
foreach ($statement->fields as $field) {
if (empty($field->key) || ($field->key->type !== 'FOREIGN KEY')) {
continue;
}
- $columns = array();
+ $columns = [];
foreach ($field->key->columns as $column) {
$columns[] = $column['name'];
}
- $tmp = array(
+ $tmp = [
'constraint' => $field->name,
'index_list' => $columns,
- );
+ ];
- if (!empty($field->references)) {
+ if (! empty($field->references)) {
$tmp['ref_db_name'] = $field->references->table->database;
$tmp['ref_table_name'] = $field->references->table->table;
$tmp['ref_index_list'] = $field->references->columns;
@@ -84,13 +84,13 @@ class Table
public static function getFields($statement)
{
if (empty($statement->fields)
- || (!is_array($statement->fields))
- || (!$statement->options->has('TABLE'))
+ || (! is_array($statement->fields))
+ || (! $statement->options->has('TABLE'))
) {
- return array();
+ return [];
}
- $ret = array();
+ $ret = [];
foreach ($statement->fields as $field) {
// Skipping keys.
@@ -98,10 +98,10 @@ class Table
continue;
}
- $ret[$field->name] = array(
+ $ret[$field->name] = [
'type' => $field->type->name,
'timestamp_not_null' => false,
- );
+ ];
if ($field->options) {
if ($field->type->name === 'TIMESTAMP') {
diff --git a/src/Utils/Tokens.php b/src/Utils/Tokens.php
index 76ab14c..cde1a79 100644
--- a/src/Utils/Tokens.php
+++ b/src/Utils/Tokens.php
@@ -76,7 +76,7 @@ class Tokens
$isList = $list instanceof TokensList;
// Parsing the tokens.
- if (!$isList) {
+ if (! $isList) {
$list = Lexer::getTokens($list);
}
@@ -85,7 +85,7 @@ class Tokens
*
* @var array
*/
- $newList = array();
+ $newList = [];
/**
* The length of the find pattern is calculated only once.
@@ -136,7 +136,7 @@ class Tokens
++$j;
}
- if (!static::match($list->tokens[$j], $find[$k])) {
+ if (! static::match($list->tokens[$j], $find[$k])) {
// This token does not match the pattern.
break;
}
diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php
index eee093d..6facd88 100644
--- a/tests/Builder/CreateStatementTest.php
+++ b/tests/Builder/CreateStatementTest.php
@@ -99,19 +99,19 @@ class CreateStatementTest extends TestCase
$stmt = new CreateStatement();
$stmt->name = new Expression('', 'test', '');
- $stmt->options = new OptionsArray(array('TABLE'));
- $stmt->fields = array(
+ $stmt->options = new OptionsArray(['TABLE']);
+ $stmt->fields = [
new CreateDefinition(
'id',
- new OptionsArray(array('NOT NULL', 'AUTO_INCREMENT')),
- new DataType('INT', array(11), new OptionsArray(array('UNSIGNED')))
+ new OptionsArray(['NOT NULL', 'AUTO_INCREMENT']),
+ new DataType('INT', [11], new OptionsArray(['UNSIGNED']))
),
new CreateDefinition(
'',
null,
- new Key('', array(array('name' => 'id')), 'PRIMARY KEY')
+ new Key('', [['name' => 'id']], 'PRIMARY KEY')
),
- );
+ ];
$this->assertEquals(
"CREATE TABLE `test` (\n" .
@@ -202,8 +202,8 @@ class CreateStatementTest extends TestCase
public function partitionQueries()
{
- return array(
- array(
+ return [
+ [
'subparts' => <<<EOT
CREATE TABLE `ts` (
`id` int(11) DEFAULT NULL,
@@ -226,8 +226,9 @@ SUBPARTITION s5 ENGINE=InnoDB
)
)
EOT
- ),
- array(
+ ,
+ ],
+ [
'parts' => <<<EOT
CREATE TABLE ptest (
`event_date` date NOT NULL
@@ -241,8 +242,9 @@ PARTITION p3 ENGINE=InnoDB,
PARTITION p4 ENGINE=InnoDB
)
EOT
- ),
- );
+ ,
+ ],
+ ];
}
/**
@@ -289,9 +291,9 @@ EOT
{
$stmt = new CreateStatement();
- $stmt->options = new OptionsArray(array('TRIGGER'));
+ $stmt->options = new OptionsArray(['TRIGGER']);
$stmt->name = new Expression('ins_sum');
- $stmt->entityOptions = new OptionsArray(array('BEFORE', 'INSERT'));
+ $stmt->entityOptions = new OptionsArray(['BEFORE', 'INSERT']);
$stmt->table = new Expression('account');
$stmt->body = 'SET @sum = @sum + NEW.amount';
diff --git a/tests/Builder/StatementTest.php b/tests/Builder/StatementTest.php
index e2c0cb7..42e9a57 100644
--- a/tests/Builder/StatementTest.php
+++ b/tests/Builder/StatementTest.php
@@ -15,7 +15,7 @@ class StatementTest extends TestCase
{
$stmt = new SelectStatement();
- $stmt->options = new OptionsArray(array('DISTINCT'));
+ $stmt->options = new OptionsArray(['DISTINCT']);
$stmt->expr[] = new Expression('sakila', 'film', 'film_id', 'fid');
$stmt->expr[] = new Expression('COUNT(film_id)');
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php
index a4dd7b5..2e2cf6b 100644
--- a/tests/Components/Array2dTest.php
+++ b/tests/Components/Array2dTest.php
@@ -13,7 +13,10 @@ class Array2dTest extends TestCase
$parser = new Parser();
$arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +'));
$this->assertEquals(
- array(1, 2),
+ [
+ 1,
+ 2,
+ ],
$arrays[0]->values
);
}
diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php
index 4c782d2..ccef92f 100644
--- a/tests/Components/ArrayObjTest.php
+++ b/tests/Components/ArrayObjTest.php
@@ -10,13 +10,13 @@ class ArrayObjTest extends TestCase
{
public function testBuildRaw()
{
- $component = new ArrayObj(array('a', 'b'), array());
+ $component = new ArrayObj(['a', 'b'], []);
$this->assertEquals('(a, b)', ArrayObj::build($component));
}
public function testBuildValues()
{
- $component = new ArrayObj(array(), array('a', 'b'));
+ $component = new ArrayObj([], ['a', 'b']);
$this->assertEquals('(a, b)', ArrayObj::build($component));
}
@@ -25,12 +25,12 @@ class ArrayObjTest extends TestCase
$components = ArrayObj::parse(
new Parser(),
$this->getTokensList('(1 + 2, 3 + 4)'),
- array(
+ [
'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
- 'typeOptions' => array(
+ 'typeOptions' => [
'breakOnParentheses' => true,
- ),
- )
+ ],
+ ]
);
$this->assertEquals($components[0]->expr, '1 + 2');
$this->assertEquals($components[1]->expr, '3 + 4');
@@ -48,9 +48,9 @@ class ArrayObjTest extends TestCase
public function testParseProvider()
{
- return array(
- array('parser/parseArrayErr1'),
- array('parser/parseArrayErr3'),
- );
+ return [
+ ['parser/parseArrayErr1'],
+ ['parser/parseArrayErr3'],
+ ];
}
}
diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php
index 475486f..52078ef 100644
--- a/tests/Components/CaseExpressionTest.php
+++ b/tests/Components/CaseExpressionTest.php
@@ -13,7 +13,8 @@ class CaseExpressionTest extends TestCase
$caseExprQuery = 'case 1 when 1 then "Some" else "Other" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE 1 WHEN 1 THEN "Some" ELSE "Other" END'
@@ -25,7 +26,8 @@ class CaseExpressionTest extends TestCase
$caseExprQuery = 'case when 1=1 then "India" else "Other" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE WHEN 1=1 THEN "India" ELSE "Other" END'
@@ -38,7 +40,8 @@ class CaseExpressionTest extends TestCase
. 'when 2 then "SomeOther" else "Other" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" ELSE "Other" END'
@@ -51,7 +54,8 @@ class CaseExpressionTest extends TestCase
. 'when 2 then "SomeOther" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" END'
@@ -64,7 +68,8 @@ class CaseExpressionTest extends TestCase
. 'when 1=2 then "SomeOther" else "Other" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" ELSE "Other" END'
@@ -77,7 +82,8 @@ class CaseExpressionTest extends TestCase
. 'when 1=2 then "SomeOther" end';
$component = CaseExpression::parse(
new Parser(),
- $this->getTokensList($caseExprQuery));
+ $this->getTokensList($caseExprQuery)
+ );
$this->assertEquals(
CaseExpression::build($component),
'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END'
diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php
index cd413ac..ede3954 100644
--- a/tests/Components/ExpressionArrayTest.php
+++ b/tests/Components/ExpressionArrayTest.php
@@ -13,11 +13,11 @@ class ExpressionArrayTest extends TestCase
$component = ExpressionArray::parse(
new Parser(),
$this->getTokensList('(expr)'),
- array(
+ [
'breakOnParentheses' => true,
- )
+ ]
);
- $this->assertEquals(array(), $component);
+ $this->assertEquals([], $component);
}
public function testParse2()
@@ -25,9 +25,9 @@ class ExpressionArrayTest extends TestCase
$component = ExpressionArray::parse(
new Parser(),
$this->getTokensList('(expr) +'),
- array(
+ [
'parenthesesDelimited' => true,
- )
+ ]
);
$this->assertCount(1, $component);
$this->assertEquals('(expr)', $component[0]->expr);
diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php
index bb4b8fc..943aa6a 100644
--- a/tests/Components/ExpressionTest.php
+++ b/tests/Components/ExpressionTest.php
@@ -36,38 +36,38 @@ class ExpressionTest extends TestCase
public function testParseErrProvider()
{
- return array(
+ return [
/*
array(
'(1))',
'Unexpected closing bracket.',
),
*/
- array(
+ [
'tbl..col',
'Unexpected dot.',
- ),
- array(
+ ],
+ [
'id AS AS id2',
'An alias was expected.',
- ),
- array(
+ ],
+ [
'id`id2`\'id3\'',
'An alias was previously found.',
- ),
- array(
+ ],
+ [
'(id) id2 id3',
'An alias was previously found.',
- ),
- );
+ ],
+ ];
}
public function testBuild()
{
- $component = array(
+ $component = [
new Expression('1 + 2', 'three'),
new Expression('1 + 3', 'four'),
- );
+ ];
$this->assertEquals(
Expression::build($component),
'1 + 2 AS `three`, 1 + 3 AS `four`'
diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php
index b8b485a..20ac4c6 100644
--- a/tests/Components/FunctionCallTest.php
+++ b/tests/Components/FunctionCallTest.php
@@ -10,13 +10,13 @@ class FunctionCallTest extends TestCase
{
public function testBuildArray()
{
- $component = new FunctionCall('func', array('a', 'b'));
+ $component = new FunctionCall('func', ['a', 'b']);
$this->assertEquals('func(a, b)', FunctionCall::build($component));
}
public function testBuildArrayObj()
{
- $component = new FunctionCall('func', new ArrayObj(array('a', 'b')));
+ $component = new FunctionCall('func', new ArrayObj(['a', 'b']));
$this->assertEquals('func(a, b)', FunctionCall::build($component));
}
}
diff --git a/tests/Components/GroupKeywordTest.php b/tests/Components/GroupKeywordTest.php
index 8d4a407..aa88c60 100644
--- a/tests/Components/GroupKeywordTest.php
+++ b/tests/Components/GroupKeywordTest.php
@@ -12,11 +12,11 @@ class GroupKeywordTest extends TestCase
{
$this->assertEquals(
GroupKeyword::build(
- array(
+ [
new GroupKeyword(new Expression('a')),
new GroupKeyword(new Expression('b')),
new GroupKeyword(new Expression('c')),
- )
+ ]
),
'a, b, c'
);
diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php
index 8baf93f..9e8b85f 100644
--- a/tests/Components/JoinKeywordTest.php
+++ b/tests/Components/JoinKeywordTest.php
@@ -23,7 +23,7 @@ class JoinKeywordTest extends TestCase
$this->assertCount(1, $component);
$this->assertEquals('table2', $component[0]->expr->expr);
$this->assertNull($component[0]->on);
- $this->assertEquals(array('id'), $component[0]->using->values);
+ $this->assertEquals(['id'], $component[0]->using->values);
}
public function testBuild()
diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php
index e78f5ff..8d336b2 100644
--- a/tests/Components/LimitTest.php
+++ b/tests/Components/LimitTest.php
@@ -31,9 +31,9 @@ class LimitTest extends TestCase
public function testParseProvider()
{
- return array(
- array('parser/parseLimitErr1'),
- array('parser/parseLimitErr2'),
- );
+ return [
+ ['parser/parseLimitErr1'],
+ ['parser/parseLimitErr2'],
+ ];
}
}
diff --git a/tests/Components/LockExpressionTest.php b/tests/Components/LockExpressionTest.php
index 56654a6..0f8e418 100644
--- a/tests/Components/LockExpressionTest.php
+++ b/tests/Components/LockExpressionTest.php
@@ -41,28 +41,28 @@ class LockExpressionTest extends TestCase
public function testParseErrProvider()
{
- return array(
- array(
+ return [
+ [
'table1 AS t1',
'Unexpected end of LOCK expression.',
- ),
- array(
+ ],
+ [
'table1 AS t1 READ WRITE',
'Unexpected keyword.',
- ),
- array(
+ ],
+ [
'table1 AS t1 READ 2',
'Unexpected token.',
- ),
- );
+ ],
+ ];
}
public function testBuild()
{
- $component = array(
+ $component = [
LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')),
LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')),
- );
+ ];
$this->assertEquals(
LockExpression::build($component),
'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE'
diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php
index 4dda0db..c5b6eb7 100644
--- a/tests/Components/OptionsArrayTest.php
+++ b/tests/Components/OptionsArrayTest.php
@@ -13,23 +13,26 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(2, 'var'),
+ 'B' => [
+ 2,
+ 'var',
+ ],
'C' => 3,
- )
+ ]
);
$this->assertEquals(
- array(
+ [
1 => 'A',
- 2 => array(
+ 2 => [
'name' => 'B',
'expr' => '(test)',
'value' => 'test',
'equals' => true,
- ),
+ ],
3 => 'C',
- ),
+ ],
$component->options
);
}
@@ -39,10 +42,17 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('SUM = (3 + 5) RESULT = 8'),
- array(
- 'SUM' => array(1, 'expr', array('parenthesesDelimited' => true)),
- 'RESULT' => array(2, 'var'),
- )
+ [
+ 'SUM' => [
+ 1,
+ 'expr',
+ ['parenthesesDelimited' => true],
+ ],
+ 'RESULT' => [
+ 2,
+ 'var',
+ ],
+ ]
);
$this->assertEquals('(3 + 5)', (string) $component->has('SUM', true));
$this->assertEquals('8', $component->has('RESULT'));
@@ -53,11 +63,14 @@ class OptionsArrayTest extends TestCase
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(2, 'var'),
+ 'B' => [
+ 2,
+ 'var',
+ ],
'C' => 3,
- )
+ ]
);
$this->assertTrue($component->has('A'));
$this->assertEquals('test', $component->has('B'));
@@ -68,20 +81,23 @@ class OptionsArrayTest extends TestCase
public function testRemove()
{
/* Assertion 1 */
- $component = new OptionsArray(array('a', 'b', 'c'));
+ $component = new OptionsArray(['a', 'b', 'c']);
$this->assertTrue($component->remove('b'));
$this->assertFalse($component->remove('d'));
- $this->assertEquals($component->options, array(0 => 'a', 2 => 'c'));
+ $this->assertEquals($component->options, [0 => 'a', 2 => 'c']);
/* Assertion 2 */
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
- array(
+ [
'A' => 1,
- 'B' => array(2, 'var'),
+ 'B' => [
+ 2,
+ 'var',
+ ],
'C' => 3,
- )
+ ]
);
$this->assertEquals('test', $component->has('B'));
$component->remove('B');
@@ -90,23 +106,23 @@ class OptionsArrayTest extends TestCase
public function testMerge()
{
- $component = new OptionsArray(array('a'));
- $component->merge(array('b', 'c'));
- $this->assertEquals($component->options, array('a', 'b', 'c'));
+ $component = new OptionsArray(['a']);
+ $component->merge(['b', 'c']);
+ $this->assertEquals($component->options, ['a', 'b', 'c']);
}
public function testBuild()
{
$component = new OptionsArray(
- array(
+ [
'ALL',
'SQL_CALC_FOUND_ROWS',
- array(
+ [
'name' => 'MAX_STATEMENT_TIME',
'value' => '42',
'equals' => true,
- ),
- )
+ ],
+ ]
);
$this->assertEquals(
OptionsArray::build($component),
diff --git a/tests/Components/OrderKeywordTest.php b/tests/Components/OrderKeywordTest.php
index c0777ec..ffacfd4 100644
--- a/tests/Components/OrderKeywordTest.php
+++ b/tests/Components/OrderKeywordTest.php
@@ -12,10 +12,10 @@ class OrderKeywordTest extends TestCase
{
$this->assertEquals(
OrderKeyword::build(
- array(
+ [
new OrderKeyword(new Expression('a'), 'ASC'),
new OrderKeyword(new Expression('b'), 'DESC'),
- )
+ ]
),
'a ASC, b DESC'
);
diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php
index dc142fe..178776c 100644
--- a/tests/Components/ReferenceTest.php
+++ b/tests/Components/ReferenceTest.php
@@ -13,12 +13,12 @@ class ReferenceTest extends TestCase
{
$component = Reference::parse(new Parser(), $this->getTokensList('tbl (id)'));
$this->assertEquals('tbl', $component->table->table);
- $this->assertEquals(array('id'), $component->columns);
+ $this->assertEquals(['id'], $component->columns);
}
public function testBuild()
{
- $component = new Reference(new Expression('`tbl`'), array('id'));
+ $component = new Reference(new Expression('`tbl`'), ['id']);
$this->assertEquals('`tbl` (`id`)', Reference::build($component));
}
}
diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php
index 4866cf4..d822cd3 100644
--- a/tests/Lexer/ContextTest.php
+++ b/tests/Lexer/ContextTest.php
@@ -40,15 +40,36 @@ class ContextTest extends TestCase
public function contextLoading()
{
- return array(
- 'MySQL match' => array('MySql50500', 'MySql50500'),
- 'MySQL strip' => array('MySql50712', 'MySql50700'),
- 'MySQL fallback' => array('MySql99999', 'MySql50700'),
- 'MariaDB match' => array('MariaDb100000', 'MariaDb100000'),
- 'MariaDB stripg' => array('MariaDb109900', 'MariaDb100000'),
- 'MariaDB fallback' => array('MariaDb990000', 'MariaDb100300'),
- 'Invalid' => array('Sql', null),
- );
+ return [
+ 'MySQL match' => [
+ 'MySql50500',
+ 'MySql50500',
+ ],
+ 'MySQL strip' => [
+ 'MySql50712',
+ 'MySql50700',
+ ],
+ 'MySQL fallback' => [
+ 'MySql99999',
+ 'MySql50700',
+ ],
+ 'MariaDB match' => [
+ 'MariaDb100000',
+ 'MariaDb100000',
+ ],
+ 'MariaDB stripg' => [
+ 'MariaDb109900',
+ 'MariaDb100000',
+ ],
+ 'MariaDB fallback' => [
+ 'MariaDb990000',
+ 'MariaDb100300',
+ ],
+ 'Invalid' => [
+ 'Sql',
+ null,
+ ],
+ ];
}
/**
@@ -67,18 +88,18 @@ class ContextTest extends TestCase
public function contextNames()
{
- return array(
- array('MySql50000'),
- array('MySql50100'),
- array('MySql50500'),
- array('MySql50600'),
- array('MySql50700'),
- array('MySql80000'),
- array('MariaDb100000'),
- array('MariaDb100100'),
- array('MariaDb100200'),
- array('MariaDb100300'),
- );
+ return [
+ ['MySql50000'],
+ ['MySql50100'],
+ ['MySql50500'],
+ ['MySql50600'],
+ ['MySql50700'],
+ ['MySql80000'],
+ ['MariaDb100000'],
+ ['MariaDb100100'],
+ ['MariaDb100200'],
+ ['MariaDb100300'],
+ ];
}
/**
@@ -118,8 +139,11 @@ class ContextTest extends TestCase
$this->assertEquals('`test`', Context::escape('test'));
$this->assertEquals(
- array('`a`', '`b`'),
- Context::escape(array('a', 'b'))
+ [
+ '`a`',
+ '`b`',
+ ],
+ Context::escape(['a', 'b'])
);
}
}
diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php
index b5e3a10..353e80a 100644
--- a/tests/Lexer/LexerTest.php
+++ b/tests/Lexer/LexerTest.php
@@ -26,10 +26,10 @@ class LexerTest extends TestCase
$this->assertEquals(
$lexer->errors,
- array(
+ [
new LexerException('error #1', 'foo', 1, 2),
new LexerException('error #2', 'bar', 3, 4),
- )
+ ]
);
}
@@ -58,33 +58,33 @@ class LexerTest extends TestCase
public function testLexProvider()
{
- return array(
- array('lexer/lex'),
- array('lexer/lexUtf8'),
- array('lexer/lexBool'),
- array('lexer/lexComment'),
- array('lexer/lexCommentEnd'),
- array('lexer/lexDelimiter'),
- array('lexer/lexDelimiter2'),
- array('lexer/lexDelimiterErr1'),
- array('lexer/lexDelimiterErr2'),
- array('lexer/lexDelimiterErr3'),
- array('lexer/lexDelimiterLen'),
- array('lexer/lexKeyword'),
- array('lexer/lexKeyword2'),
- array('lexer/lexNumber'),
- array('lexer/lexOperator'),
- array('lexer/lexString'),
- array('lexer/lexStringErr1'),
- array('lexer/lexSymbol'),
- array('lexer/lexSymbolErr1'),
- array('lexer/lexSymbolErr2'),
- array('lexer/lexSymbolErr3'),
- array('lexer/lexSymbolUser'),
- array('lexer/lexWhitespace'),
- array('lexer/lexLabel1'),
- array('lexer/lexLabel2'),
- array('lexer/lexNoLabel'),
- );
+ return [
+ ['lexer/lex'],
+ ['lexer/lexUtf8'],
+ ['lexer/lexBool'],
+ ['lexer/lexComment'],
+ ['lexer/lexCommentEnd'],
+ ['lexer/lexDelimiter'],
+ ['lexer/lexDelimiter2'],
+ ['lexer/lexDelimiterErr1'],
+ ['lexer/lexDelimiterErr2'],
+ ['lexer/lexDelimiterErr3'],
+ ['lexer/lexDelimiterLen'],
+ ['lexer/lexKeyword'],
+ ['lexer/lexKeyword2'],
+ ['lexer/lexNumber'],
+ ['lexer/lexOperator'],
+ ['lexer/lexString'],
+ ['lexer/lexStringErr1'],
+ ['lexer/lexSymbol'],
+ ['lexer/lexSymbolErr1'],
+ ['lexer/lexSymbolErr2'],
+ ['lexer/lexSymbolErr3'],
+ ['lexer/lexSymbolUser'],
+ ['lexer/lexWhitespace'],
+ ['lexer/lexLabel1'],
+ ['lexer/lexLabel2'],
+ ['lexer/lexNoLabel'],
+ ];
}
}
diff --git a/tests/Lexer/TokensListTest.php b/tests/Lexer/TokensListTest.php
index 7d23eee..4bb844a 100644
--- a/tests/Lexer/TokensListTest.php
+++ b/tests/Lexer/TokensListTest.php
@@ -20,7 +20,7 @@ class TokensListTest extends TestCase
*/
public function setUp()
{
- $this->tokens = array(
+ $this->tokens = [
new Token('SELECT', Token::TYPE_KEYWORD),
new Token(' ', Token::TYPE_WHITESPACE),
new Token('*', Token::TYPE_OPERATOR),
@@ -29,7 +29,7 @@ class TokensListTest extends TestCase
new Token(' ', Token::TYPE_WHITESPACE),
new Token('`test`', Token::TYPE_SYMBOL),
new Token(' ', Token::TYPE_WHITESPACE),
- );
+ ];
}
public function testBuild()
diff --git a/tests/Misc/BugsTest.php b/tests/Misc/BugsTest.php
index 9a1c070..5dbb861 100644
--- a/tests/Misc/BugsTest.php
+++ b/tests/Misc/BugsTest.php
@@ -18,15 +18,15 @@ class BugsTest extends TestCase
public function testBugProvider()
{
- return array(
- array('bugs/gh9'),
- array('bugs/gh14'),
- array('bugs/gh16'),
- array('bugs/pma11800'),
- array('bugs/pma11836'),
- array('bugs/pma11843'),
- array('bugs/pma11867'),
- array('bugs/pma11879'),
- );
+ return [
+ ['bugs/gh9'],
+ ['bugs/gh14'],
+ ['bugs/gh16'],
+ ['bugs/pma11800'],
+ ['bugs/pma11836'],
+ ['bugs/pma11843'],
+ ['bugs/pma11867'],
+ ['bugs/pma11879'],
+ ];
}
}
diff --git a/tests/Misc/ParameterTest.php b/tests/Misc/ParameterTest.php
index 8aaed96..fa6b79c 100644
--- a/tests/Misc/ParameterTest.php
+++ b/tests/Misc/ParameterTest.php
@@ -18,8 +18,8 @@ class ParameterTest extends TestCase
public function testParameterProvider()
{
- return array(
- array('misc/parseParameter'),
- );
+ return [
+ ['misc/parseParameter'],
+ ];
}
}
diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php
index d0c95a3..afa3b0c 100644
--- a/tests/Misc/UtfStringTest.php
+++ b/tests/Misc/UtfStringTest.php
@@ -86,7 +86,7 @@ class UtfStringTest extends TestCase
/**
* Test access to string.
*
- * @dataProvider utf8_strings
+ * @dataProvider utf8Strings
*
* @param mixed $text
* @param mixed $pos10
@@ -100,21 +100,29 @@ class UtfStringTest extends TestCase
$this->assertEquals($pos10, $str->offsetGet(10));
}
- public function utf8_strings()
+ public function utf8Strings()
{
- return array(
- 'ascii' => array(
- 'abcdefghijklmnopqrstuvwxyz', 'k', 'u',
- ),
- 'unicode' => array(
- 'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň', 'ǐ', 'č',
- ),
- 'emoji' => array(
- '😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯', '😂', '😋',
- ),
- 'iso' => array(
- "P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy", null, null,
- ),
- );
+ return [
+ 'ascii' => [
+ 'abcdefghijklmnopqrstuvwxyz',
+ 'k',
+ 'u',
+ ],
+ 'unicode' => [
+ 'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň',
+ 'ǐ',
+ 'č',
+ ],
+ 'emoji' => [
+ '😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯',
+ '😂',
+ '😋',
+ ],
+ 'iso' => [
+ "P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy",
+ null,
+ null,
+ ],
+ ];
}
}
diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php
index 3582bf3..4582a23 100644
--- a/tests/Parser/AlterStatementTest.php
+++ b/tests/Parser/AlterStatementTest.php
@@ -18,17 +18,17 @@ class AlterStatementTest extends TestCase
public function testAlterProvider()
{
- return array(
- array('parser/parseAlter'),
- array('parser/parseAlter2'),
- array('parser/parseAlter3'),
- array('parser/parseAlter4'),
- array('parser/parseAlter5'),
- array('parser/parseAlter6'),
- array('parser/parseAlter7'),
- array('parser/parseAlter8'),
- array('parser/parseAlterErr'),
- array('parser/parseAlterErr2'),
- );
+ return [
+ ['parser/parseAlter'],
+ ['parser/parseAlter2'],
+ ['parser/parseAlter3'],
+ ['parser/parseAlter4'],
+ ['parser/parseAlter5'],
+ ['parser/parseAlter6'],
+ ['parser/parseAlter7'],
+ ['parser/parseAlter8'],
+ ['parser/parseAlterErr'],
+ ['parser/parseAlterErr2'],
+ ];
}
}
diff --git a/tests/Parser/CallStatementTest.php b/tests/Parser/CallStatementTest.php
index cb8ac25..0bb34e1 100644
--- a/tests/Parser/CallStatementTest.php
+++ b/tests/Parser/CallStatementTest.php
@@ -18,10 +18,10 @@ class CallStatementTest extends TestCase
public function testCallProvider()
{
- return array(
- array('parser/parseCall'),
- array('parser/parseCall2'),
- array('parser/parseCall3'),
- );
+ return [
+ ['parser/parseCall'],
+ ['parser/parseCall2'],
+ ['parser/parseCall3'],
+ ];
}
}
diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php
index cfb7cd0..1ac1ddc 100644
--- a/tests/Parser/CreateStatementTest.php
+++ b/tests/Parser/CreateStatementTest.php
@@ -18,36 +18,36 @@ class CreateStatementTest extends TestCase
public function testCreateProvider()
{
- return array(
- array('parser/parseCreateFunction'),
- array('parser/parseCreateFunctionErr1'),
- array('parser/parseCreateFunctionErr2'),
- array('parser/parseCreateFunctionErr3'),
- array('parser/parseCreateProcedure'),
- array('parser/parseCreateProcedure2'),
- array('parser/parseCreateTable'),
- array('parser/parseCreateTable2'),
- array('parser/parseCreateTable3'),
- array('parser/parseCreateTable4'),
- array('parser/parseCreateTable5'),
- array('parser/parseCreateTable6'),
- array('parser/parseCreateTable7'),
- array('parser/parseCreateTableErr1'),
- array('parser/parseCreateTableErr2'),
- array('parser/parseCreateTableErr3'),
- array('parser/parseCreateTableErr4'),
- array('parser/parseCreateTableErr5'),
- array('parser/parseCreateTableSelect'),
- array('parser/parseCreateTableAsSelect'),
- array('parser/parseCreateTableLike'),
- array('parser/parseCreateTableSpatial'),
- array('parser/parseCreateTableTimestampWithPrecision'),
- array('parser/parseCreateTrigger'),
- array('parser/parseCreateUser'),
- array('parser/parseCreateView'),
- array('parser/parseCreateView2'),
- array('parser/parseCreateViewWithoutQuotes'),
- array('parser/parseCreateViewWithQuotes'),
- );
+ return [
+ ['parser/parseCreateFunction'],
+ ['parser/parseCreateFunctionErr1'],
+ ['parser/parseCreateFunctionErr2'],
+ ['parser/parseCreateFunctionErr3'],
+ ['parser/parseCreateProcedure'],
+ ['parser/parseCreateProcedure2'],
+ ['parser/parseCreateTable'],
+ ['parser/parseCreateTable2'],
+ ['parser/parseCreateTable3'],
+ ['parser/parseCreateTable4'],
+ ['parser/parseCreateTable5'],
+ ['parser/parseCreateTable6'],
+ ['parser/parseCreateTable7'],
+ ['parser/parseCreateTableErr1'],
+ ['parser/parseCreateTableErr2'],
+ ['parser/parseCreateTableErr3'],
+ ['parser/parseCreateTableErr4'],
+ ['parser/parseCreateTableErr5'],
+ ['parser/parseCreateTableSelect'],
+ ['parser/parseCreateTableAsSelect'],
+ ['parser/parseCreateTableLike'],
+ ['parser/parseCreateTableSpatial'],
+ ['parser/parseCreateTableTimestampWithPrecision'],
+ ['parser/parseCreateTrigger'],
+ ['parser/parseCreateUser'],
+ ['parser/parseCreateView'],
+ ['parser/parseCreateView2'],
+ ['parser/parseCreateViewWithoutQuotes'],
+ ['parser/parseCreateViewWithQuotes'],
+ ];
}
}
diff --git a/tests/Parser/DeleteStatementTest.php b/tests/Parser/DeleteStatementTest.php
index f781d7b..348d666 100644
--- a/tests/Parser/DeleteStatementTest.php
+++ b/tests/Parser/DeleteStatementTest.php
@@ -18,32 +18,32 @@ class DeleteStatementTest extends TestCase
public function testDeleteProvider()
{
- return array(
- array('parser/parseDelete'),
- array('parser/parseDelete2'),
- array('parser/parseDelete3'),
- array('parser/parseDelete4'),
- array('parser/parseDelete5'),
- array('parser/parseDelete6'),
- array('parser/parseDelete7'),
- array('parser/parseDelete8'),
- array('parser/parseDelete9'),
- array('parser/parseDelete10'),
- array('parser/parseDelete11'),
- array('parser/parseDelete12'),
- array('parser/parseDeleteErr1'),
- array('parser/parseDeleteErr2'),
- array('parser/parseDeleteErr3'),
- array('parser/parseDeleteErr4'),
- array('parser/parseDeleteErr5'),
- array('parser/parseDeleteErr6'),
- array('parser/parseDeleteErr7'),
- array('parser/parseDeleteErr8'),
- array('parser/parseDeleteErr9'),
- array('parser/parseDeleteErr10'),
- array('parser/parseDeleteErr11'),
- array('parser/parseDeleteErr12'),
- array('parser/parseDeleteJoin'),
- );
+ return [
+ ['parser/parseDelete'],
+ ['parser/parseDelete2'],
+ ['parser/parseDelete3'],
+ ['parser/parseDelete4'],
+ ['parser/parseDelete5'],
+ ['parser/parseDelete6'],
+ ['parser/parseDelete7'],
+ ['parser/parseDelete8'],
+ ['parser/parseDelete9'],
+ ['parser/parseDelete10'],
+ ['parser/parseDelete11'],
+ ['parser/parseDelete12'],
+ ['parser/parseDeleteErr1'],
+ ['parser/parseDeleteErr2'],
+ ['parser/parseDeleteErr3'],
+ ['parser/parseDeleteErr4'],
+ ['parser/parseDeleteErr5'],
+ ['parser/parseDeleteErr6'],
+ ['parser/parseDeleteErr7'],
+ ['parser/parseDeleteErr8'],
+ ['parser/parseDeleteErr9'],
+ ['parser/parseDeleteErr10'],
+ ['parser/parseDeleteErr11'],
+ ['parser/parseDeleteErr12'],
+ ['parser/parseDeleteJoin'],
+ ];
}
}
diff --git a/tests/Parser/ExplainStatement.php b/tests/Parser/ExplainStatement.php
index 6cf3059..804a0e4 100644
--- a/tests/Parser/ExplainStatement.php
+++ b/tests/Parser/ExplainStatement.php
@@ -18,8 +18,8 @@ class ExplainStatementTest extends TestCase
public function testExplainProvider()
{
- return array(
- array('parser/parseExplain'),
- );
+ return [
+ ['parser/parseExplain'],
+ ];
}
}
diff --git a/tests/Parser/InsertStatementTest.php b/tests/Parser/InsertStatementTest.php
index 1ba0a05..396b6c4 100644
--- a/tests/Parser/InsertStatementTest.php
+++ b/tests/Parser/InsertStatementTest.php
@@ -18,16 +18,16 @@ class InsertStatementTest extends TestCase
public function testInsertProvider()
{
- return array(
- array('parser/parseInsert'),
- array('parser/parseInsertSelect'),
- array('parser/parseInsertOnDuplicateKey'),
- array('parser/parseInsertSetOnDuplicateKey'),
- array('parser/parseInsertSelectOnDuplicateKey'),
- array('parser/parseInsertOnDuplicateKeyErr'),
- array('parser/parseInsertErr'),
- array('parser/parseInsertErr2'),
- array('parser/parseInsertIntoErr'),
- );
+ return [
+ ['parser/parseInsert'],
+ ['parser/parseInsertSelect'],
+ ['parser/parseInsertOnDuplicateKey'],
+ ['parser/parseInsertSetOnDuplicateKey'],
+ ['parser/parseInsertSelectOnDuplicateKey'],
+ ['parser/parseInsertOnDuplicateKeyErr'],
+ ['parser/parseInsertErr'],
+ ['parser/parseInsertErr2'],
+ ['parser/parseInsertIntoErr'],
+ ];
}
}
diff --git a/tests/Parser/LoadStatementTest.php b/tests/Parser/LoadStatementTest.php
index 089b1f4..f18dcf6 100644
--- a/tests/Parser/LoadStatementTest.php
+++ b/tests/Parser/LoadStatementTest.php
@@ -27,19 +27,19 @@ class LoadStatementTest extends TestCase
public function testLoadProvider()
{
- return array(
- array('parser/parseLoad1'),
- array('parser/parseLoad2'),
- array('parser/parseLoad3'),
- array('parser/parseLoad4'),
- array('parser/parseLoad5'),
- array('parser/parseLoad6'),
- array('parser/parseLoadErr1'),
- array('parser/parseLoadErr2'),
- array('parser/parseLoadErr3'),
- array('parser/parseLoadErr4'),
- array('parser/parseLoadErr5'),
- array('parser/parseLoadErr6'),
- );
+ return [
+ ['parser/parseLoad1'],
+ ['parser/parseLoad2'],
+ ['parser/parseLoad3'],
+ ['parser/parseLoad4'],
+ ['parser/parseLoad5'],
+ ['parser/parseLoad6'],
+ ['parser/parseLoadErr1'],
+ ['parser/parseLoadErr2'],
+ ['parser/parseLoadErr3'],
+ ['parser/parseLoadErr4'],
+ ['parser/parseLoadErr5'],
+ ['parser/parseLoadErr6'],
+ ];
}
}
diff --git a/tests/Parser/LockStatementTest.php b/tests/Parser/LockStatementTest.php
index 3458e0a..0f7a416 100644
--- a/tests/Parser/LockStatementTest.php
+++ b/tests/Parser/LockStatementTest.php
@@ -18,24 +18,24 @@ class LockStatementTest extends TestCase
public function testLockProvider()
{
- return array(
- array('parser/parseLock1'),
- array('parser/parseLock2'),
- array('parser/parseLock3'),
- array('parser/parseLock4'),
- array('parser/parseLock5'),
- array('parser/parseLockErr1'),
- array('parser/parseLockErr2'),
- array('parser/parseLockErr3'),
- array('parser/parseLockErr4'),
- array('parser/parseLockErr5'),
- array('parser/parseLockErr6'),
- array('parser/parseLockErr7'),
- array('parser/parseLockErr8'),
- array('parser/parseLockErr9'),
- array('parser/parseLockErr10'),
- array('parser/parseUnlock1'),
- array('parser/parseUnlockErr1'),
- );
+ return [
+ ['parser/parseLock1'],
+ ['parser/parseLock2'],
+ ['parser/parseLock3'],
+ ['parser/parseLock4'],
+ ['parser/parseLock5'],
+ ['parser/parseLockErr1'],
+ ['parser/parseLockErr2'],
+ ['parser/parseLockErr3'],
+ ['parser/parseLockErr4'],
+ ['parser/parseLockErr5'],
+ ['parser/parseLockErr6'],
+ ['parser/parseLockErr7'],
+ ['parser/parseLockErr8'],
+ ['parser/parseLockErr9'],
+ ['parser/parseLockErr10'],
+ ['parser/parseUnlock1'],
+ ['parser/parseUnlockErr1'],
+ ];
}
}
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index 9d1b7b8..16dcbf9 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -22,11 +22,11 @@ class ParserTest extends TestCase
public function testParseProvider()
{
- return array(
- array('parser/parse'),
- array('parser/parse2'),
- array('parser/parseDelimiter'),
- );
+ return [
+ ['parser/parse'],
+ ['parser/parse2'],
+ ['parser/parseDelimiter'],
+ ];
}
public function testUnrecognizedStatement()
@@ -60,10 +60,10 @@ class ParserTest extends TestCase
$this->assertEquals(
$parser->errors,
- array(
+ [
new ParserException('error #1', new Token('foo'), 1),
new ParserException('error #2', new Token('bar'), 2),
- )
+ ]
);
}
diff --git a/tests/Parser/PurgeStatementTest.php b/tests/Parser/PurgeStatementTest.php
index dd67dc6..8716cb4 100644
--- a/tests/Parser/PurgeStatementTest.php
+++ b/tests/Parser/PurgeStatementTest.php
@@ -18,14 +18,14 @@ class PurgeStatementTest extends TestCase
public function testPurgeProvider()
{
- return array(
- array('parser/parsePurge'),
- array('parser/parsePurge2'),
- array('parser/parsePurge3'),
- array('parser/parsePurge4'),
- array('parser/parsePurgeErr'),
- array('parser/parsePurgeErr2'),
- array('parser/parsePurgeErr3'),
- );
+ return [
+ ['parser/parsePurge'],
+ ['parser/parsePurge2'],
+ ['parser/parsePurge3'],
+ ['parser/parsePurge4'],
+ ['parser/parsePurgeErr'],
+ ['parser/parsePurgeErr2'],
+ ['parser/parsePurgeErr3'],
+ ];
}
}
diff --git a/tests/Parser/RenameStatementTest.php b/tests/Parser/RenameStatementTest.php
index acbe2e2..47db80e 100644
--- a/tests/Parser/RenameStatementTest.php
+++ b/tests/Parser/RenameStatementTest.php
@@ -18,14 +18,14 @@ class RenameStatementTest extends TestCase
public function testRenameProvider()
{
- return array(
- array('parser/parseRename'),
- array('parser/parseRename2'),
- array('parser/parseRenameErr1'),
- array('parser/parseRenameErr2'),
- array('parser/parseRenameErr3'),
- array('parser/parseRenameErr4'),
- array('parser/parseRenameErr5'),
- );
+ return [
+ ['parser/parseRename'],
+ ['parser/parseRename2'],
+ ['parser/parseRenameErr1'],
+ ['parser/parseRenameErr2'],
+ ['parser/parseRenameErr3'],
+ ['parser/parseRenameErr4'],
+ ['parser/parseRenameErr5'],
+ ];
}
}
diff --git a/tests/Parser/ReplaceStatementTest.php b/tests/Parser/ReplaceStatementTest.php
index a3551bc..9745ada 100644
--- a/tests/Parser/ReplaceStatementTest.php
+++ b/tests/Parser/ReplaceStatementTest.php
@@ -18,16 +18,16 @@ class ReplaceStatementTest extends TestCase
public function testReplaceProvider()
{
- return array(
- array('parser/parseReplace'),
- array('parser/parseReplace2'),
- array('parser/parseReplaceValues'),
- array('parser/parseReplaceSet'),
- array('parser/parseReplaceSelect'),
- array('parser/parseReplaceErr'),
- array('parser/parseReplaceErr2'),
- array('parser/parseReplaceErr3'),
- array('parser/parseReplaceIntoErr'),
- );
+ return [
+ ['parser/parseReplace'],
+ ['parser/parseReplace2'],
+ ['parser/parseReplaceValues'],
+ ['parser/parseReplaceSet'],
+ ['parser/parseReplaceSelect'],
+ ['parser/parseReplaceErr'],
+ ['parser/parseReplaceErr2'],
+ ['parser/parseReplaceErr3'],
+ ['parser/parseReplaceIntoErr'],
+ ];
}
}
diff --git a/tests/Parser/RestoreStatementTest.php b/tests/Parser/RestoreStatementTest.php
index 7f25e95..d8b73dc 100644
--- a/tests/Parser/RestoreStatementTest.php
+++ b/tests/Parser/RestoreStatementTest.php
@@ -18,8 +18,8 @@ class RestoreStatementTest extends TestCase
public function testRestoreProvider()
{
- return array(
- array('parser/parseRestore'),
- );
+ return [
+ ['parser/parseRestore'],
+ ];
}
}
diff --git a/tests/Parser/SelectStatementTest.php b/tests/Parser/SelectStatementTest.php
index 55b80ec..cc860f0 100644
--- a/tests/Parser/SelectStatementTest.php
+++ b/tests/Parser/SelectStatementTest.php
@@ -27,64 +27,64 @@ class SelectStatementTest extends TestCase
public function testSelectProvider()
{
- return array(
- array('parser/parseSelect2'),
- array('parser/parseSelect3'),
- array('parser/parseSelect4'),
- array('parser/parseSelect5'),
- array('parser/parseSelect6'),
- array('parser/parseSelect7'),
- array('parser/parseSelect8'),
- array('parser/parseSelect9'),
- array('parser/parseSelect10'),
- array('parser/parseSelect11'),
- array('parser/parseSelectErr1'),
- array('parser/parseSelectErr2'),
- array('parser/parseSelectNested'),
- array('parser/parseSelectCase1'),
- array('parser/parseSelectCase2'),
- array('parser/parseSelectCase3'),
- array('parser/parseSelectCase4'),
- array('parser/parseSelectCase5'),
- array('parser/parseSelectCaseErr1'),
- array('parser/parseSelectCaseErr2'),
- array('parser/parseSelectCaseErr3'),
- array('parser/parseSelectCaseErr4'),
- array('parser/parseSelectCaseErr5'),
- array('parser/parseSelectCaseAlias1'),
- array('parser/parseSelectCaseAlias2'),
- array('parser/parseSelectCaseAlias3'),
- array('parser/parseSelectCaseAlias4'),
- array('parser/parseSelectCaseAlias5'),
- array('parser/parseSelectCaseAlias6'),
- array('parser/parseSelectCaseAliasErr1'),
- array('parser/parseSelectCaseAliasErr2'),
- array('parser/parseSelectCaseAliasErr3'),
- array('parser/parseSelectCaseAliasErr4'),
- array('parser/parseSelectIntoOptions1'),
- array('parser/parseSelectIntoOptions2'),
- array('parser/parseSelectIntoOptions3'),
- array('parser/parseSelectJoinCross'),
- array('parser/parseSelectJoinNatural'),
- array('parser/parseSelectJoinNaturalLeft'),
- array('parser/parseSelectJoinNaturalRight'),
- array('parser/parseSelectJoinNaturalLeftOuter'),
- array('parser/parseSelectJoinNaturalRightOuter'),
- array('parser/parseSelectJoinMultiple'),
- array('parser/parseSelectJoinMultiple2'),
- array('parser/parseSelectWrongOrder'),
- array('parser/parseSelectWrongOrder2'),
- array('parser/parseSelectEndOptions1'),
- array('parser/parseSelectEndOptions2'),
- array('parser/parseSelectEndOptionsErr'),
- array('parser/parseSelectUnion'),
- array('parser/parseSelectUnion2'),
- array('parser/parseSelectIndexHint1'),
- array('parser/parseSelectIndexHint2'),
- array('parser/parseSelectIndexHintErr1'),
- array('parser/parseSelectIndexHintErr2'),
- array('parser/parseSelectIndexHintErr3'),
- array('parser/parseSelectIndexHintErr4'),
- );
+ return [
+ ['parser/parseSelect2'],
+ ['parser/parseSelect3'],
+ ['parser/parseSelect4'],
+ ['parser/parseSelect5'],
+ ['parser/parseSelect6'],
+ ['parser/parseSelect7'],
+ ['parser/parseSelect8'],
+ ['parser/parseSelect9'],
+ ['parser/parseSelect10'],
+ ['parser/parseSelect11'],
+ ['parser/parseSelectErr1'],
+ ['parser/parseSelectErr2'],
+ ['parser/parseSelectNested'],
+ ['parser/parseSelectCase1'],
+ ['parser/parseSelectCase2'],
+ ['parser/parseSelectCase3'],
+ ['parser/parseSelectCase4'],
+ ['parser/parseSelectCase5'],
+ ['parser/parseSelectCaseErr1'],
+ ['parser/parseSelectCaseErr2'],
+ ['parser/parseSelectCaseErr3'],
+ ['parser/parseSelectCaseErr4'],
+ ['parser/parseSelectCaseErr5'],
+ ['parser/parseSelectCaseAlias1'],
+ ['parser/parseSelectCaseAlias2'],
+ ['parser/parseSelectCaseAlias3'],
+ ['parser/parseSelectCaseAlias4'],
+ ['parser/parseSelectCaseAlias5'],
+ ['parser/parseSelectCaseAlias6'],
+ ['parser/parseSelectCaseAliasErr1'],
+ ['parser/parseSelectCaseAliasErr2'],
+ ['parser/parseSelectCaseAliasErr3'],
+ ['parser/parseSelectCaseAliasErr4'],
+ ['parser/parseSelectIntoOptions1'],
+ ['parser/parseSelectIntoOptions2'],
+ ['parser/parseSelectIntoOptions3'],
+ ['parser/parseSelectJoinCross'],
+ ['parser/parseSelectJoinNatural'],
+ ['parser/parseSelectJoinNaturalLeft'],
+ ['parser/parseSelectJoinNaturalRight'],
+ ['parser/parseSelectJoinNaturalLeftOuter'],
+ ['parser/parseSelectJoinNaturalRightOuter'],
+ ['parser/parseSelectJoinMultiple'],
+ ['parser/parseSelectJoinMultiple2'],
+ ['parser/parseSelectWrongOrder'],
+ ['parser/parseSelectWrongOrder2'],
+ ['parser/parseSelectEndOptions1'],
+ ['parser/parseSelectEndOptions2'],
+ ['parser/parseSelectEndOptionsErr'],
+ ['parser/parseSelectUnion'],
+ ['parser/parseSelectUnion2'],
+ ['parser/parseSelectIndexHint1'],
+ ['parser/parseSelectIndexHint2'],
+ ['parser/parseSelectIndexHintErr1'],
+ ['parser/parseSelectIndexHintErr2'],
+ ['parser/parseSelectIndexHintErr3'],
+ ['parser/parseSelectIndexHintErr4'],
+ ];
}
}
diff --git a/tests/Parser/SetStatementTest.php b/tests/Parser/SetStatementTest.php
index 61062e3..b3ae9c2 100644
--- a/tests/Parser/SetStatementTest.php
+++ b/tests/Parser/SetStatementTest.php
@@ -18,14 +18,14 @@ class SetStatementTest extends TestCase
public function testSetProvider()
{
- return array(
- array('parser/parseSetCharset'),
- array('parser/parseSetCharsetError'),
- array('parser/parseSetCharacterSet'),
- array('parser/parseSetCharacterSetError'),
- array('parser/parseSetNames'),
- array('parser/parseSetNamesError'),
- array('parser/parseSetError1'),
- );
+ return [
+ ['parser/parseSetCharset'],
+ ['parser/parseSetCharsetError'],
+ ['parser/parseSetCharacterSet'],
+ ['parser/parseSetCharacterSetError'],
+ ['parser/parseSetNames'],
+ ['parser/parseSetNamesError'],
+ ['parser/parseSetError1'],
+ ];
}
}
diff --git a/tests/Parser/TransactionStatementTest.php b/tests/Parser/TransactionStatementTest.php
index 031ffa6..6234f17 100644
--- a/tests/Parser/TransactionStatementTest.php
+++ b/tests/Parser/TransactionStatementTest.php
@@ -18,11 +18,11 @@ class TransactionStatementTest extends TestCase
public function testTransactionProvider()
{
- return array(
- array('parser/parseTransaction'),
- array('parser/parseTransaction2'),
- array('parser/parseTransaction3'),
- array('parser/parseTransactionErr1'),
- );
+ return [
+ ['parser/parseTransaction'],
+ ['parser/parseTransaction2'],
+ ['parser/parseTransaction3'],
+ ['parser/parseTransactionErr1'],
+ ];
}
}
diff --git a/tests/Parser/UpdateStatementTest.php b/tests/Parser/UpdateStatementTest.php
index 1d6c923..8a47f44 100644
--- a/tests/Parser/UpdateStatementTest.php
+++ b/tests/Parser/UpdateStatementTest.php
@@ -18,11 +18,11 @@ class UpdateStatementTest extends TestCase
public function testUpdateProvider()
{
- return array(
- array('parser/parseUpdate'),
- array('parser/parseUpdate2'),
- array('parser/parseUpdate3'),
- array('parser/parseUpdateErr'),
- );
+ return [
+ ['parser/parseUpdate'],
+ ['parser/parseUpdate2'],
+ ['parser/parseUpdate3'],
+ ['parser/parseUpdateErr'],
+ ];
}
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 1b97a9e..cb925e1 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -45,11 +45,20 @@ abstract class TestCase extends BaseTestCase
*/
public function getErrorsAsArray($obj)
{
- $ret = array();
+ $ret = [];
foreach ($obj->errors as $err) {
$ret[] = $obj instanceof Lexer
- ? array($err->getMessage(), $err->ch, $err->pos, $err->getCode())
- : array($err->getMessage(), $err->token, $err->getCode());
+ ? [
+ $err->getMessage(),
+ $err->ch,
+ $err->pos,
+ $err->getCode(),
+ ]
+ : [
+ $err->getMessage(),
+ $err->token,
+ $err->getCode(),
+ ];
}
return $ret;
@@ -92,14 +101,14 @@ abstract class TestCase extends BaseTestCase
// Lexer.
$lexer = new Lexer($data['query']);
$lexerErrors = $this->getErrorsAsArray($lexer);
- $lexer->errors = array();
+ $lexer->errors = [];
// Parser.
$parser = empty($data['parser']) ? null : new Parser($lexer->list);
- $parserErrors = array();
+ $parserErrors = [];
if ($parser !== null) {
$parserErrors = $this->getErrorsAsArray($parser);
- $parser->errors = array();
+ $parser->errors = [];
}
// Testing objects.
diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php
index 731fc0e..f31dd78 100644
--- a/tests/Utils/BufferedQueryTest.php
+++ b/tests/Utils/BufferedQueryTest.php
@@ -27,7 +27,7 @@ class BufferedQueryTest extends TestCase
*
* @var array
*/
- $statements = array();
+ $statements = [];
/**
* The `BufferedQuery` instance used for extraction.
@@ -99,21 +99,21 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' . "\n" .
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */';
- return array(
- array(
+ return [
+ [
"SELECT '\'';\nSELECT '\'';",
8,
- array(
+ [
'parse_delimiter' => true,
'add_delimiter' => true,
- ),
- array(
+ ],
+ [
"SELECT '\'';",
"SELECT '\'';",
- ),
- ),
+ ],
+ ],
- array(
+ [
"CREATE TABLE `test` (\n" .
" `txt` varchar(10)\n" .
");\n" .
@@ -121,58 +121,58 @@ class BufferedQueryTest extends TestCase
"INSERT INTO `test` (`txt`) VALUES('\\\\');\n" .
"INSERT INTO `test` (`txt`) VALUES('xyz');\n",
8,
- array(
+ [
'parse_delimiter' => true,
'add_delimiter' => true,
- ),
- array(
+ ],
+ [
"CREATE TABLE `test` (\n" .
" `txt` varchar(10)\n" .
');',
"INSERT INTO `test` (`txt`) VALUES('abc');",
"INSERT INTO `test` (`txt`) VALUES('\\\\');",
"INSERT INTO `test` (`txt`) VALUES('xyz');",
- ),
- ),
+ ],
+ ],
- array(
+ [
'SELECT """""""";' .
'SELECT """\\\\"""',
8,
- array(
+ [
'parse_delimiter' => true,
'add_delimiter' => true,
- ),
- array(
+ ],
+ [
'SELECT """""""";',
'SELECT """\\\\"""',
- ),
- ),
+ ],
+ ],
- array(
+ [
'DELIMITER A_VERY_LONG_DEL' . "\n" .
'SELECT 1 A_VERY_LONG_DEL' . "\n" .
'DELIMITER ;',
3,
- array(
+ [
'parse_delimiter' => true,
'add_delimiter' => true,
- ),
- array(
+ ],
+ [
'DELIMITER A_VERY_LONG_DEL',
'SELECT 1 A_VERY_LONG_DEL',
'DELIMITER ;',
- ),
- ),
+ ],
+ ],
- array(
+ [
$query,
32,
- array(
+ [
'parse_delimiter' => false,
'add_delimiter' => false,
- ),
- array(
+ ],
+ [
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */',
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */',
@@ -216,17 +216,17 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
- ),
- ),
+ ],
+ ],
- array(
+ [
$query,
32,
- array(
+ [
'parse_delimiter' => true,
'add_delimiter' => false,
- ),
- array(
+ ],
+ [
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */',
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */',
@@ -274,17 +274,17 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
- ),
- ),
+ ],
+ ],
- array(
+ [
$query,
64,
- array(
+ [
'parse_delimiter' => false,
'add_delimiter' => true,
- ),
- array(
+ ],
+ [
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;',
'/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;',
@@ -328,8 +328,8 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;',
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
- ),
- ),
- );
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/CLITest.php b/tests/Utils/CLITest.php
index f627dfd..ebcd35e 100644
--- a/tests/Utils/CLITest.php
+++ b/tests/Utils/CLITest.php
@@ -8,7 +8,7 @@ class CLITest extends TestCase
{
private function getCLI($getopt)
{
- $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt'))->getMock();
+ $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(['getopt'])->getMock();
$cli->method('getopt')->willReturn($getopt);
return $cli;
@@ -23,8 +23,8 @@ class CLITest extends TestCase
{
$cli = new \PhpMyAdmin\SqlParser\Utils\CLI();
$this->assertEquals(
- $cli->getopt('', array()),
- array()
+ $cli->getopt('', []),
+ []
);
}
@@ -44,50 +44,59 @@ class CLITest extends TestCase
public function highlightParams()
{
- return array(
- array(
- array('q' => 'SELECT 1'),
+ return [
+ [
+ ['q' => 'SELECT 1'],
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n",
0,
- ),
- array(
- array('query' => 'SELECT 1'),
+ ],
+ [
+ ['query' => 'SELECT 1'],
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n",
0,
- ),
- array(
- array('q' => 'SELECT /* comment */ 1 /* other */', 'f' => 'text'),
+ ],
+ [
+ [
+ 'q' => 'SELECT /* comment */ 1 /* other */',
+ 'f' => 'text',
+ ],
"SELECT\n /* comment */ 1 /* other */\n",
0,
- ),
- array(
- array('q' => 'SELECT 1', 'f' => 'foo'),
+ ],
+ [
+ [
+ 'q' => 'SELECT 1',
+ 'f' => 'foo',
+ ],
"ERROR: Invalid value for format!\n",
1,
- ),
- array(
- array('q' => 'SELECT 1', 'f' => 'html'),
+ ],
+ [
+ [
+ 'q' => 'SELECT 1',
+ 'f' => 'html',
+ ],
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>' . "\n",
0,
- ),
- array(
- array('h' => true),
+ ],
+ [
+ ['h' => true],
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n",
0,
- ),
- array(
- array(),
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
1,
- ),
- );
+ ],
+ ];
}
/**
@@ -106,41 +115,41 @@ class CLITest extends TestCase
public function lintParams()
{
- return array(
- array(
- array('q' => 'SELECT 1'),
+ return [
+ [
+ ['q' => 'SELECT 1'],
'',
0,
- ),
- array(
- array('query' => 'SELECT 1'),
+ ],
+ [
+ ['query' => 'SELECT 1'],
'',
0,
- ),
- array(
- array('q' => 'SELECT SELECT'),
+ ],
+ [
+ ['q' => 'SELECT SELECT'],
'#1: An expression was expected. (near "SELECT" at position 7)' . "\n" .
'#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" .
'#3: An expression was expected. (near "" at position 0)' . "\n",
10,
- ),
- array(
- array('h' => true),
+ ],
+ [
+ ['h' => true],
'Usage: lint-query --query SQL' . "\n",
0,
- ),
- array(
- array(),
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: lint-query --query SQL' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
1,
- ),
- );
+ ],
+ ];
}
/**
@@ -166,33 +175,33 @@ class CLITest extends TestCase
. "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n"
);
- return array(
- array(
- array('q' => 'SELECT 1'),
+ return [
+ [
+ ['q' => 'SELECT 1'],
$result,
0,
- ),
- array(
- array('query' => 'SELECT 1'),
+ ],
+ [
+ ['query' => 'SELECT 1'],
$result,
0,
- ),
- array(
- array('h' => true),
+ ],
+ [
+ ['h' => true],
'Usage: tokenize-query --query SQL' . "\n",
0,
- ),
- array(
- array(),
+ ],
+ [
+ [],
'ERROR: Missing parameters!' . "\n" .
'Usage: tokenize-query --query SQL' . "\n",
1,
- ),
- array(
+ ],
+ [
false,
'',
1,
- ),
- );
+ ],
+ ];
}
}
diff --git a/tests/Utils/ErrorTest.php b/tests/Utils/ErrorTest.php
index 7a62e46..d7d1393 100644
--- a/tests/Utils/ErrorTest.php
+++ b/tests/Utils/ErrorTest.php
@@ -14,19 +14,29 @@ class ErrorTest extends TestCase
$lexer = new Lexer('SELECT * FROM db..tbl $');
$parser = new Parser($lexer->list);
$this->assertEquals(
- array(
- array('Unexpected character.', 0, '$', 22),
- array('Unexpected dot.', 0, '.', 17),
- ),
- Error::get(array($lexer, $parser))
+ [
+ [
+ 'Unexpected character.',
+ 0,
+ '$',
+ 22,
+ ],
+ [
+ 'Unexpected dot.',
+ 0,
+ '.',
+ 17,
+ ],
+ ],
+ Error::get([$lexer, $parser])
);
}
public function testFormat()
{
$this->assertEquals(
- array('#1: error msg (near "token" at position 100)'),
- Error::format(array(array('error msg', 42, 'token', 100)))
+ ['#1: error msg (near "token" at position 100)'],
+ Error::format([['error msg', 42, 'token', 100]])
);
}
}
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index d39ff9e..152359e 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -18,37 +18,37 @@ class FormatTest extends TestCase
{
$formatter = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\Formatter')
->disableOriginalConstructor()
- ->setMethods(array('getDefaultOptions', 'getDefaultFormats'))
+ ->setMethods(['getDefaultOptions', 'getDefaultFormats'])
->getMock();
$formatter->expects($this->once())
->method('getDefaultOptions')
- ->willReturn(array(
+ ->willReturn([
'type' => 'text',
'line_ending' => null,
'indentation' => null,
'clause_newline' => null,
'parts_newline' => null,
- ));
+ ]);
$formatter->expects($this->once())
->method('getDefaultFormats')
->willReturn($default);
- $expectedOptions = array(
+ $expectedOptions = [
'type' => 'test-type',
'line_ending' => '<br>',
'indentation' => ' ',
'clause_newline' => null,
'parts_newline' => 0,
'formats' => $expected,
- );
+ ];
- $overridingOptions = array(
+ $overridingOptions = [
'type' => 'test-type',
'line_ending' => '<br>',
'formats' => $overriding,
- );
+ ];
$reflectionMethod = new \ReflectionMethod($formatter, 'getMergedOptions');
$reflectionMethod->setAccessible(true);
@@ -58,179 +58,178 @@ class FormatTest extends TestCase
public function mergeFormats()
{
// array($default[], $overriding[], $expected[])
- return array(
- 'empty formats' => array(
- 'default' => array(
- array(
+ return [
+ 'empty formats' => [
+ 'default' => [
+ [
'type' => 0,
'flags' => 0,
'html' => '',
'cli' => '',
'function' => '',
- ),
- ),
- 'overriding' => array(
- array(
- ),
- ),
- 'expected' => array(
- array(
+ ],
+ ],
+ 'overriding' => [
+ [],
+ ],
+ 'expected' => [
+ [
'type' => 0,
'flags' => 0,
'html' => '',
'cli' => '',
'function' => '',
- ),
- ),
- ),
- 'no flags' => array(
- 'default' => array(
- array(
+ ],
+ ],
+ ],
+ 'no flags' => [
+ 'default' => [
+ [
'type' => 0,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 1,
'html' => 'html',
'cli' => 'cli',
- ),
- ),
- 'overriding' => array(
- array(
+ ],
+ ],
+ 'overriding' => [
+ [
'type' => 0,
'html' => 'new html',
'cli' => 'new cli',
- ),
- ),
- 'expected' => array(
- array(
+ ],
+ ],
+ 'expected' => [
+ [
'type' => 0,
'flags' => 0,
'html' => 'new html',
'cli' => 'new cli',
'function' => '',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 1,
'html' => 'html',
'cli' => 'cli',
- ),
- ),
- ),
- 'with flags' => array(
- 'default' => array(
- array(
+ ],
+ ],
+ ],
+ 'with flags' => [
+ 'default' => [
+ [
'type' => -1,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 1,
'html' => 'html',
'cli' => 'cli',
- ),
- ),
- 'overriding' => array(
- array(
+ ],
+ ],
+ 'overriding' => [
+ [
'type' => 0,
'flags' => 0,
'html' => 'new html',
'cli' => 'new cli',
- ),
- ),
- 'expected' => array(
- array(
+ ],
+ ],
+ 'expected' => [
+ [
'type' => -1,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 0,
'html' => 'new html',
'cli' => 'new cli',
'function' => '',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 1,
'html' => 'html',
'cli' => 'cli',
- ),
- ),
- ),
- 'with extra formats' => array(
- 'default' => array(
- array(
+ ],
+ ],
+ ],
+ 'with extra formats' => [
+ 'default' => [
+ [
'type' => 0,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- ),
- 'overriding' => array(
- array(
+ ],
+ ],
+ 'overriding' => [
+ [
'type' => 0,
'flags' => 1,
'html' => 'new html',
'cli' => 'new cli',
- ),
- array(
+ ],
+ [
'type' => 1,
'html' => 'new html',
'cli' => 'new cli',
- ),
- array(
+ ],
+ [
'type' => 1,
'flags' => 1,
'html' => 'new html',
'cli' => 'new cli',
- ),
- ),
- 'expected' => array(
- array(
+ ],
+ ],
+ 'expected' => [
+ [
'type' => 0,
'flags' => 0,
'html' => 'html',
'cli' => 'cli',
- ),
- array(
+ ],
+ [
'type' => 0,
'flags' => 1,
'html' => 'new html',
'cli' => 'new cli',
'function' => '',
- ),
- array(
+ ],
+ [
'type' => 1,
'flags' => 0,
'html' => 'new html',
'cli' => 'new cli',
'function' => '',
- ),
- array(
+ ],
+ [
'type' => 1,
'flags' => 1,
'html' => 'new html',
'cli' => 'new cli',
'function' => '',
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
}
/**
@@ -241,28 +240,28 @@ class FormatTest extends TestCase
* @param mixed $cli
* @param mixed $html
*/
- public function testFormat($query, $text, $cli, $html, array $options = array())
+ public function testFormat($query, $text, $cli, $html, array $options = [])
{
// Test TEXT format
- $this->assertEquals($text, Formatter::format($query, array('type' => 'text') + $options), 'Text formatting failed.');
+ $this->assertEquals($text, Formatter::format($query, ['type' => 'text'] + $options), 'Text formatting failed.');
// Test CLI format
- $this->assertEquals($cli, Formatter::format($query, array('type' => 'cli') + $options), 'CLI formatting failed.');
+ $this->assertEquals($cli, Formatter::format($query, ['type' => 'cli'] + $options), 'CLI formatting failed.');
// Test HTML format
- $this->assertEquals($html, Formatter::format($query, array('type' => 'html') + $options), 'HTML formatting failed.');
+ $this->assertEquals($html, Formatter::format($query, ['type' => 'html'] + $options), 'HTML formatting failed.');
}
public function formatQueries()
{
- return array(
- 'empty' => array(
+ return [
+ 'empty' => [
'query' => '',
'text' => '',
'cli' => "\x1b[0m",
'html' => '',
- ),
- 'minimal' => array(
+ ],
+ 'minimal' => [
'query' => 'select 1',
'text' => 'SELECT' . "\n" .
' 1',
@@ -270,8 +269,8 @@ class FormatTest extends TestCase
" \x1b[92m1" . "\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- ),
- 'simply' => array(
+ ],
+ 'simply' => [
'query' => 'select * from tbl where 1',
'text' => 'SELECT' . "\n" .
' *' . "\n" .
@@ -291,8 +290,8 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;tbl' . '<br/>' .
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- ),
- 'typical' => array(
+ ],
+ 'typical' => [
'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or id = 1 group by id order by id desc limit 1 offset 0',
'text' => 'SELECT' . "\n" .
' id,' . "\n" .
@@ -333,8 +332,8 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;id' . '<br/>' .
'<span class="sql-reserved">DESC</span>' . '<br/>' .
'<span class="sql-reserved">LIMIT</span> <span class="sql-number">1</span> <span class="sql-keyword">OFFSET</span> <span class="sql-number">0</span>',
- ),
- 'comments' => array(
+ ],
+ 'comments' => [
'query' => 'select /* Comment */ *' . "\n" .
'from tbl # Comment' . "\n" .
'where 1 -- Comment',
@@ -356,8 +355,8 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;tbl <span class="sql-comment"># Comment</span>' . '<br/>' .
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span> <span class="sql-comment">-- Comment</span>',
- ),
- 'strip comments' => array(
+ ],
+ 'strip comments' => [
'query' => 'select /* Comment */ *' . "\n" .
'from tbl # Comment' . "\n" .
'where 1 -- Comment',
@@ -379,11 +378,11 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;tbl' . '<br/>' .
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
- 'options' => array(
+ 'options' => [
'remove_comments' => true,
- ),
- ),
- 'keywords' => array(
+ ],
+ ],
+ 'keywords' => [
'query' => 'select hex("1")',
'text' => 'SELECT' . "\n" .
' HEX("1")',
@@ -391,8 +390,8 @@ class FormatTest extends TestCase
" \x1b[95mHEX\x1b[39m(\x1b[91m\"1\"\x1b[39m)" . "\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-keyword">HEX</span>(<span class="sql-string">"1"</span>)',
- ),
- 'distinct count' => array(
+ ],
+ 'distinct count' => [
'query' => 'select distinct count(*)',
'text' => 'SELECT DISTINCT' . "\n" .
' COUNT(*)',
@@ -400,8 +399,8 @@ class FormatTest extends TestCase
" \x1b[95mCOUNT\x1b[39m(*)" . "\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span> <span class="sql-reserved">DISTINCT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-keyword">COUNT</span>(*)',
- ),
- 'create procedure' => array(
+ ],
+ 'create procedure' => [
'query' => 'create procedure test_procedure() begin from tbl select *; end',
'text' => 'CREATE PROCEDURE test_procedure()' . "\n" .
'BEGIN' . "\n" .
@@ -424,8 +423,8 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*;' . '<br/>' .
'<span class="sql-keyword">END</span>',
- ),
- 'insert' => array(
+ ],
+ 'insert' => [
'query' => 'insert into foo values (0, 0, 0), (1, 1, 1)',
'text' => 'INSERT INTO foo' . "\n" .
'VALUES(0, 0, 0),(1, 1, 1)',
@@ -433,8 +432,8 @@ class FormatTest extends TestCase
"\x1b[35mVALUES\x1b[39m(\x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m),(\x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m)" . "\x1b[0m",
'html' => '<span class="sql-reserved">INSERT</span> <span class="sql-reserved">INTO</span> foo' . '<br/>' .
'<span class="sql-reserved">VALUES</span>(<span class="sql-number">0</span>, <span class="sql-number">0</span>, <span class="sql-number">0</span>),(<span class="sql-number">1</span>, <span class="sql-number">1</span>, <span class="sql-number">1</span>)',
- ),
- 'string as alias' => array(
+ ],
+ 'string as alias' => [
'query' => 'select "Text" as bar',
'text' => 'SELECT' . "\n" .
' "Text" AS bar',
@@ -442,8 +441,8 @@ class FormatTest extends TestCase
" \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar" . "\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">"Text"</span> <span class="sql-reserved">AS</span> bar',
- ),
- 'escape cli' => array(
+ ],
+ 'escape cli' => [
'query' => "select 'text\x1b[33mcolor-inj'",
'text' => 'SELECT' . "\n" .
" 'text\x1B[33mcolor-inj'",
@@ -451,8 +450,8 @@ class FormatTest extends TestCase
" \x1b[91m'text\\x1B[33mcolor-inj'" . "\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">\'text' . "\x1b[33m" . 'color-inj\'</span>',
- ),
- 'escape html' => array(
+ ],
+ 'escape html' => [
'query' => "select '<s>xss' from `<s>xss` , <s>nxss /*s<s>xss*/",
'text' => 'SELECT' . "\n" .
' \'<s>xss\'' . "\n" .
@@ -468,8 +467,8 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-string">\'&lt;s&gt;xss\'</span>' . '<br/>' .
'<span class="sql-reserved">FROM</span>' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`&lt;s&gt;xss`</span>,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt; s &gt; nxss <span class="sql-comment">/*s&lt;s&gt;xss*/</span>',
- ),
- 'create table' => array(
+ ],
+ 'create table' => [
'query' => 'create table if not exists `pma__bookmark` (' . "\n" .
'`id` int(11) not null auto_increment,' . "\n" .
'`dbase` varchar(255) not null default "",' . "\n" .
@@ -498,14 +497,14 @@ class FormatTest extends TestCase
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`label`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">COLLATE</span> utf8_general_ci <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,' . '<br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">PRIMARY KEY</span>(<span class="sql-variable">`id`</span>)',
- ),
- 'join' => array(
+ ],
+ 'join' => [
'query' => 'join tbl2 on c1=c2',
'text' => 'JOIN tbl2 ON c1 = c2',
'cli' => "\x1b[35mJOIN \x1b[39mtbl2 \x1b[35mON \x1b[39mc1 = c2" .
"\x1b[0m",
'html' => '<span class="sql-reserved">JOIN</span> tbl2 <span class="sql-reserved">ON</span> c1 = c2',
- ),
- );
+ ],
+ ];
}
}
diff --git a/tests/Utils/MiscTest.php b/tests/Utils/MiscTest.php
index c6b03a2..01a2926 100644
--- a/tests/Utils/MiscTest.php
+++ b/tests/Utils/MiscTest.php
@@ -24,104 +24,104 @@ class MiscTest extends TestCase
public function getAliasesProvider()
{
- return array(
- array(
+ return [
+ [
'select * from (select 1) tbl',
'mydb',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'select i.name as `n`,abcdef gh from qwerty i',
'mydb',
- array(
- 'mydb' => array(
+ [
+ 'mydb' => [
'alias' => null,
- 'tables' => array(
- 'qwerty' => array(
+ 'tables' => [
+ 'qwerty' => [
'alias' => 'i',
- 'columns' => array(
+ 'columns' => [
'name' => 'n',
'abcdef' => 'gh',
- ),
- ),
- ),
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ [
'select film_id id,title from film',
'sakila',
- array(
- 'sakila' => array(
+ [
+ 'sakila' => [
'alias' => null,
- 'tables' => array(
- 'film' => array(
+ 'tables' => [
+ 'film' => [
'alias' => null,
- 'columns' => array(
+ 'columns' => [
'film_id' => 'id',
- ),
- ),
- ),
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ [
'select `sakila`.`A`.`actor_id` as aid,`F`.`film_id` `fid`,'
. 'last_update updated from `sakila`.actor A join `film_actor` as '
. '`F` on F.actor_id = A.`actor_id`',
'sakila',
- array(
- 'sakila' => array(
+ [
+ 'sakila' => [
'alias' => null,
- 'tables' => array(
- 'film_actor' => array(
+ 'tables' => [
+ 'film_actor' => [
'alias' => 'F',
- 'columns' => array(
+ 'columns' => [
'film_id' => 'fid',
'last_update' => 'updated',
- ),
- ),
- 'actor' => array(
+ ],
+ ],
+ 'actor' => [
'alias' => 'A',
- 'columns' => array(
+ 'columns' => [
'actor_id' => 'aid',
'last_update' => 'updated',
- ),
- ),
- ),
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ [
'SELECT film_id FROM (SELECT * FROM film) as f;',
'sakila',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'',
null,
- array(),
- ),
- array(
+ [],
+ ],
+ [
'SELECT 1',
null,
- array(),
- ),
- array(
+ [],
+ ],
+ [
'SELECT * FROM orders AS ord WHERE 1',
'db',
- array(
- 'db' => array(
+ [
+ 'db' => [
'alias' => null,
- 'tables' => array(
- 'orders' => array(
+ 'tables' => [
+ 'orders' => [
'alias' => 'ord',
- 'columns' => array(),
- ),
- ),
- ),
- ),
- ),
- );
+ 'columns' => [],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php
index 8cb9f85..6991870 100644
--- a/tests/Utils/QueryTest.php
+++ b/tests/Utils/QueryTest.php
@@ -25,257 +25,257 @@ class QueryTest extends TestCase
public function testGetFlagsProvider()
{
- return array(
- array(
+ return [
+ [
'ALTER TABLE DROP col',
- array(
+ [
'reload' => true,
'querytype' => 'ALTER',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CALL test()',
- array(
+ [
'is_procedure' => true,
'querytype' => 'CALL',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CREATE TABLE tbl (id INT)',
- array(
+ [
'reload' => true,
'querytype' => 'CREATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECK TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECK',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DELETE FROM tbl',
- array(
+ [
'is_affected' => true,
'is_delete' => true,
'querytype' => 'DELETE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP VIEW v',
- array(
+ [
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'DROP DATABASE db',
- array(
+ [
'drop_database' => true,
'reload' => true,
'querytype' => 'DROP',
- ),
- ),
- array(
+ ],
+ ],
+ [
'EXPLAIN tbl',
- array(
+ [
'is_explain' => true,
'querytype' => 'EXPLAIN',
- ),
- ),
- array(
+ ],
+ ],
+ [
'LOAD DATA INFILE \'/tmp/test.txt\' INTO TABLE test',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'LOAD',
- ),
- ),
- array(
+ ],
+ ],
+ [
'INSERT INTO tbl VALUES (1)',
- array(
+ [
'is_affected' => true,
'is_insert' => true,
'querytype' => 'INSERT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPLACE INTO tbl VALUES (2)',
- array(
+ [
'is_affected' => true,
'is_replace' => true,
'is_insert' => true,
'querytype' => 'REPLACE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT 1',
- array(
+ [
'is_select' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl',
- array(
+ [
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT DISTINCT * FROM tbl LIMIT 0, 10 ORDER BY id',
- array(
+ [
'distinct' => true,
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM actor GROUP BY actor_id',
- array(
+ [
'is_group' => true,
'is_select' => true,
'select_from' => true,
'group' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);',
- array(
+ [
'is_analyse' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"',
- array(
+ [
'is_export' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT COUNT(id), SUM(id) FROM tbl',
- array(
+ [
'is_count' => true,
'is_func' => true,
'is_select' => true,
'select_from' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT (SELECT "foo")',
- array(
+ [
'is_select' => true,
'is_subquery' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM customer HAVING store_id = 2;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'is_group' => true,
'having' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;',
- array(
+ [
'is_select' => true,
'select_from' => true,
'join' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SHOW CREATE TABLE tbl',
- array(
+ [
'is_show' => true,
'querytype' => 'SHOW',
- ),
- ),
- array(
+ ],
+ ],
+ [
'UPDATE tbl SET id = 1',
- array(
+ [
'is_affected' => true,
'querytype' => 'UPDATE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'ANALYZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'ANALYZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'CHECKSUM TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'CHECKSUM',
- ),
- ),
- array(
+ ],
+ ],
+ [
'OPTIMIZE TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'OPTIMIZE',
- ),
- ),
- array(
+ ],
+ ],
+ [
'REPAIR TABLE tbl',
- array(
+ [
'is_maint' => true,
'querytype' => 'REPAIR',
- ),
- ),
- array(
+ ],
+ ],
+ [
'(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) ' .
'UNION ' .
'(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);',
- array(
+ [
'is_select' => true,
'select_from' => true,
'limit' => true,
'order' => true,
'union' => true,
'querytype' => 'SELECT',
- ),
- ),
- array(
+ ],
+ ],
+ [
'SELECT * FROM orders AS ord WHERE 1',
- array(
+ [
'querytype' => 'SELECT',
'is_select' => true,
'select_from' => true,
- ),
- ),
- array(
+ ],
+ ],
+ [
'SET NAMES \'latin\'',
- array(
+ [
'querytype' => 'SET',
- ),
- ),
- );
+ ],
+ ],
+ ];
}
public function testGetAll()
{
$this->assertEquals(
- array(
+ [
'distinct' => false,
'drop_database' => false,
'group' => false,
@@ -303,7 +303,7 @@ class QueryTest extends TestCase
'reload' => false,
'select_from' => false,
'union' => false,
- ),
+ ],
Query::getAll('')
);
@@ -313,15 +313,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array('actor', null),
- array('film', 'sakila2'),
- ),
- )
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
+ 'actor',
+ null,
+ ],
+ [
+ 'film',
+ 'sakila2',
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -331,15 +337,21 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array('*'),
- 'select_tables' => array(
- array('actor', 'sakila'),
- array('film', null),
- ),
- )
+ 'select_expr' => ['*'],
+ 'select_tables' => [
+ [
+ 'actor',
+ 'sakila',
+ ],
+ [
+ 'film',
+ null,
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -349,14 +361,17 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(),
- 'select_tables' => array(
- array('actor', 'sakila'),
- ),
- )
+ 'select_expr' => [],
+ 'select_tables' => [
+ [
+ 'actor',
+ 'sakila',
+ ],
+ ],
+ ]
),
Query::getAll($query)
);
@@ -366,14 +381,14 @@ class QueryTest extends TestCase
$this->assertEquals(
array_merge(
Query::getFlags($parser->statements[0], true),
- array(
+ [
'parser' => $parser,
'statement' => $parser->statements[0],
- 'select_expr' => array(
+ 'select_expr' => [
'CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END',
- ),
- 'select_tables' => array(),
- )
+ ],
+ 'select_tables' => [],
+ ]
),
Query::getAll($query)
);
@@ -396,36 +411,42 @@ class QueryTest extends TestCase
public function testGetTablesProvider()
{
- return array(
- array(
+ return [
+ [
'INSERT INTO tbl(`id`, `name`) VALUES (1, "Name")',
- array('`tbl`'),
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'UPDATE tbl SET id = 0',
- array('`tbl`'),
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DELETE FROM tbl WHERE id < 10',
- array('`tbl`'),
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'TRUNCATE tbl',
- array('`tbl`'),
- ),
- array(
+ ['`tbl`'],
+ ],
+ [
'DROP VIEW v',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'DROP TABLE tbl1, tbl2',
- array('`tbl1`', '`tbl2`'),
- ),
- array(
+ [
+ '`tbl1`',
+ '`tbl2`',
+ ],
+ ],
+ [
'RENAME TABLE a TO b, c TO d',
- array('`a`', '`c`'),
- ),
- );
+ [
+ '`a`',
+ '`c`',
+ ],
+ ],
+ ];
}
public function testGetClause()
@@ -494,7 +515,7 @@ class QueryTest extends TestCase
public function testReplaceClauses()
{
- $this->assertEquals('', Query::replaceClauses(null, null, array()));
+ $this->assertEquals('', Query::replaceClauses(null, null, []));
$parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;');
$this->assertEquals(
@@ -502,9 +523,12 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array('WHERE', 'WHERE film_id > 0'),
- )
+ [
+ [
+ 'WHERE',
+ 'WHERE film_id > 0',
+ ],
+ ]
)
);
@@ -525,11 +549,20 @@ class QueryTest extends TestCase
Query::replaceClauses(
$parser->statements[0],
$parser->list,
- array(
- array('FROM', 'FROM city AS c'),
- array('WHERE', ''),
- array('LIMIT', 'LIMIT 0, 10'),
- )
+ [
+ [
+ 'FROM',
+ 'FROM city AS c',
+ ],
+ [
+ 'WHERE',
+ '',
+ ],
+ [
+ 'LIMIT',
+ 'LIMIT 0, 10',
+ ],
+ ]
)
);
}
diff --git a/tests/Utils/RoutineTest.php b/tests/Utils/RoutineTest.php
index 3a6ba55..9a7c4ca 100644
--- a/tests/Utils/RoutineTest.php
+++ b/tests/Utils/RoutineTest.php
@@ -20,33 +20,88 @@ class RoutineTest extends TestCase
public function getReturnTypeProvider()
{
- return array(
- array('', array('', '', '', '', '')),
- array('TEXT', array('', '', 'TEXT', '', '')),
- array('INT(20)', array('', '', 'INT', '20', '')),
- array(
+ return [
+ [
+ '',
+ [
+ '',
+ '',
+ '',
+ '',
+ '',
+ ],
+ ],
+ [
+ 'TEXT',
+ [
+ '',
+ '',
+ 'TEXT',
+ '',
+ '',
+ ],
+ ],
+ [
+ 'INT(20)',
+ [
+ '',
+ '',
+ 'INT',
+ '20',
+ '',
+ ],
+ ],
+ [
'INT UNSIGNED',
- array('', '', 'INT', '', 'UNSIGNED'),
- ),
- array(
+ [
+ '',
+ '',
+ 'INT',
+ '',
+ 'UNSIGNED',
+ ],
+ ],
+ [
'VARCHAR(1) CHARSET utf8',
- array('', '', 'VARCHAR', '1', 'utf8'),
- ),
- array(
+ [
+ '',
+ '',
+ 'VARCHAR',
+ '1',
+ 'utf8',
+ ],
+ ],
+ [
'ENUM(\'a\', \'b\') CHARSET latin1',
- array('', '', 'ENUM', '\'a\',\'b\'', 'latin1'),
- ),
- array(
+ [
+ '',
+ '',
+ 'ENUM',
+ '\'a\',\'b\'',
+ 'latin1',
+ ],
+ ],
+ [
'DECIMAL(5,2) UNSIGNED ZEROFILL',
- array('', '', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL'),
- ),
- array(
+ [
+ '',
+ '',
+ 'DECIMAL',
+ '5,2',
+ 'UNSIGNED ZEROFILL',
+ ],
+ ],
+ [
'SET(\'test\'\'esc"\', \'more\\\'esc\')',
- array(
- '', '', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '',
- ),
- ),
- );
+ [
+ '',
+ '',
+ 'SET',
+ '\'test\'\'esc"\',\'more\\\'esc\'',
+ '',
+ ],
+ ],
+ ];
}
/**
@@ -61,33 +116,88 @@ class RoutineTest extends TestCase
public function getParameterProvider()
{
- return array(
- array('', array('', '', '', '', '')),
- array('`foo` TEXT', array('', 'foo', 'TEXT', '', '')),
- array('`foo` INT(20)', array('', 'foo', 'INT', '20', '')),
- array(
+ return [
+ [
+ '',
+ [
+ '',
+ '',
+ '',
+ '',
+ '',
+ ],
+ ],
+ [
+ '`foo` TEXT',
+ [
+ '',
+ 'foo',
+ 'TEXT',
+ '',
+ '',
+ ],
+ ],
+ [
+ '`foo` INT(20)',
+ [
+ '',
+ 'foo',
+ 'INT',
+ '20',
+ '',
+ ],
+ ],
+ [
'IN `fo``fo` INT UNSIGNED',
- array('IN', 'fo`fo', 'INT', '', 'UNSIGNED'),
- ),
- array(
+ [
+ 'IN',
+ 'fo`fo',
+ 'INT',
+ '',
+ 'UNSIGNED',
+ ],
+ ],
+ [
'OUT bar VARCHAR(1) CHARSET utf8',
- array('OUT', 'bar', 'VARCHAR', '1', 'utf8'),
- ),
- array(
+ [
+ 'OUT',
+ 'bar',
+ 'VARCHAR',
+ '1',
+ 'utf8',
+ ],
+ ],
+ [
'`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1',
- array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1'),
- ),
- array(
+ [
+ '',
+ '"baz\'\'',
+ 'ENUM',
+ '\'a\',\'b\'',
+ 'latin1',
+ ],
+ ],
+ [
'INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL',
- array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL'),
- ),
- array(
+ [
+ 'INOUT',
+ 'foo',
+ 'DECIMAL',
+ '5,2',
+ 'UNSIGNED ZEROFILL',
+ ],
+ ],
+ [
'`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')',
- array(
- '', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '',
- ),
- ),
- );
+ [
+ '',
+ 'foo`s func',
+ 'SET',
+ '\'test\'\'esc"\',\'more\\\'esc\'',
+ '',
+ ],
+ ],
+ ];
}
/**
@@ -103,98 +213,98 @@ class RoutineTest extends TestCase
public function getParametersProvider()
{
- return array(
- array(
+ return [
+ [
'CREATE PROCEDURE `foo`() SET @A=0',
- array(
+ [
'num' => 0,
- 'dir' => array(),
- 'name' => array(),
- 'type' => array(),
- 'length' => array(),
- 'length_arr' => array(),
- 'opts' => array(),
- ),
- ),
- array(
+ 'dir' => [],
+ 'name' => [],
+ 'type' => [],
+ 'length' => [],
+ 'length_arr' => [],
+ 'opts' => [],
+ ],
+ ],
+ [
'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
- array(
+ [
'num' => 1,
- 'dir' => array(
+ 'dir' => [
0 => '',
- ),
- 'name' => array(
+ ],
+ 'name' => [
0 => 'baz',
- ),
- 'type' => array(
+ ],
+ 'type' => [
0 => 'INT',
- ),
- 'length' => array(
+ ],
+ 'length' => [
0 => '',
- ),
- 'length_arr' => array(
- 0 => array(),
- ),
- 'opts' => array(
+ ],
+ 'length_arr' => [
+ 0 => [],
+ ],
+ 'opts' => [
0 => '',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
- array(
+ [
'num' => 1,
- 'dir' => array(
+ 'dir' => [
0 => 'IN',
- ),
- 'name' => array(
+ ],
+ 'name' => [
0 => 'baz\\)',
- ),
- 'type' => array(
+ ],
+ 'type' => [
0 => 'INT',
- ),
- 'length' => array(
+ ],
+ 'length' => [
0 => '25',
- ),
- 'length_arr' => array(
- 0 => array('25'),
- ),
- 'opts' => array(
+ ],
+ 'length_arr' => [
+ 0 => ['25'],
+ ],
+ 'opts' => [
0 => 'UNSIGNED ZEROFILL',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' .
'BEGIN SELECT NULL; END',
- array(
+ [
'num' => 2,
- 'dir' => array(
+ 'dir' => [
0 => 'IN',
1 => 'OUT',
- ),
- 'name' => array(
+ ],
+ 'name' => [
0 => 'baz\\',
1 => 'bazz',
- ),
- 'type' => array(
+ ],
+ 'type' => [
0 => 'INT',
1 => 'VARCHAR',
- ),
- 'length' => array(
+ ],
+ 'length' => [
0 => '1',
1 => '15',
- ),
- 'length_arr' => array(
- 0 => array('1'),
- 1 => array('15'),
- ),
- 'opts' => array(
+ ],
+ 'length_arr' => [
+ 0 => ['1'],
+ 1 => ['15'],
+ ],
+ 'opts' => [
0 => 'ZEROFILL',
1 => 'utf8',
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/TableTest.php b/tests/Utils/TableTest.php
index ef21137..fe68100 100644
--- a/tests/Utils/TableTest.php
+++ b/tests/Utils/TableTest.php
@@ -21,12 +21,12 @@ class TableTest extends TestCase
public function getForeignKeysProvider()
{
- return array(
- array(
+ return [
+ [
'CREATE USER test',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'CREATE TABLE `payment` (
`payment_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` smallint(5) unsigned NOT NULL,
@@ -43,35 +43,35 @@ class TableTest extends TestCase
CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`) REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=16050 DEFAULT CHARSET=utf8',
- array(
- array(
+ [
+ [
'constraint' => 'fk_payment_customer',
- 'index_list' => array('customer_id'),
+ 'index_list' => ['customer_id'],
'ref_db_name' => null,
'ref_table_name' => 'customer',
- 'ref_index_list' => array('customer_id'),
+ 'ref_index_list' => ['customer_id'],
'on_update' => 'CASCADE',
- ),
- array(
+ ],
+ [
'constraint' => 'fk_payment_rental',
- 'index_list' => array('rental_id'),
+ 'index_list' => ['rental_id'],
'ref_db_name' => null,
'ref_table_name' => 'rental',
- 'ref_index_list' => array('rental_id'),
+ 'ref_index_list' => ['rental_id'],
'on_delete' => 'SET_NULL',
'on_update' => 'CASCADE',
- ),
- array(
+ ],
+ [
'constraint' => 'fk_payment_staff',
- 'index_list' => array('staff_id'),
+ 'index_list' => ['staff_id'],
'ref_db_name' => null,
'ref_table_name' => 'staff',
- 'ref_index_list' => array('staff_id'),
+ 'ref_index_list' => ['staff_id'],
'on_update' => 'CASCADE',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE TABLE `actor` (
`actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(45) NOT NULL,
@@ -80,9 +80,9 @@ class TableTest extends TestCase
PRIMARY KEY (`actor_id`),
KEY `idx_actor_last_name` (`last_name`)
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'CREATE TABLE `address` (
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`address` varchar(50) NOT NULL,
@@ -96,18 +96,18 @@ class TableTest extends TestCase
KEY `idx_fk_city_id` (`city_id`),
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
- array(
- array(
+ [
+ [
'constraint' => 'fk_address_city',
- 'index_list' => array('city_id'),
+ 'index_list' => ['city_id'],
'ref_db_name' => null,
'ref_table_name' => 'city',
- 'ref_index_list' => array('city_id'),
+ 'ref_index_list' => ['city_id'],
'on_update' => 'CASCADE',
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
}
/**
@@ -123,12 +123,12 @@ class TableTest extends TestCase
public function getFieldsProvider()
{
- return array(
- array(
+ return [
+ [
'CREATE USER test',
- array(),
- ),
- array(
+ [],
+ ],
+ [
'CREATE TABLE `address` (
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`address` varchar(50) NOT NULL,
@@ -142,76 +142,76 @@ class TableTest extends TestCase
KEY `idx_fk_city_id` (`city_id`),
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
- array(
- 'address_id' => array(
+ [
+ 'address_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
- ),
- 'address' => array(
+ ],
+ 'address' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
- ),
- 'address2' => array(
+ ],
+ 'address2' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
- ),
- 'district' => array(
+ ],
+ 'district' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
- ),
- 'city_id' => array(
+ ],
+ 'city_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
- ),
- 'postal_code' => array(
+ ],
+ 'postal_code' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
- ),
- 'phone' => array(
+ ],
+ 'phone' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
- ),
- 'last_update' => array(
+ ],
+ 'last_update' => [
'type' => 'TIMESTAMP',
'timestamp_not_null' => true,
'default_value' => 'CURRENT_TIMESTAMP',
'default_current_timestamp' => true,
'on_update_current_timestamp' => true,
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'CREATE TABLE table1 (
a INT NOT NULL,
b VARCHAR(32),
c INT AS (a mod 10) VIRTUAL,
d VARCHAR(5) AS (left(b,5)) PERSISTENT
)',
- array(
- 'a' => array(
+ [
+ 'a' => [
'type' => 'INT',
'timestamp_not_null' => false,
- ),
- 'b' => array(
+ ],
+ 'b' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
- ),
- 'c' => array(
+ ],
+ 'c' => [
'type' => 'INT',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(a mod 10)',
- ),
- 'd' => array(
+ ],
+ 'd' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(left(b,5))',
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
}
}
diff --git a/tests/Utils/TokensTest.php b/tests/Utils/TokensTest.php
index 5e268ec..533021c 100644
--- a/tests/Utils/TokensTest.php
+++ b/tests/Utils/TokensTest.php
@@ -23,20 +23,20 @@ class TokensTest extends TestCase
public function replaceTokensProvider()
{
- return array(
- array(
+ return [
+ [
'SELECT * FROM /*x*/a/*c*/.b',
- array(
- array('value_str' => 'a'),
- array('token' => '.'),
- ),
- array(
+ [
+ ['value_str' => 'a'],
+ ['token' => '.'],
+ ],
+ [
new Token('c'),
new Token('.'),
- ),
+ ],
'SELECT * FROM /*x*/c.b',
- ),
- );
+ ],
+ ];
}
/**
@@ -53,60 +53,64 @@ class TokensTest extends TestCase
public function matchProvider()
{
- return array(
- array(new Token(''), array(), true),
+ return [
+ [
+ new Token(''),
+ [],
+ true,
+ ],
- array(
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('token' => '"abc"'),
+ ['token' => '"abc"'],
true,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('value' => 'abc'),
+ ['value' => 'abc'],
true,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('value_str' => 'ABC'),
+ ['value_str' => 'ABC'],
true,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('type' => Token::TYPE_STRING),
+ ['type' => Token::TYPE_STRING],
true,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('flags' => Token::FLAG_STRING_DOUBLE_QUOTES),
+ ['flags' => Token::FLAG_STRING_DOUBLE_QUOTES],
true,
- ),
+ ],
- array(
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('token' => '"abcd"'),
+ ['token' => '"abcd"'],
false,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('value' => 'abcd'),
+ ['value' => 'abcd'],
false,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('value_str' => 'ABCd'),
+ ['value_str' => 'ABCd'],
false,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('type' => Token::TYPE_NUMBER),
+ ['type' => Token::TYPE_NUMBER],
false,
- ),
- array(
+ ],
+ [
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
- array('flags' => Token::FLAG_STRING_SINGLE_QUOTES),
+ ['flags' => Token::FLAG_STRING_SINGLE_QUOTES],
false,
- ),
- );
+ ],
+ ];
}
}
diff --git a/tools/ContextGenerator.php b/tools/ContextGenerator.php
index 503c0e9..5c6b747 100644
--- a/tools/ContextGenerator.php
+++ b/tools/ContextGenerator.php
@@ -18,19 +18,19 @@ class ContextGenerator
*
* @var array
*/
- public static $LABELS_FLAGS = array(
+ public static $LABELS_FLAGS = [
'(R)' => 2, // reserved
'(D)' => 8, // data type
'(K)' => 16, // keyword
'(F)' => 32, // function name
- );
+ ];
/**
* Documentation links for each context.
*
* @var array
*/
- public static $LINKS = array(
+ public static $LINKS = [
'MySql50000' => 'https://dev.mysql.com/doc/refman/5.0/en/keywords.html',
'MySql50100' => 'https://dev.mysql.com/doc/refman/5.1/en/keywords.html',
'MySql50500' => 'https://dev.mysql.com/doc/refman/5.5/en/keywords.html',
@@ -41,7 +41,7 @@ class ContextGenerator
'MariaDb100100' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
'MariaDb100200' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
'MariaDb100300' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
- );
+ ];
/**
* The template of a context.
@@ -124,12 +124,12 @@ class ContextGenerator
*/
public static function readWords(array $files)
{
- $words = array();
+ $words = [];
foreach ($files as $file) {
$words = array_merge($words, file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
}
- $types = array();
+ $types = [];
for ($i = 0, $count = count($words); $i !== $count; ++$i) {
$type = 1;
@@ -155,21 +155,21 @@ class ContextGenerator
}
$value = strtoupper($value);
- if (!isset($types[$value])) {
+ if (! isset($types[$value])) {
$types[$value] = $type;
} else {
$types[$value] |= $type;
}
}
- $ret = array();
+ $ret = [];
foreach ($types as $word => $type) {
$len = strlen($word);
- if (!isset($ret[$type])) {
- $ret[$type] = array();
+ if (! isset($ret[$type])) {
+ $ret[$type] = [];
}
- if (!isset($ret[$type][$len])) {
- $ret[$type][$len] = array();
+ if (! isset($ret[$type][$len])) {
+ $ret[$type][$len] = [];
}
$ret[$type][$len][] = $word;
}
@@ -254,7 +254,7 @@ class ContextGenerator
public static function formatName($name)
{
/* Split name and version */
- $parts = array();
+ $parts = [];
if (preg_match('/([^[0-9]*)([0-9]*)/', $name, $parts) === false) {
return $name;
}
@@ -334,18 +334,18 @@ class ContextGenerator
file_put_contents(
$output . '/' . $class . '.php',
static::generate(
- array(
+ [
'name' => $formattedName,
'class' => $class,
'link' => static::$LINKS[$name],
'keywords' => static::readWords(
- array(
+ [
$directory . '_common.txt',
$directory . '_functions' . $file,
$directory . $file,
- )
+ ]
),
- )
+ ]
)
);
}
@@ -389,9 +389,9 @@ if (count($argv) >= 3) {
$output = rtrim($argv[2], '/');
// Checking if all directories are valid.
- if (!is_dir($input)) {
+ if (! is_dir($input)) {
throw new \Exception('The input directory does not exist.');
- } elseif (!is_dir($output)) {
+ } elseif (! is_dir($output)) {
throw new \Exception('The output directory does not exist.');
}
diff --git a/tools/TestGenerator.php b/tools/TestGenerator.php
index 7598af3..599387f 100644
--- a/tools/TestGenerator.php
+++ b/tools/TestGenerator.php
@@ -46,14 +46,14 @@ class TestGenerator
*
* @var array
*/
- $lexerErrors = array();
+ $lexerErrors = [];
/**
* Parser's errors.
*
* @var array
*/
- $parserErrors = array();
+ $parserErrors = [];
// Both the lexer and the parser construct exception for errors.
// Usually, exceptions contain a full stack trace and other details that
@@ -61,30 +61,39 @@ class TestGenerator
// The code below extracts only the relevant information.
// Extracting lexer's errors.
- if (!empty($lexer->errors)) {
+ if (! empty($lexer->errors)) {
foreach ($lexer->errors as $err) {
- $lexerErrors[] = array($err->getMessage(), $err->ch, $err->pos, $err->getCode());
+ $lexerErrors[] = [
+ $err->getMessage(),
+ $err->ch,
+ $err->pos,
+ $err->getCode(),
+ ];
}
- $lexer->errors = array();
+ $lexer->errors = [];
}
// Extracting parser's errors.
- if (!empty($parser->errors)) {
+ if (! empty($parser->errors)) {
foreach ($parser->errors as $err) {
- $parserErrors[] = array($err->getMessage(), $err->token, $err->getCode());
+ $parserErrors[] = [
+ $err->getMessage(),
+ $err->token,
+ $err->getCode(),
+ ];
}
- $parser->errors = array();
+ $parser->errors = [];
}
- return array(
+ return [
'query' => $query,
'lexer' => $lexer,
'parser' => $parser,
- 'errors' => array(
+ 'errors' => [
'lexer' => $lexerErrors,
'parser' => $parserErrors,
- ),
- );
+ ],
+ ];
}
/**
@@ -100,7 +109,7 @@ class TestGenerator
public static function build($type, $input, $output, $debug = null)
{
// Support query types: `lexer` / `parser`.
- if (!in_array($type, array('lexer', 'parser'))) {
+ if (! in_array($type, ['lexer', 'parser'])) {
throw new \Exception('Unknown test type (expected `lexer` or `parser`).');
}
@@ -122,7 +131,7 @@ class TestGenerator
file_put_contents($output, serialize($test));
// Dumping test's data in human readable format too (if required).
- if (!empty($debug)) {
+ if (! empty($debug)) {
file_put_contents($debug, print_r($test, true));
}
}
@@ -152,10 +161,10 @@ class TestGenerator
if (is_dir($inputFile)) {
// Creating required directories to maintain the structure.
// Ignoring errors if the folder structure exists already.
- if (!is_dir($outputFile)) {
+ if (! is_dir($outputFile)) {
mkdir($outputFile);
}
- if (($debug !== null) && (!is_dir($debugFile))) {
+ if (($debug !== null) && (! is_dir($debugFile))) {
mkdir($debugFile);
}
@@ -170,7 +179,7 @@ class TestGenerator
}
// Building the test.
- if (!file_exists($outputFile)) {
+ if (! file_exists($outputFile)) {
sprintf("Building test for %s...\n", $inputFile);
static::build(
strpos($inputFile, 'lex') !== false ? 'lexer' : 'parser',
@@ -203,11 +212,11 @@ if (count($argv) >= 3) {
$debug = empty($argv[3]) ? null : rtrim($argv[3], '/');
// Checking if all directories are valid.
- if (!is_dir($input)) {
+ if (! is_dir($input)) {
throw new \Exception('The input directory does not exist.');
- } elseif (!is_dir($output)) {
+ } elseif (! is_dir($output)) {
throw new \Exception('The output directory does not exist.');
- } elseif (($debug !== null) && (!is_dir($debug))) {
+ } elseif (($debug !== null) && (! is_dir($debug))) {
throw new \Exception('The debug directory does not exist.');
}