diff options
Diffstat (limited to 'src')
84 files changed, 1065 insertions, 1064 deletions
diff --git a/src/Component.php b/src/Component.php index bb230c2..520735b 100644 --- a/src/Component.php +++ b/src/Component.php @@ -1,5 +1,4 @@ <?php - /** * Defines a component that is later extended to parse specialized components or * keywords. @@ -8,6 +7,7 @@ * *Component parsers can be reused in multiple situations and *Keyword parsers * count on the *Component classes to do their job. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -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 b3f8e26..2540521 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -1,8 +1,8 @@ <?php - /** * Parses an alter operation. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -25,67 +25,67 @@ class AlterOperation extends Component * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array( + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ 1, - 'var' - ), - 'CHARSET' => array( + 'var', + ], + 'CHARSET' => [ 1, - 'var' - ), - 'DEFAULT CHARACTER SET' => array( + 'var', + ], + 'DEFAULT CHARACTER SET' => [ 1, - 'var' - ), - 'DEFAULT CHARSET' => array( + 'var', + ], + 'DEFAULT CHARSET' => [ 1, - 'var' - ), - 'UPGRADE' => array( + 'var', + ], + 'UPGRADE' => [ 1, - 'var' - ), - 'COLLATE' => array( + 'var', + ], + 'COLLATE' => [ 2, - 'var' - ), - 'DEFAULT COLLATE' => array( + 'var', + ], + 'DEFAULT COLLATE' => [ 2, - 'var' - ) - ); + 'var', + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array( + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ 1, - 'var=' - ), - 'AUTO_INCREMENT' => array( + 'var=', + ], + 'AUTO_INCREMENT' => [ 1, - 'var=' - ), - 'AVG_ROW_LENGTH' => array( + 'var=', + ], + 'AVG_ROW_LENGTH' => [ 1, - 'var' - ), - 'MAX_ROWS' => array( + 'var', + ], + 'MAX_ROWS' => [ 1, - 'var' - ), - 'ROW_FORMAT' => array( + 'var', + ], + 'ROW_FORMAT' => [ 1, - 'var' - ), - 'COMMENT' => array( + 'var', + ], + 'COMMENT' => [ 1, - 'var' - ), + 'var', + ], 'ADD' => 1, 'ALTER' => 1, 'ANALYZE' => 1, @@ -122,17 +122,17 @@ class AlterOperation extends Component 'PRIMARY KEY' => 2, 'SPATIAL' => 2, 'TABLESPACE' => 2, - 'INDEX' => 2 - ); + 'INDEX' => 2, + ]; /** * All view options. * * @var array */ - public static $VIEW_OPTIONS = array( + public static $VIEW_OPTIONS = [ 'AS' => 1, - ); + ]; /** * Options of this operation. @@ -153,7 +153,7 @@ class AlterOperation extends Component * * @var Token[]|string */ - public $unknown = array(); + public $unknown = []; /** * Constructor. @@ -165,7 +165,7 @@ class AlterOperation extends Component public function __construct( $options = null, $field = null, - $unknown = array() + $unknown = [] ) { $this->options = $options; $this->field = $field; @@ -179,9 +179,9 @@ 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(); + $ret = new static(); /** * Counts brackets. @@ -251,10 +251,10 @@ class AlterOperation extends Component $ret->field = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - 'parseField' => 'column' - ) + 'parseField' => 'column', + ] ); if ($ret->field === null) { // No field was read. We go back one token so the next @@ -315,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 !== '')) { @@ -334,13 +334,13 @@ class AlterOperation extends Component */ private static function checkIfColumnDefinitionKeyword($tokenValue) { - $common_options = array( + $common_options = [ 'AUTO_INCREMENT', 'COMMENT', 'DEFAULT', 'CHARACTER SET', - 'COLLATE' - ); + 'COLLATE', + ]; // Since these options 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..7c99952 100644 --- a/src/Components/Array2d.php +++ b/src/Components/Array2d.php @@ -1,8 +1,8 @@ <?php - /** * `VALUES` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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 2b2fe92..6b90a3f 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -1,8 +1,8 @@ <?php - /** * Parses an array. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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 static() : []; /** * 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,7 +176,7 @@ 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); diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php index f6b422c..4bd347d 100644 --- a/src/Components/CaseExpression.php +++ b/src/Components/CaseExpression.php @@ -1,8 +1,8 @@ <?php - /** * Parses a reference to a CASE expression. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -33,21 +33,21 @@ class CaseExpression extends Component * * @var array */ - public $conditions = array(); + public $conditions = []; /** * The results matching with the WHEN clauses. * * @var array */ - public $results = array(); + public $results = []; /** * The values to be compared against. * * @var array */ - public $compare_values = array(); + public $compare_values = []; /** * The result in ELSE section of expr. @@ -84,9 +84,9 @@ 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(); + $ret = new static(); /** * State of parser. @@ -216,7 +216,7 @@ class CaseExpression extends Component if ($token->type === Token::TYPE_DELIMITER) { break; } - + // Skipping whitespaces and comments. if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT) @@ -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 700b071..4ad9864 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -1,8 +1,8 @@ <?php - /** * `WHERE` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -25,20 +25,20 @@ class Condition extends Component * * @var array */ - public static $DELIMITERS = array( + public static $DELIMITERS = [ '&&', '||', 'AND', 'OR', - 'XOR' - ); + '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, @@ -56,15 +56,15 @@ class Condition extends Component 'OR' => 1, 'REGEXP' => 1, 'RLIKE' => 1, - 'XOR' => 1 - ); + 'XOR' => 1, + ]; /** * Identifiers recognized. * * @var array */ - public $identifiers = array(); + public $identifiers = []; /** * Whether this component is an operator. @@ -87,7 +87,7 @@ class Condition extends Component */ public function __construct($expr = null) { - $this->expr = trim($expr); + $this->expr = trim((string) $expr); } /** @@ -97,11 +97,11 @@ 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(); + $expr = new static(); /** * Counts brackets. @@ -159,12 +159,12 @@ class Condition extends Component } // Adding the operator. - $expr = new self($token->value); + $expr = new static($token->value); $expr->isOperator = true; $ret[] = $expr; // Preparing to parse another condition. - $expr = new self(); + $expr = new static(); continue; } } @@ -222,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 0f44e09..03f8225 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -1,10 +1,10 @@ <?php - /** * Parses the create definition of a column or a key. * * Used for parsing `CREATE TABLE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -30,61 +30,61 @@ 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( + 'DEFAULT' => [ 2, 'expr', - array('breakOnAlias' => true) - ), + ['breakOnAlias' => true], + ], /* Following are not according to grammar, but MySQL happily accepts * these at any location */ - 'CHARSET' => array( + 'CHARSET' => [ 2, 'var', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 3, 'var', - ), + ], 'AUTO_INCREMENT' => 3, 'PRIMARY' => 4, 'PRIMARY KEY' => 4, 'UNIQUE' => 4, 'UNIQUE KEY' => 4, - 'COMMENT' => array( + 'COMMENT' => [ 5, 'var', - ), - 'COLUMN_FORMAT' => array( + ], + 'COLUMN_FORMAT' => [ 6, 'var', - ), - 'ON UPDATE' => array( + ], + 'ON UPDATE' => [ 7, 'expr', - ), + ], // Generated columns options. 'GENERATED ALWAYS' => 8, - 'AS' => array( + 'AS' => [ 9, 'expr', - array('parenthesesDelimited' => true) - ), + ['parenthesesDelimited' => true], + ], 'VIRTUAL' => 10, 'PERSISTENT' => 11, 'STORED' => 11, - 'CHECK' => array( + 'CHECK' => [ 12, 'expr', - array('parenthesesDelimited' => true), - ) + ['parenthesesDelimited' => true], + ] // Common entries. // // NOTE: Some of the common options are not in the same order which @@ -99,7 +99,7 @@ class CreateDefinition extends Component // 'NULL' => 1, // 'PRIMARY' => 4, // 'PRIMARY KEY' => 4, - ); + ]; /** * The name of the new column. @@ -177,11 +177,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -290,7 +290,7 @@ class CreateDefinition extends Component if (! empty($expr->type) || ! empty($expr->key)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); if ($token->value === ',') { $state = 1; } elseif ($token->value === ')') { @@ -331,7 +331,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)"; @@ -350,7 +350,7 @@ class CreateDefinition extends Component if (! empty($component->type)) { $tmp .= DataType::build( $component->type, - array('lowercase' => true) + ['lowercase' => true] ) . ' '; } diff --git a/src/Components/DataType.php b/src/Components/DataType.php index 0d8dea3..8218e5b 100644 --- a/src/Components/DataType.php +++ b/src/Components/DataType.php @@ -1,8 +1,8 @@ <?php - /** * Parses a data type. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -25,23 +25,23 @@ class DataType extends Component * * @var array */ - public static $DATA_TYPE_OPTIONS = array( + public static $DATA_TYPE_OPTIONS = [ 'BINARY' => 1, - 'CHARACTER SET' => array( + 'CHARACTER SET' => [ 2, 'var', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 2, 'var', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 3, 'var', - ), + ], 'UNSIGNED' => 4, - 'ZEROFILL' => 5 - ); + 'ZEROFILL' => 5, + ]; /** * The name of the data type. @@ -63,7 +63,7 @@ class DataType extends Component * * @var array */ - public $parameters = array(); + public $parameters = []; /** * The options of this data type. @@ -81,7 +81,7 @@ class DataType extends Component */ public function __construct( $name = null, - array $parameters = array(), + array $parameters = [], $options = null ) { $this->name = $name; @@ -96,9 +96,9 @@ 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(); + $ret = new static(); /** * The state of the parser. @@ -127,7 +127,7 @@ class DataType extends Component } if ($state === 0) { - $ret->name = strtoupper($token->value); + $ret->name = strtoupper((string) $token->value); if (($token->type !== Token::TYPE_KEYWORD) || (! ($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { $parser->error('Unrecognized data type.', $token); } @@ -160,7 +160,7 @@ 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); diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 67767dc..108f335 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -1,9 +1,9 @@ <?php - /** * Parses a reference to an expression (column, table or database name, function * call, mathematical expression, etc.). */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -28,7 +28,7 @@ class Expression extends Component * * @var array */ - private static $ALLOWED_KEYWORDS = array( + private static $ALLOWED_KEYWORDS = [ 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, @@ -39,8 +39,8 @@ class Expression extends Component 'OR' => 1, 'XOR' => 1, 'NOT' => 1, - 'MOD' => 1 - ); + 'MOD' => 1, + ]; /** * The name of this database. @@ -155,9 +155,9 @@ 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(); + $ret = new static(); /** * Whether current tokens make an expression or a table reference. @@ -192,10 +192,10 @@ class Expression extends Component * * @var Token[] */ - $prev = array( + $prev = [ + null, null, - null - ); + ]; // When a field is parsed, no parentheses are expected. if (! empty($options['parseField'])) { @@ -269,7 +269,7 @@ class Expression extends Component continue; } $isExpr = true; - } elseif ($brackets === 0 && strlen($ret->expr) > 0 && ! $alias) { + } elseif ($brackets === 0 && strlen((string) $ret->expr) > 0 && ! $alias) { /* End of expression */ break; } @@ -413,7 +413,7 @@ class Expression extends Component } // White-spaces might be added at the end. - $ret->expr = trim($ret->expr); + $ret->expr = trim((string) $ret->expr); if ($ret->expr === '') { return null; @@ -430,7 +430,7 @@ 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); @@ -439,7 +439,7 @@ class Expression extends Component if ($component->expr !== '' && ! is_null($component->expr)) { $ret = $component->expr; } else { - $fields = array(); + $fields = []; if (isset($component->database) && ($component->database !== '')) { $fields[] = $component->database; } diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index cdec66b..eb05aac 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -1,8 +1,8 @@ <?php - /** * Parses a list of expressions delimited by a comma. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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..073b0e3 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -1,8 +1,8 @@ <?php - /** * Parses a function call. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -57,9 +57,9 @@ 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(); + $ret = new static(); /** * The state of the parser. @@ -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 c782288..bef1ebe 100644 --- a/src/Components/GroupKeyword.php +++ b/src/Components/GroupKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `GROUP BY` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -44,11 +44,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -96,7 +96,7 @@ class GroupKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -120,12 +120,12 @@ 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); } - return trim($component->expr); + return trim((string) $component->expr); } } diff --git a/src/Components/IndexHint.php b/src/Components/IndexHint.php index 254152e..7484172 100644 --- a/src/Components/IndexHint.php +++ b/src/Components/IndexHint.php @@ -1,8 +1,8 @@ <?php - /** * Parses an Index hint. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -46,7 +46,7 @@ class IndexHint extends Component * * @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,10 +71,10 @@ 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(); - $expr = new self(); + $ret = []; + $expr = new static(); $expr->type = isset($options['type']) ? $options['type'] : null; /** * The state of the parser. @@ -143,7 +143,7 @@ class IndexHint extends Component $expr->indexes = ExpressionArray::parse($parser, $list); $state = 0; $ret[] = $expr; - $expr = new self(); + $expr = new static(); } break; case 3: @@ -163,7 +163,7 @@ class IndexHint extends Component $expr->indexes = ExpressionArray::parse($parser, $list); $state = 0; $ret[] = $expr; - $expr = new self(); + $expr = new static(); break; } } @@ -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 a31f6a0..cebfa7a 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `INTO` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -25,37 +25,37 @@ class IntoKeyword extends Component * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array( + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ 1, 'expr', - ), + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array( + 'ENCLOSED BY' => [ 3, 'expr', - ), - 'ESCAPED BY' => array( + ], + 'ESCAPED BY' => [ 4, 'expr', - ) - ); + ], + ]; /** * LINES Options for `SELECT...INTO` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array( + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ 1, 'expr', - ), - 'TERMINATED BY' => array( + ], + 'TERMINATED BY' => [ 2, 'expr', - ) - ); + ], + ]; /** * Type of target (OUTFILE or SYMBOL). @@ -143,9 +143,9 @@ 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(); + $ret = new static(); /** * The state of the parser. @@ -203,10 +203,10 @@ class IntoKeyword extends Component $ret->dest = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); } else { $ret->values = ExpressionArray::parse($parser, $list); @@ -269,7 +269,7 @@ 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) . '`)' : ''; @@ -287,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 afc62ba..0c9dd70 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `JOIN` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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', @@ -40,8 +40,8 @@ class JoinKeyword extends Component 'NATURAL RIGHT JOIN' => 'NATURAL RIGHT', 'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER', 'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER', - 'STRAIGHT_JOIN' => 'STRAIGHT' - ); + 'STRAIGHT_JOIN' => 'STRAIGHT', + ]; /** * Type of this join. @@ -98,11 +98,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -159,7 +159,7 @@ 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) { @@ -174,7 +174,7 @@ class JoinKeyword extends Component if (! empty(static::$JOINS[$token->keyword]) ) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); $expr->type = static::$JOINS[$token->keyword]; $state = 1; } else { @@ -187,12 +187,12 @@ class JoinKeyword extends Component } elseif ($state === 3) { $expr->on = Condition::parse($parser, $list); $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } elseif ($state === 4) { $expr->using = ArrayObj::parse($parser, $list); $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } } @@ -212,9 +212,9 @@ 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) diff --git a/src/Components/Key.php b/src/Components/Key.php index bf87e54..b924c87 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -1,8 +1,8 @@ <?php - /** * Parses the definition of a key. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -28,24 +28,24 @@ class Key extends Component * * @var array */ - public static $KEY_OPTIONS = array( - 'KEY_BLOCK_SIZE' => array( + public static $KEY_OPTIONS = [ + 'KEY_BLOCK_SIZE' => [ 1, 'var', - ), - 'USING' => array( + ], + 'USING' => [ 2, 'var', - ), - 'WITH PARSER' => array( + ], + 'WITH PARSER' => [ 3, 'var', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 4, 'var=', - ) - ); + ], + ]; /** * The name of this key. @@ -85,7 +85,7 @@ class Key extends Component */ public function __construct( $name = null, - array $columns = array(), + array $columns = [], $type = null, $options = null ) { @@ -102,16 +102,16 @@ 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(); + $ret = new static(); /** * Last parsed column. * * @var array */ - $lastColumn = array(); + $lastColumn = []; /** * The state of the parser. @@ -164,7 +164,7 @@ class Key extends Component $state = ($token->value === ',') ? 2 : 4; if (! empty($lastColumn)) { $ret->columns[] = $lastColumn; - $lastColumn = array(); + $lastColumn = []; } } } else { @@ -194,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)) { $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..e18219d 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -1,8 +1,8 @@ <?php - /** * `LIMIT` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -53,9 +53,9 @@ 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(); + $ret = new static(); $offset = false; @@ -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 1a2479d..039d011 100644 --- a/src/Components/LockExpression.php +++ b/src/Components/LockExpression.php @@ -1,8 +1,8 @@ <?php - /** * Parses a reference to a LOCK expression. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -41,9 +41,9 @@ class LockExpression 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(); + $ret = new static(); /** * The state of the parser. @@ -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); diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index 69aabb3..ac6d7de 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -1,8 +1,8 @@ <?php - /** * Parses a list of options. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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,9 +47,9 @@ 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(); + $ret = new static(); /** * The ID that will be assigned to duplicate options. @@ -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. @@ -176,8 +176,8 @@ class OptionsArray extends Component // @var string Raw value. 'expr' => '', // @var string Processed value. - 'value' => '' - ); + 'value' => '', + ]; $state = 1; } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { // This is a keyword that is followed by an expression. @@ -185,15 +185,15 @@ 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. // This is used by the builder to rebuild it. 'equals' => $lastOption[1] === 'expr=', // @var Expression The parsed expression. - 'expr' => '' - ); + '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; @@ -276,13 +276,13 @@ 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)) { $options[] = $option; diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 1e77f57..7d80683 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `ORDER BY` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -53,11 +53,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -105,7 +105,7 @@ class OrderKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -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 831ee4b..9294273 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -1,8 +1,8 @@ <?php - /** * The definition of a parameter of a function or procedure. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -63,11 +63,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -127,7 +127,7 @@ class ParameterDefinition extends Component $state = 3; } elseif ($state === 3) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); if ($token->value === ',') { $state = 1; } elseif ($token->value === ')') { @@ -153,7 +153,7 @@ 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) . ')'; diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 71f73b8..e43f765 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -1,10 +1,10 @@ <?php - /** * Parses the create definition of a partition. * * Used for parsing `CREATE TABLE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -29,44 +29,44 @@ class PartitionDefinition extends Component * * @var array */ - public static $OPTIONS = array( - 'STORAGE ENGINE' => array( + public static $OPTIONS = [ + 'STORAGE ENGINE' => [ 1, 'var', - ), - 'ENGINE' => array( + ], + 'ENGINE' => [ 1, 'var', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 2, 'var', - ), - 'DATA DIRECTORY' => array( + ], + 'DATA DIRECTORY' => [ 3, 'var', - ), - 'INDEX DIRECTORY' => array( + ], + 'INDEX DIRECTORY' => [ 4, 'var', - ), - 'MAX_ROWS' => array( + ], + 'MAX_ROWS' => [ 5, 'var', - ), - 'MIN_ROWS' => array( + ], + 'MIN_ROWS' => [ 6, 'var', - ), - 'TABLESPACE' => array( + ], + 'TABLESPACE' => [ 7, 'var', - ), - 'NODEGROUP' => array( + ], + 'NODEGROUP' => [ 8, 'var', - ) - ); + ], + ]; /** * Whether this entry is a subpartition or a partition. @@ -117,9 +117,9 @@ 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(); + $ret = new static(); /** * The state of the parser. @@ -190,10 +190,10 @@ class PartitionDefinition extends Component $ret->expr = Expression::parse( $parser, $list, - array( + [ 'parenthesesDelimited' => true, - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); } $state = 5; @@ -205,9 +205,9 @@ class PartitionDefinition extends Component $ret->subpartitions = ArrayObj::parse( $parser, $list, - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition' - ) + [ + 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', + ] ); ++$list->idx; } @@ -226,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)"; diff --git a/src/Components/Reference.php b/src/Components/Reference.php index 38fc060..aac73ac 100644 --- a/src/Components/Reference.php +++ b/src/Components/Reference.php @@ -1,8 +1,8 @@ <?php - /** * `REFERENCES` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -26,20 +26,20 @@ class Reference extends Component * * @var array */ - public static $REFERENCES_OPTIONS = array( - 'MATCH' => array( + public static $REFERENCES_OPTIONS = [ + 'MATCH' => [ 1, 'var', - ), - 'ON DELETE' => array( + ], + 'ON DELETE' => [ 2, 'var', - ), - 'ON UPDATE' => array( + ], + 'ON UPDATE' => [ 3, 'var', - ) - ); + ], + ]; /** * The referenced table. @@ -69,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; @@ -83,9 +83,9 @@ 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(); + $ret = new static(); /** * The state of the parser. @@ -124,10 +124,10 @@ class Reference extends Component $ret->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); $state = 1; } elseif ($state === 1) { @@ -151,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 bf6167b..0008a41 100644 --- a/src/Components/RenameOperation.php +++ b/src/Components/RenameOperation.php @@ -1,8 +1,8 @@ <?php - /** * `RENAME TABLE` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -53,11 +53,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -99,10 +99,10 @@ class RenameOperation extends Component $expr->old = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - 'parseField' => 'table' - ) + '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' - ) + 'parseField' => 'table', + ] ); if (empty($expr->new)) { $parser->error( @@ -140,7 +140,7 @@ class RenameOperation extends Component } elseif ($state === 3) { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -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 d27819c..2d76704 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -1,8 +1,8 @@ <?php - /** * `SET` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -53,11 +53,11 @@ 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(); + $expr = new static(); /** * The state of the parser. @@ -118,9 +118,9 @@ class SetOperation extends Component $tmp = Expression::parse( $parser, $list, - array( - 'breakOnAlias' => true - ) + [ + 'breakOnAlias' => true, + ] ); if (is_null($tmp)) { $parser->error('Missing expression.', $token); @@ -129,7 +129,7 @@ class SetOperation extends Component $expr->column = trim($expr->column); $expr->value = $tmp->expr; $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; $commaLastSeenAt = null; } @@ -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..dc06831 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `UNION` keyword builder. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -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 9625deb..c9ff19e 100644 --- a/src/Context.php +++ b/src/Context.php @@ -1,11 +1,11 @@ <?php - /** * Defines a context class that is later extended to define other contexts. * * A context is a collection of keywords, operators and functions used for * parsing. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -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) @@ -137,8 +137,8 @@ abstract class Context ')' => 16, '.' => 16, ',' => 16, - ';' => 16 - ); + ';' => 16, + ]; /** * The mode of the MySQL server that will be used in lexing, parsing and diff --git a/src/Contexts/ContextMariaDb100000.php b/src/Contexts/ContextMariaDb100000.php index e4c368d..cb0ac6e 100644 --- a/src/Contexts/ContextMariaDb100000.php +++ b/src/Contexts/ContextMariaDb100000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.0. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -311,6 +311,6 @@ class ContextMariaDb100000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100100.php b/src/Contexts/ContextMariaDb100100.php index 26ce58b..7a419ab 100644 --- a/src/Contexts/ContextMariaDb100100.php +++ b/src/Contexts/ContextMariaDb100100.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.1. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -360,6 +360,6 @@ class ContextMariaDb100100 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100200.php b/src/Contexts/ContextMariaDb100200.php index 911afe8..e0923ad 100644 --- a/src/Contexts/ContextMariaDb100200.php +++ b/src/Contexts/ContextMariaDb100200.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.2. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -360,6 +360,6 @@ class ContextMariaDb100200 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100300.php b/src/Contexts/ContextMariaDb100300.php index e30ab04..b162600 100644 --- a/src/Contexts/ContextMariaDb100300.php +++ b/src/Contexts/ContextMariaDb100300.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.3. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -360,6 +360,6 @@ class ContextMariaDb100300 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50000.php b/src/Contexts/ContextMySql50000.php index 63f12fe..5a8322b 100644 --- a/src/Contexts/ContextMySql50000.php +++ b/src/Contexts/ContextMySql50000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.0. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.0/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -281,6 +281,6 @@ class ContextMySql50000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50100.php b/src/Contexts/ContextMySql50100.php index 4b97896..e4d353e 100644 --- a/src/Contexts/ContextMySql50100.php +++ b/src/Contexts/ContextMySql50100.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.1. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.1/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -306,6 +306,6 @@ class ContextMySql50100 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50500.php b/src/Contexts/ContextMySql50500.php index 4d1de76..2ef9b81 100644 --- a/src/Contexts/ContextMySql50500.php +++ b/src/Contexts/ContextMySql50500.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.5. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.5/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -311,6 +311,6 @@ class ContextMySql50500 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50600.php b/src/Contexts/ContextMySql50600.php index e447ec7..5fa8786 100644 --- a/src/Contexts/ContextMySql50600.php +++ b/src/Contexts/ContextMySql50600.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.6. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.6/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -340,6 +340,6 @@ class ContextMySql50600 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50700.php b/src/Contexts/ContextMySql50700.php index bf77167..6f24dc1 100644 --- a/src/Contexts/ContextMySql50700.php +++ b/src/Contexts/ContextMySql50700.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.7. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.7/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -360,6 +360,6 @@ class ContextMySql50700 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql80000.php b/src/Contexts/ContextMySql80000.php index 05fc4c9..df581f5 100644 --- a/src/Contexts/ContextMySql80000.php +++ b/src/Contexts/ContextMySql80000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 8.0. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/8.0/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -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, @@ -360,6 +360,6 @@ class ContextMySql80000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Core.php b/src/Core.php index 052ac5e..1965a2f 100644 --- a/src/Core.php +++ b/src/Core.php @@ -1,8 +1,8 @@ <?php - /** * Defines the core helper infrastructure of the library. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -28,7 +28,7 @@ class Core * * @see Core::error() */ - public $errors = array(); + public $errors = []; /** * Creates a new error log. diff --git a/src/Exceptions/LexerException.php b/src/Exceptions/LexerException.php index 61e88c9..7dd85a4 100644 --- a/src/Exceptions/LexerException.php +++ b/src/Exceptions/LexerException.php @@ -1,8 +1,8 @@ <?php - /** * Exception thrown by the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; diff --git a/src/Exceptions/LoaderException.php b/src/Exceptions/LoaderException.php index bfbd4c3..d809876 100644 --- a/src/Exceptions/LoaderException.php +++ b/src/Exceptions/LoaderException.php @@ -1,8 +1,8 @@ <?php - /** * Exception thrown by the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index eb13653..575eeb1 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -1,8 +1,8 @@ <?php - /** * Exception thrown by the parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; diff --git a/src/Lexer.php b/src/Lexer.php index 895cb2b..7fc1a75 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -1,5 +1,4 @@ <?php - /** * Defines the lexer of the library. * @@ -7,6 +6,7 @@ * * Depends on context to extract lexemes. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -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). // @@ -80,8 +80,8 @@ class Lexer extends Core 'parseSymbol', 'parseKeyword', 'parseLabel', - 'parseUnknown' - ); + 'parseUnknown', + ]; /** * The string to be parsed. diff --git a/src/Parser.php b/src/Parser.php index ab3e1b7..91524fd 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -1,10 +1,10 @@ <?php - /** * Defines the parser of the library. * * This is one of the most important components, along with the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -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', @@ -92,247 +92,247 @@ class Parser extends Core // Lock statements // https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html 'LOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement', - 'UNLOCK' => '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. @@ -526,16 +526,16 @@ class Parser extends Core * * @var SelectStatement $lastStatement */ - $lastStatement->union[] = array( + $lastStatement->union[] = [ $unionType, - $statement - ); + $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 diff --git a/src/Statement.php b/src/Statement.php index 2e7fc49..d2d0ed2 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -1,11 +1,11 @@ <?php - /** * The result of the parser is an array of statements are extensions of the * class defined here. * * A statement represents the result of parsing the lexemes. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -40,7 +40,7 @@ abstract class Statement * * @var array */ - public static $OPTIONS = array(); + public static $OPTIONS = []; /** * The clauses of this statement, in order. @@ -54,9 +54,9 @@ abstract class Statement * * @var array */ - public static $CLAUSES = array(); + public static $CLAUSES = []; - public static $END_OPTIONS = array(); + public static $END_OPTIONS = []; /** * The options of this query. @@ -120,7 +120,7 @@ abstract class Statement * * @var array */ - $built = array(); + $built = []; /** * Statement's clauses. @@ -202,7 +202,7 @@ abstract class Statement * * @var array */ - $parsedClauses = array(); + $parsedClauses = []; // This may be corrected by the parser. $this->first = $list->idx; @@ -303,7 +303,7 @@ abstract class Statement * * @var array */ - $options = array(); + $options = []; // Looking for duplicated clauses. if (! empty(Parser::$KEYWORD_PARSERS[$token->value]) diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php index ce0c824..0620936 100644 --- a/src/Statements/AlterStatement.php +++ b/src/Statements/AlterStatement.php @@ -1,8 +1,8 @@ <?php - /** * `ALTER` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -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, @@ -54,8 +54,8 @@ class AlterStatement extends Statement 'SERVER' => 3, 'TABLE' => 3, 'TABLESPACE' => 3, - 'VIEW' => 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 - ) + '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 4f6ea32..ebc7f70 100644 --- a/src/Statements/AnalyzeStatement.php +++ b/src/Statements/AnalyzeStatement.php @@ -1,8 +1,8 @@ <?php - /** * `ANALYZE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -12,8 +12,8 @@ use PhpMyAdmin\SqlParser\Statement; /** * `ANALYZE` statement. * - * ANALYZE array(NO_WRITE_TO_BINLOG | LOCAL] TABLE - * tbl_name array(, tbl_name] ... + * ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE + * tbl_name [, tbl_name] ... * * @category Statements * @@ -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 - ); + 'LOCAL' => 3, + ]; /** * Analyzed tables. diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php index 52f136b..574dc9a 100644 --- a/src/Statements/BackupStatement.php +++ b/src/Statements/BackupStatement.php @@ -1,15 +1,15 @@ <?php - /** * `BACKUP` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `BACKUP` statement. * - * BACKUP TABLE tbl_name array(, tbl_name] ... TO '/path/to/backup/directory' + * BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory' * * @category Statements * @@ -22,15 +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( + 'TO' => [ 4, 'var', - ) - ); + ], + ]; } diff --git a/src/Statements/CallStatement.php b/src/Statements/CallStatement.php index 00cb95c..570d3a8 100644 --- a/src/Statements/CallStatement.php +++ b/src/Statements/CallStatement.php @@ -1,8 +1,8 @@ <?php - /** * `CALL` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php index 57e5cb7..789679f 100644 --- a/src/Statements/CheckStatement.php +++ b/src/Statements/CheckStatement.php @@ -1,15 +1,15 @@ <?php - /** * `CHECK` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `CHECK` statement. * - * CHECK TABLE tbl_name array(, tbl_name] ... array(option] ... + * CHECK TABLE tbl_name [, tbl_name] ... [option] ... * * @category Statements * @@ -22,7 +22,7 @@ class CheckStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'FOR UPGRADE' => 2, @@ -30,6 +30,6 @@ class CheckStatement extends MaintenanceStatement 'FAST' => 4, 'MEDIUM' => 5, 'EXTENDED' => 6, - 'CHANGED' => 7 - ); + 'CHANGED' => 7, + ]; } diff --git a/src/Statements/ChecksumStatement.php b/src/Statements/ChecksumStatement.php index 1be2588..3214748 100644 --- a/src/Statements/ChecksumStatement.php +++ b/src/Statements/ChecksumStatement.php @@ -1,15 +1,15 @@ <?php - /** * `CHECKSUM` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `CHECKSUM` statement. * - * CHECKSUM TABLE tbl_name array(, tbl_name] ... array( QUICK | EXTENDED ] + * CHECKSUM TABLE tbl_name [, tbl_name] ... [ QUICK | EXTENDED ] * * @category Statements * @@ -22,10 +22,10 @@ class ChecksumStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'QUICK' => 2, - 'EXTENDED' => 3 - ); + 'EXTENDED' => 3, + ]; } diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index 17c5bf1..ffa08bc 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `CREATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -32,25 +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( + 'ALGORITHM' => [ 3, 'var=', - ), + ], // `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE` - 'DEFINER' => array( + 'DEFINER' => [ 4, 'expr=', - ), - 'SQL SECURITY' => array( + ], + 'SQL SECURITY' => [ 5, 'var', - ), + ], 'DATABASE' => 6, 'EVENT' => 6, @@ -68,159 +68,159 @@ class CreateStatement extends Statement 'VIEW' => 6, // CREATE TABLE - 'IF NOT EXISTS' => 7 - ); + 'IF NOT EXISTS' => 7, + ]; /** * All database options. * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array( + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ 1, 'var=', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 1, 'var=', - ), - 'DEFAULT CHARACTER SET' => array( + ], + 'DEFAULT CHARACTER SET' => [ 1, 'var=', - ), - 'DEFAULT CHARSET' => array( + ], + 'DEFAULT CHARSET' => [ 1, 'var=', - ), - 'DEFAULT COLLATE' => array( + ], + 'DEFAULT COLLATE' => [ 2, 'var=', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 2, 'var=', - ) - ); + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array( + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ 1, 'var=', - ), - 'AUTO_INCREMENT' => array( + ], + 'AUTO_INCREMENT' => [ 2, 'var=', - ), - 'AVG_ROW_LENGTH' => array( + ], + 'AVG_ROW_LENGTH' => [ 3, 'var', - ), - 'CHARACTER SET' => array( + ], + 'CHARACTER SET' => [ 4, 'var=', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 4, 'var=', - ), - 'DEFAULT CHARACTER SET' => array( + ], + 'DEFAULT CHARACTER SET' => [ 4, 'var=', - ), - 'DEFAULT CHARSET' => array( + ], + 'DEFAULT CHARSET' => [ 4, 'var=', - ), - 'CHECKSUM' => array( + ], + 'CHECKSUM' => [ 5, 'var', - ), - 'DEFAULT COLLATE' => array( + ], + 'DEFAULT COLLATE' => [ 6, 'var=', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 6, 'var=', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 7, 'var=', - ), - 'CONNECTION' => array( + ], + 'CONNECTION' => [ 8, 'var', - ), - 'DATA DIRECTORY' => array( + ], + 'DATA DIRECTORY' => [ 9, 'var', - ), - 'DELAY_KEY_WRITE' => array( + ], + 'DELAY_KEY_WRITE' => [ 10, 'var', - ), - 'INDEX DIRECTORY' => array( + ], + 'INDEX DIRECTORY' => [ 11, 'var', - ), - 'INSERT_METHOD' => array( + ], + 'INSERT_METHOD' => [ 12, 'var', - ), - 'KEY_BLOCK_SIZE' => array( + ], + 'KEY_BLOCK_SIZE' => [ 13, 'var', - ), - 'MAX_ROWS' => array( + ], + 'MAX_ROWS' => [ 14, 'var', - ), - 'MIN_ROWS' => array( + ], + 'MIN_ROWS' => [ 15, 'var', - ), - 'PACK_KEYS' => array( + ], + 'PACK_KEYS' => [ 16, 'var', - ), - 'PASSWORD' => array( + ], + 'PASSWORD' => [ 17, 'var', - ), - 'ROW_FORMAT' => array( + ], + 'ROW_FORMAT' => [ 18, 'var', - ), - 'TABLESPACE' => array( + ], + 'TABLESPACE' => [ 19, 'var', - ), - 'STORAGE' => array( + ], + 'STORAGE' => [ 20, 'var', - ), - 'UNION' => array( + ], + 'UNION' => [ 21, 'var', - ) - ); + ], + ]; /** * All function options. * * @var array */ - public static $FUNC_OPTIONS = array( - 'COMMENT' => array( + public static $FUNC_OPTIONS = [ + 'COMMENT' => [ 1, 'var=', - ), + ], 'LANGUAGE SQL' => 2, 'DETERMINISTIC' => 3, 'NOT DETERMINISTIC' => 3, @@ -228,24 +228,24 @@ class CreateStatement extends Statement 'NO SQL' => 4, 'READS SQL DATA' => 4, 'MODIFIES SQL DATA' => 4, - 'SQL SECURITY DEFINER' => array( + '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 - ); + 'DELETE' => 2, + ]; /** * The name of the entity that is created. @@ -367,7 +367,7 @@ class CreateStatement extends Statement * * @var Token[]|string */ - public $body = array(); + public $body = []; /** * @return string @@ -474,10 +474,10 @@ class CreateStatement extends Statement $this->name = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); if (! isset($this->name) || ($this->name === '')) { @@ -524,10 +524,10 @@ class CreateStatement extends Statement $this->like = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); // The 'LIKE' keyword was found, but no table_name was found next to it if (is_null($this->like)) { @@ -637,9 +637,9 @@ class CreateStatement extends Statement $this->partitions = ArrayObj::parse( $parser, $list, - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition' - ) + [ + 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', + ] ); } break; @@ -714,10 +714,10 @@ class CreateStatement extends Statement $this->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); ++$list->idx; diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 088489d..b55d5f4 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -1,8 +1,8 @@ <?php - /** * `DELETE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -54,11 +54,11 @@ class DeleteStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'QUICK' => 2, - 'IGNORE' => 3 - ); + 'IGNORE' => 3, + ]; /** * The clauses of this statement, in order. @@ -67,41 +67,41 @@ class DeleteStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DELETE' => array( + public static $CLAUSES = [ + 'DELETE' => [ 'DELETE', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), - 'FROM' => array( + ], + 'FROM' => [ 'FROM', 3, - ), - 'PARTITION' => array( + ], + 'PARTITION' => [ 'PARTITION', 3, - ), - 'USING' => array( + ], + 'USING' => [ 'USING', 3, - ), - 'WHERE' => array( + ], + 'WHERE' => [ 'WHERE', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ) - ); + ], + ]; /** * Table(s) used as sources for this statement. @@ -184,7 +184,7 @@ class DeleteStatement extends Statement 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((string) $this->limit) > 0) { $ret .= ' LIMIT ' . Limit::build($this->limit); } diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php index e6f9591..453bed1 100644 --- a/src/Statements/DropStatement.php +++ b/src/Statements/DropStatement.php @@ -1,8 +1,8 @@ <?php - /** * `DROP` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -23,7 +23,7 @@ class DropStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'DATABASE' => 1, 'EVENT' => 1, 'FUNCTION' => 1, @@ -38,8 +38,8 @@ class DropStatement extends Statement 'TRIGGER' => 1, 'TEMPORARY' => 2, - 'IF EXISTS' => 3 - ); + 'IF EXISTS' => 3, + ]; /** * The clauses of this statement, in order. @@ -48,26 +48,26 @@ class DropStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DROP' => array( + public static $CLAUSES = [ + 'DROP' => [ 'DROP', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for select expressions. - 'DROP_' => array( + 'DROP_' => [ 'DROP', 1, - ), - 'ON' => array( + ], + 'ON' => [ 'ON', 3, - ) - ); + ], + ]; /** * Dropped elements. diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php index 96a5828..65ea597 100644 --- a/src/Statements/ExplainStatement.php +++ b/src/Statements/ExplainStatement.php @@ -1,8 +1,8 @@ <?php - /** * `EXPLAIN` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index 4e48c0d..265929d 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -1,8 +1,8 @@ <?php - /** * `INSERT` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -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 - ); + 'IGNORE' => 4, + ]; /** * Tables used as target for this statement. @@ -117,7 +117,7 @@ class InsertStatement extends Statement $ret .= ' VALUES ' . Array2d::build($this->values); } 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((string) $this->select) > 0) { $ret .= ' ' . $this->select->build(); } @@ -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 422efc7..c5186cf 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -1,8 +1,8 @@ <?php - /** * `LOAD` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -49,48 +49,48 @@ class LoadStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'CONCURRENT' => 1, - 'LOCAL' => 2 - ); + 'LOCAL' => 2, + ]; /** * FIELDS/COLUMNS Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array( + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ 1, 'expr', - ), + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array( + 'ENCLOSED BY' => [ 3, 'expr', - ), - 'ESCAPED BY' => array( + ], + 'ESCAPED BY' => [ 4, 'expr', - ) - ); + ], + ]; /** * LINES Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array( + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ 1, 'expr', - ), - 'TERMINATED BY' => array( + ], + 'TERMINATED BY' => [ 2, 'expr', - ) - ); + ], + ]; /** * File name being used to load data. @@ -194,7 +194,7 @@ class LoadStatement extends Statement $ret .= ' INTO TABLE ' . $this->table; - if ($this->partition !== null && strlen($this->partition) > 0) { + if ($this->partition !== null && strlen((string) $this->partition) > 0) { $ret .= ' PARTITION ' . ArrayObj::build($this->partition); } @@ -206,7 +206,7 @@ class LoadStatement extends Statement $ret .= ' ' . $this->fields_keyword . ' ' . $this->fields_options; } - if ($this->lines_options !== null && strlen($this->lines_options) > 0) { + if ($this->lines_options !== null && strlen((string) $this->lines_options) > 0) { $ret .= ' LINES ' . $this->lines_options; } @@ -281,7 +281,7 @@ class LoadStatement extends Statement $this->file_name = Expression::parse( $parser, $list, - array('parseField' => 'file') + ['parseField' => 'file'] ); $state = 1; } elseif ($state === 1) { @@ -298,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); diff --git a/src/Statements/LockStatement.php b/src/Statements/LockStatement.php index d4c6cb1..0166dca 100644 --- a/src/Statements/LockStatement.php +++ b/src/Statements/LockStatement.php @@ -1,8 +1,8 @@ <?php - /** * `LOCK` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -26,7 +26,7 @@ class LockStatement extends Statement * * @var LockExpression[] */ - public $locked = array(); + public $locked = []; /** * Whether it's a LOCK statement diff --git a/src/Statements/MaintenanceStatement.php b/src/Statements/MaintenanceStatement.php index ac3b8c9..c59bb77 100644 --- a/src/Statements/MaintenanceStatement.php +++ b/src/Statements/MaintenanceStatement.php @@ -1,8 +1,8 @@ <?php - /** * Maintenance statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php index e534cdf..254ca15 100644 --- a/src/Statements/NotImplementedStatement.php +++ b/src/Statements/NotImplementedStatement.php @@ -1,8 +1,8 @@ <?php - /** * Not implemented (yet) statements. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -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 1aff056..cd9be0c 100644 --- a/src/Statements/OptimizeStatement.php +++ b/src/Statements/OptimizeStatement.php @@ -1,8 +1,8 @@ <?php - /** * `OPTIMIZE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -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 - ); + 'LOCAL' => 3, + ]; /** * Optimized tables. diff --git a/src/Statements/PurgeStatement.php b/src/Statements/PurgeStatement.php index 0374813..4dc385e 100644 --- a/src/Statements/PurgeStatement.php +++ b/src/Statements/PurgeStatement.php @@ -1,8 +1,8 @@ <?php - /** * `PURGE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -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/RenameStatement.php b/src/Statements/RenameStatement.php index e1bcf0d..17662d3 100644 --- a/src/Statements/RenameStatement.php +++ b/src/Statements/RenameStatement.php @@ -1,8 +1,8 @@ <?php - /** * `RENAME` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php index fb76855..e17cdee 100644 --- a/src/Statements/RepairStatement.php +++ b/src/Statements/RepairStatement.php @@ -1,8 +1,8 @@ <?php - /** * `REPAIR` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -24,7 +24,7 @@ class RepairStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, @@ -32,6 +32,6 @@ class RepairStatement extends MaintenanceStatement 'QUICK' => 4, 'EXTENDED' => 5, - 'USE_FRM' => 6 - ); + 'USE_FRM' => 6, + ]; } diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index d912da0..5bb5e12 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -1,8 +1,8 @@ <?php - /** * `REPLACE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -47,10 +47,10 @@ class ReplaceStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, - 'DELAYED' => 1 - ); + 'DELAYED' => 1, + ]; /** * Tables used as target for this statement. @@ -94,7 +94,7 @@ class ReplaceStatement extends Statement $ret .= ' VALUES ' . Array2d::build($this->values); } 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((string) $this->select) > 0) { $ret .= ' ' . $this->select->build(); } @@ -160,7 +160,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 a7bf2c8..6d2a72e 100644 --- a/src/Statements/RestoreStatement.php +++ b/src/Statements/RestoreStatement.php @@ -1,8 +1,8 @@ <?php - /** * `RESTORE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -22,12 +22,12 @@ class RestoreStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, - 'FROM' => array( + 'FROM' => [ 2, 'var', - ) - ); + ], + ]; } diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index 852dc0b..a770227 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -1,8 +1,8 @@ <?php - /** * `SELECT` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -33,10 +33,10 @@ use PhpMyAdmin\SqlParser\Statement; * [PARTITION partition_list] * [WHERE where_condition] * [GROUP BY {col_name | expr | position} - * [ASC | DESC), ... [WITH ROLLUP]] + * [ASC | DESC], ... [WITH ROLLUP]] * [HAVING where_condition] * [ORDER BY {col_name | expr | position} - * [ASC | DESC), ...] + * [ASC | DESC], ...] * [LIMIT {[offset,] row_count | row_count OFFSET offset}] * [PROCEDURE procedure_name(argument_list)] * [INTO OUTFILE 'file_name' @@ -57,28 +57,28 @@ 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( + 'MAX_STATEMENT_TIME' => [ 3, 'var=', - ), + ], 'STRAIGHT_JOIN' => 4, 'SQL_SMALL_RESULT' => 5, 'SQL_BIG_RESULT' => 6, 'SQL_BUFFER_RESULT' => 7, 'SQL_CACHE' => 8, 'SQL_NO_CACHE' => 8, - 'SQL_CALC_FOUND_ROWS' => 9 - ); + 'SQL_CALC_FOUND_ROWS' => 9, + ]; - public static $END_OPTIONS = array( + public static $END_OPTIONS = [ 'FOR UPDATE' => 1, - 'LOCK IN SHARE MODE' => 1 - ); + 'LOCK IN SHARE MODE' => 1, + ]; /** * The clauses of this statement, in order. @@ -87,153 +87,153 @@ class SelectStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SELECT' => array( + public static $CLAUSES = [ + 'SELECT' => [ 'SELECT', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for selected expressions. - '_SELECT' => array( + '_SELECT' => [ 'SELECT', 1, - ), - 'INTO' => array( + ], + 'INTO' => [ 'INTO', 3, - ), - 'FROM' => array( + ], + 'FROM' => [ 'FROM', 3, - ), - 'FORCE' => array( + ], + 'FORCE' => [ 'FORCE', 1, - ), - 'USE' => array( + ], + 'USE' => [ 'USE', 1, - ), - 'IGNORE' => array( + ], + 'IGNORE' => [ 'IGNORE', 3, - ), - 'PARTITION' => array( + ], + 'PARTITION' => [ 'PARTITION', 3, - ), + ], - 'JOIN' => array( + 'JOIN' => [ 'JOIN', 1, - ), - 'FULL JOIN' => array( + ], + 'FULL JOIN' => [ 'FULL JOIN', 1, - ), - 'INNER JOIN' => array( + ], + 'INNER JOIN' => [ 'INNER JOIN', 1, - ), - 'LEFT JOIN' => array( + ], + 'LEFT JOIN' => [ 'LEFT JOIN', 1, - ), - 'LEFT OUTER JOIN' => array( + ], + 'LEFT OUTER JOIN' => [ 'LEFT OUTER JOIN', 1, - ), - 'RIGHT JOIN' => array( + ], + 'RIGHT JOIN' => [ 'RIGHT JOIN', 1, - ), - 'RIGHT OUTER JOIN' => array( + ], + 'RIGHT OUTER JOIN' => [ 'RIGHT OUTER JOIN', 1, - ), - 'NATURAL JOIN' => array( + ], + 'NATURAL JOIN' => [ 'NATURAL JOIN', 1, - ), - 'NATURAL LEFT JOIN' => array( + ], + 'NATURAL LEFT JOIN' => [ 'NATURAL LEFT JOIN', 1, - ), - 'NATURAL RIGHT JOIN' => array( + ], + 'NATURAL RIGHT JOIN' => [ 'NATURAL RIGHT JOIN', 1, - ), - 'NATURAL LEFT OUTER JOIN' => array( + ], + 'NATURAL LEFT OUTER JOIN' => [ 'NATURAL LEFT OUTER JOIN', 1, - ), - 'NATURAL RIGHT OUTER JOIN' => array( + ], + 'NATURAL RIGHT OUTER JOIN' => [ 'NATURAL RIGHT JOIN', 1, - ), + ], - 'WHERE' => array( + 'WHERE' => [ 'WHERE', 3, - ), - 'GROUP BY' => array( + ], + 'GROUP BY' => [ 'GROUP BY', 3, - ), - 'HAVING' => array( + ], + 'HAVING' => [ 'HAVING', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ), - 'PROCEDURE' => array( + ], + 'PROCEDURE' => [ 'PROCEDURE', 3, - ), - 'UNION' => array( + ], + 'UNION' => [ 'UNION', 1, - ), - 'EXCEPT' => array( + ], + 'EXCEPT' => [ 'EXCEPT', 1, - ), - 'INTERSECT' => array( + ], + 'INTERSECT' => [ 'INTERSECT', 1, - ), - '_END_OPTIONS' => array( + ], + '_END_OPTIONS' => [ '_END_OPTIONS', 1, - ), + ], // These are available only when `UNION` is present. // 'ORDER BY' => array('ORDER BY', 3), - // 'LIMIT' => array('LIMIT', 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 @@ -310,7 +310,7 @@ class SelectStatement extends Statement * * @var SelectStatement[] */ - public $union = array(); + public $union = []; /** * The end options of this query. @@ -334,14 +334,14 @@ class SelectStatement extends Statement if (! empty($this->union)) { $clauses = static::$CLAUSES; unset($clauses['ORDER BY'], $clauses['LIMIT']); - $clauses['ORDER BY'] = array( + $clauses['ORDER BY'] = [ 'ORDER BY', - 3 - ); - $clauses['LIMIT'] = array( + 3, + ]; + $clauses['LIMIT'] = [ 'LIMIT', - 3 - ); + 3, + ]; return $clauses; } diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php index 2643578..cc1e487 100644 --- a/src/Statements/SetStatement.php +++ b/src/Statements/SetStatement.php @@ -1,8 +1,8 @@ <?php - /** * `SET` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -26,48 +26,48 @@ class SetStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SET' => array( + public static $CLAUSES = [ + 'SET' => [ 'SET', - 3 - ), - '_END_OPTIONS' => array( + 3, + ], + '_END_OPTIONS' => [ '_END_OPTIONS', - 1 - ) - ); + 1, + ], + ]; /** * Possible exceptions in SET statment. * * @var array */ - public static $OPTIONS = array( - 'CHARSET' => array( + public static $OPTIONS = [ + 'CHARSET' => [ 3, 'var', - ), - 'CHARACTER SET' => array( + ], + 'CHARACTER SET' => [ 3, 'var', - ), - 'NAMES' => array( + ], + 'NAMES' => [ 3, 'var', - ), - 'PASSWORD' => array( + ], + 'PASSWORD' => [ 3, 'expr', - ) - ); + ], + ]; - public static $END_OPTIONS = array( - 'COLLATE' => array( + public static $END_OPTIONS = [ + 'COLLATE' => [ 1, 'var', - ), - 'DEFAULT' => 1 - ); + ], + 'DEFAULT' => 1, + ]; /** * Options used in current statement. diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php index 1e9e67e..d332968 100644 --- a/src/Statements/ShowStatement.php +++ b/src/Statements/ShowStatement.php @@ -1,8 +1,8 @@ <?php - /** * `SHOW` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -20,7 +20,7 @@ class ShowStatement extends NotImplementedStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'CREATE' => 1, 'AUTHORS' => 2, 'BINARY' => 2, @@ -61,6 +61,6 @@ class ShowStatement extends NotImplementedStatement 'TRIGGERS' => 2, 'VARIABLES' => 2, 'VIEW' => 2, - 'WARNINGS' => 2 - ); + 'WARNINGS' => 2, + ]; } diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php index 59bd9c6..7c07b5f 100644 --- a/src/Statements/TransactionStatement.php +++ b/src/Statements/TransactionStatement.php @@ -1,8 +1,8 @@ <?php - /** * Transaction statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -60,7 +60,7 @@ class TransactionStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'START TRANSACTION' => 1, 'BEGIN' => 1, 'COMMIT' => 1, @@ -70,8 +70,8 @@ class TransactionStatement extends Statement 'AND NO CHAIN' => 3, 'AND CHAIN' => 3, 'RELEASE' => 4, - 'NO 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 13a4d21..519ffaf 100644 --- a/src/Statements/TruncateStatement.php +++ b/src/Statements/TruncateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `TRUNCATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -23,9 +23,9 @@ class TruncateStatement extends Statement * * @var array */ - public static $OPTIONS = array( - 'TABLE' => 1 - ); + public static $OPTIONS = [ + 'TABLE' => 1, + ]; /** * The name of the truncated table. diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php index da7d741..8e6708f 100644 --- a/src/Statements/UpdateStatement.php +++ b/src/Statements/UpdateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `UPDATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -39,10 +39,10 @@ class UpdateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, - 'IGNORE' => 2 - ); + 'IGNORE' => 2, + ]; /** * The clauses of this statement, in order. @@ -51,38 +51,38 @@ class UpdateStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'UPDATE' => array( + public static $CLAUSES = [ + 'UPDATE' => [ 'UPDATE', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for updated tables. - '_UPDATE' => array( + '_UPDATE' => [ 'UPDATE', 1, - ), - 'SET' => array( + ], + 'SET' => [ 'SET', 3, - ), - 'WHERE' => array( + ], + 'WHERE' => [ 'WHERE', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ) - ); + ], + ]; /** * Tables used as sources for this statement. diff --git a/src/Token.php b/src/Token.php index f2f9860..fe43e8b 100644 --- a/src/Token.php +++ b/src/Token.php @@ -1,10 +1,10 @@ <?php - /** * Defines a token along with a set of types and flags and utility functions. * * An array of tokens will result after parsing the query. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -330,16 +330,16 @@ class Token public function getInlineToken() { return str_replace( - array( + [ "\r", "\n", "\t", - ), - array( + ], + [ '\r', '\n', '\t', - ), + ], $this->token ); } diff --git a/src/TokensList.php b/src/TokensList.php index 5c04ad4..507d68b 100644 --- a/src/TokensList.php +++ b/src/TokensList.php @@ -1,8 +1,8 @@ <?php - /** * Defines an array of tokens and utility functions to iterate through it. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -20,7 +20,7 @@ class TokensList implements \ArrayAccess * * @var array */ - public $tokens = array(); + public $tokens = []; /** * The count of tokens. @@ -42,7 +42,7 @@ 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)) { $this->tokens = $tokens; diff --git a/src/Translator.php b/src/Translator.php index 622bec9..a169632 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -1,8 +1,8 @@ <?php - /** * Defines the localization helper infrastructure of the library. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; diff --git a/src/UtfString.php b/src/UtfString.php index 58905f3..9e6e55b 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -1,5 +1,4 @@ <?php - /** * Implementation for UTF-8 strings. * @@ -10,6 +9,7 @@ * Because the lexer relies on the subscript operator this class had to be * implemented. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php index db9c4e5..c2dd074 100644 --- a/src/Utils/BufferedQuery.php +++ b/src/Utils/BufferedQuery.php @@ -1,8 +1,8 @@ <?php - /** * Buffered query utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -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 ); diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 60af222..cd27908 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -1,8 +1,8 @@ <?php - /** * CLI interface. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -42,11 +42,11 @@ class CLI public function parseHighlight() { - $longopts = array( + $longopts = [ 'help', 'query:', - 'format:' - ); + 'format:', + ]; $params = $this->getopt( 'hq:f:', $longopts @@ -58,7 +58,7 @@ class CLI 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; @@ -78,7 +78,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -86,7 +86,7 @@ class CLI if (isset($params['q'])) { echo Formatter::format( $params['q'], - array('type' => $params['f']) + ['type' => $params['f']] ); echo "\n"; @@ -106,11 +106,11 @@ class CLI public function parseLint() { - $longopts = array( + $longopts = [ 'help', 'query:', - 'context:' - ); + 'context:', + ]; $params = $this->getopt( 'hq:c:', $longopts @@ -134,7 +134,7 @@ class CLI if (isset($params['c'])) { Context::load($params['c']); } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -142,7 +142,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; } @@ -166,10 +166,10 @@ class CLI public function parseTokenize() { - $longopts = array( + $longopts = [ 'help', - 'query:' - ); + 'query:', + ]; $params = $this->getopt( 'hq:', $longopts @@ -190,7 +190,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -218,7 +218,8 @@ class CLI return 1; } - private function readStdin() { + private function readStdin() + { stream_set_blocking(STDIN, false); $stdin = stream_get_contents(STDIN); // restore-default block-mode setting diff --git a/src/Utils/Error.php b/src/Utils/Error.php index 20310a1..d0f82ed 100644 --- a/src/Utils/Error.php +++ b/src/Utils/Error.php @@ -1,8 +1,8 @@ <?php - /** * Error related utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -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 - ); + $err->pos, + ]; } } elseif ($obj instanceof Parser) { foreach ($obj->errors as $err) { - $ret[] = array( + $ret[] = [ $err->getMessage(), $err->getCode(), $err->token->token, - $err->token->position - ); + $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) { @@ -86,7 +86,7 @@ class Error ++$i, $err[0], $err[1], - htmlspecialchars($err[2]), + htmlspecialchars((string) $err[2]), $err[3] ); } diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index b608b73..3b17a2b 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -1,8 +1,8 @@ <?php - /** * Utilities that are used for formatting queries. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -46,10 +46,10 @@ class Formatter * * @var array */ - public static $SHORT_CLAUSES = array( + public static $SHORT_CLAUSES = [ 'CREATE' => true, - 'INSERT' => 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, @@ -66,15 +66,15 @@ class Formatter 'PARTITION' => true, 'PROCEDURE' => true, 'SUBPARTITION BY' => true, - 'VALUES' => 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. * @@ -170,8 +170,8 @@ class Formatter * * @var bool */ - 'indent_parts' => true - ); + 'indent_parts' => true, + ]; } /** @@ -182,78 +182,78 @@ 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' => Token::FLAG_SYMBOL_PARAMETER, 'html' => 'class="sql-parameter"', 'cli' => "\x1b[31m", '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( + $added = []; + $integers = [ 'flags', - 'type' - ); - $strings = array( + 'type', + ]; + $strings = [ 'html', 'cli', - 'function' - ); + 'function', + ]; /* Sanitize the array so that we do not have to care later */ foreach ($newFormats as $j => $new) { @@ -341,7 +341,7 @@ class Formatter * * @var array */ - $blocksIndentation = array(); + $blocksIndentation = []; /** * A stack that keeps track of the line endings every time a new block @@ -349,7 +349,7 @@ class Formatter * * @var array */ - $blocksLineEndings = array(); + $blocksLineEndings = []; /** * Whether clause's options were formatted. @@ -437,7 +437,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]) ) { @@ -507,7 +507,7 @@ class Formatter // No space after . ( || ($curr->type === Token::TYPE_OPERATOR && ($curr->value === '.' || $curr->value === ',' || $curr->value === '(' || $curr->value === ')')) // No space before . , ( ) - || $curr->type === Token::TYPE_DELIMITER && mb_strlen($curr->value, 'UTF-8') < 2 + || $curr->type === Token::TYPE_DELIMITER && mb_strlen((string) $curr->value, 'UTF-8') < 2 ) ) { $ret .= ' '; @@ -529,7 +529,7 @@ class Formatter public function escapeConsole($string) { return str_replace( - array( + [ "\x00", "\x01", "\x02", @@ -562,8 +562,8 @@ class Formatter "\x1D", "\x1E", "\x1F", - ), - array( + ], + [ '\x00', '\x01', '\x02', @@ -596,7 +596,7 @@ class Formatter '\x1D', '\x1E', '\x1F', - ), + ], $string ); } @@ -663,7 +663,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); @@ -713,7 +713,7 @@ class Formatter } // Keeping track of this group's length. - $length += mb_strlen($list->tokens[$idx]->value, 'UTF-8'); + $length += mb_strlen((string) $list->tokens[$idx]->value, 'UTF-8'); } return $length; diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index 7e6297f..9e3ae02 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -1,8 +1,8 @@ <?php - /** * Miscellaneous utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -32,12 +32,12 @@ class Misc || empty($statement->expr) || empty($statement->from) ) { - return array(); + return []; } - $retval = array(); + $retval = []; - $tables = array(); + $tables = []; /** * Expressions that may contain aliases. @@ -63,22 +63,22 @@ class Misc $expr->database : $database; if (! isset($retval[$thisDb])) { - $retval[$thisDb] = array( + $retval[$thisDb] = [ 'alias' => null, - 'tables' => array() - ); + 'tables' => [], + ]; } if (! isset($retval[$thisDb]['tables'][$expr->table])) { - $retval[$thisDb]['tables'][$expr->table] = array( + $retval[$thisDb]['tables'][$expr->table] = [ 'alias' => (isset($expr->alias) && ($expr->alias !== '')) ? $expr->alias : null, - 'columns' => array() - ); + 'columns' => [], + ]; } if (! isset($tables[$thisDb])) { - $tables[$thisDb] = array(); + $tables[$thisDb] = []; } $tables[$thisDb][$expr->alias] = $expr->table; } diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 2e623aa..7b14ded 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -1,8 +1,8 @@ <?php - /** * Statement utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -47,7 +47,7 @@ class Query * * @var array */ - public static $FUNCTIONS = array( + public static $FUNCTIONS = [ 'SUM', 'AVG', 'STD', @@ -55,10 +55,10 @@ class Query 'MIN', 'MAX', 'BIT_OR', - 'BIT_AND' - ); + 'BIT_AND', + ]; - public static $ALLFLAGS = array( + public static $ALLFLAGS = [ /* * select ... DISTINCT ... */ @@ -211,8 +211,8 @@ class Query /* * ... UNION ... */ - 'union' => false - ); + 'union' => false, + ]; /** * Gets an array with flags select statement has. @@ -300,7 +300,7 @@ class Query */ public static function getFlags($statement, $all = false) { - $flags = array('querytype' => false); + $flags = ['querytype' => false]; if ($all) { $flags = self::$ALLFLAGS; } @@ -416,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 - ); + isset($expr->database) ? $expr->database : null, + ]; } } @@ -439,11 +439,11 @@ class Query if (isset($tableAliases[$expr->table])) { $arr = $tableAliases[$expr->table]; } else { - $arr = array( + $arr = [ $expr->table, (isset($expr->database) && ($expr->database !== '')) ? - $expr->database : null - ); + $expr->database : null, + ]; } if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; @@ -459,11 +459,11 @@ class Query if (empty($ret['select_tables'])) { foreach ($statement->from as $expr) { if (isset($expr->table) && ($expr->table !== '')) { - $arr = array( + $arr = [ $expr->table, (isset($expr->database) && ($expr->database !== '')) ? - $expr->database : null - ); + $expr->database : null, + ]; if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; } @@ -484,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) @@ -499,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')) { // No tables are dropped. - return array(); + return []; } $expressions = $statement->fields; } elseif ($statement instanceof RenameStatement) { @@ -512,7 +512,7 @@ class Query } } - $ret = array(); + $ret = []; foreach ($expressions as $expr) { if (! empty($expr->table)) { $expr->expr = null; // Force rebuild. @@ -796,11 +796,11 @@ class Query // No statement was found so we return the entire query as being the // remaining part. if (! $fullStatement) { - return array( + return [ null, $query, - $delimiter - ); + $delimiter, + ]; } // At least one query was found so we have to build the rest of the @@ -810,11 +810,11 @@ class Query $query .= $list->tokens[$list->idx]->token; } - return array( + return [ trim($statement), $query, - $delimiter - ); + $delimiter, + ]; } /** diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 9b075dc..9842ff1 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -1,8 +1,8 @@ <?php - /** * Routine utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -36,27 +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) - ); + implode(' ', $options), + ]; } /** @@ -74,29 +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) - ); + implode(' ', $options), + ]; } /** @@ -108,15 +108,15 @@ 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() - ); + 'dir' => [], + 'name' => [], + 'type' => [], + 'length' => [], + 'length_arr' => [], + 'opts' => [], + ]; if (! empty($statement->parameters)) { $idx = 0; @@ -126,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 e73e430..140ed2a 100644 --- a/src/Utils/Table.php +++ b/src/Utils/Table.php @@ -1,8 +1,8 @@ <?php - /** * Table utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -30,25 +30,25 @@ class 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 - ); + 'index_list' => $columns, + ]; if (! empty($field->references)) { $tmp['ref_db_name'] = $field->references->table->database; @@ -87,10 +87,10 @@ class 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 - ); + '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 9166085..b7f5935 100644 --- a/src/Utils/Tokens.php +++ b/src/Utils/Tokens.php @@ -1,8 +1,8 @@ <?php - /** * Token utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -44,7 +44,7 @@ class Tokens } if (isset($pattern['value_str']) - && strcasecmp($pattern['value_str'], $token->value) + && strcasecmp($pattern['value_str'], (string) $token->value) ) { return false; } @@ -85,7 +85,7 @@ class Tokens * * @var array */ - $newList = array(); + $newList = []; /** * The length of the find pattern is calculated only once. |