diff options
author | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-08 21:32:02 -0200 |
---|---|---|
committer | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-16 17:21:25 -0200 |
commit | 86c5baebda24c1721fb6881df8671a3c7df60e8b (patch) | |
tree | 0a76d58ea229d1008e169b1c5b25ce90dde91808 /src/Statements | |
parent | 28427543566b6dd32fe44db704ea41368ba55c0e (diff) | |
download | sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.zip sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.gz sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.bz2 |
Apply phpmyadmin/coding-standard
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
Diffstat (limited to 'src/Statements')
23 files changed, 549 insertions, 239 deletions
diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php index e1c3f83..3909c42 100644 --- a/src/Statements/AlterStatement.php +++ b/src/Statements/AlterStatement.php @@ -35,14 +35,14 @@ class AlterStatement extends Statement * * @var AlterOperation[] */ - public $altered = array(); + public $altered = []; /** * Options of this statement. * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'ONLINE' => 1, 'OFFLINE' => 1, 'IGNORE' => 2, @@ -55,7 +55,7 @@ class AlterStatement extends Statement 'TABLE' => 3, 'TABLESPACE' => 3, 'VIEW' => 3, - ); + ]; /** * @param Parser $parser the instance that requests parsing @@ -75,10 +75,10 @@ class AlterStatement extends Statement $this->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); ++$list->idx; // Skipping field. @@ -114,7 +114,7 @@ class AlterStatement extends Statement } if ($state === 0) { - $options = array(); + $options = []; if ($this->options->has('DATABASE')) { $options = AlterOperation::$DB_OPTIONS; } elseif ($this->options->has('TABLE')) { @@ -138,7 +138,7 @@ class AlterStatement extends Statement */ public function build() { - $tmp = array(); + $tmp = []; foreach ($this->altered as $altered) { $tmp[] = $altered::build($altered); } diff --git a/src/Statements/AnalyzeStatement.php b/src/Statements/AnalyzeStatement.php index 0efbbde..4166bdb 100644 --- a/src/Statements/AnalyzeStatement.php +++ b/src/Statements/AnalyzeStatement.php @@ -26,12 +26,12 @@ class AnalyzeStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, 'LOCAL' => 3, - ); + ]; /** * Analyzed tables. diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php index bef39d4..0c8c314 100644 --- a/src/Statements/BackupStatement.php +++ b/src/Statements/BackupStatement.php @@ -22,12 +22,15 @@ class BackupStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, 'LOCAL' => 3, - 'TO' => array(4, 'var'), - ); + 'TO' => [ + 4, + 'var', + ], + ]; } diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php index dd4b134..690818c 100644 --- a/src/Statements/CheckStatement.php +++ b/src/Statements/CheckStatement.php @@ -22,7 +22,7 @@ class CheckStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'FOR UPGRADE' => 2, @@ -31,5 +31,5 @@ class CheckStatement extends MaintenanceStatement 'MEDIUM' => 5, 'EXTENDED' => 6, 'CHANGED' => 7, - ); + ]; } diff --git a/src/Statements/ChecksumStatement.php b/src/Statements/ChecksumStatement.php index b400e48..3ddca9a 100644 --- a/src/Statements/ChecksumStatement.php +++ b/src/Statements/ChecksumStatement.php @@ -22,10 +22,10 @@ class ChecksumStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'QUICK' => 2, 'EXTENDED' => 3, - ); + ]; } diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index 65cdbbb..61ffac2 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -32,16 +32,25 @@ class CreateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ // CREATE TABLE 'TEMPORARY' => 1, // CREATE VIEW 'OR REPLACE' => 2, - 'ALGORITHM' => array(3, 'var='), + 'ALGORITHM' => [ + 3, + 'var=', + ], // `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE` - 'DEFINER' => array(4, 'expr='), - 'SQL SECURITY' => array(5, 'var'), + 'DEFINER' => [ + 4, + 'expr=', + ], + 'SQL SECURITY' => [ + 5, + 'var', + ], 'DATABASE' => 6, 'EVENT' => 6, @@ -60,62 +69,158 @@ class CreateStatement extends Statement // CREATE TABLE 'IF NOT EXISTS' => 7, - ); + ]; /** * All database options. * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array(1, 'var='), - 'CHARSET' => array(1, 'var='), - 'DEFAULT CHARACTER SET' => array(1, 'var='), - 'DEFAULT CHARSET' => array(1, 'var='), - 'DEFAULT COLLATE' => array(2, 'var='), - 'COLLATE' => array(2, 'var='), - ); + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ + 1, + 'var=', + ], + 'CHARSET' => [ + 1, + 'var=', + ], + 'DEFAULT CHARACTER SET' => [ + 1, + 'var=', + ], + 'DEFAULT CHARSET' => [ + 1, + 'var=', + ], + 'DEFAULT COLLATE' => [ + 2, + 'var=', + ], + 'COLLATE' => [ + 2, + 'var=', + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array(1, 'var='), - 'AUTO_INCREMENT' => array(2, 'var='), - 'AVG_ROW_LENGTH' => array(3, 'var'), - 'CHARACTER SET' => array(4, 'var='), - 'CHARSET' => array(4, 'var='), - 'DEFAULT CHARACTER SET' => array(4, 'var='), - 'DEFAULT CHARSET' => array(4, 'var='), - 'CHECKSUM' => array(5, 'var'), - 'DEFAULT COLLATE' => array(6, 'var='), - 'COLLATE' => array(6, 'var='), - 'COMMENT' => array(7, 'var='), - 'CONNECTION' => array(8, 'var'), - 'DATA DIRECTORY' => array(9, 'var'), - 'DELAY_KEY_WRITE' => array(10, 'var'), - 'INDEX DIRECTORY' => array(11, 'var'), - 'INSERT_METHOD' => array(12, 'var'), - 'KEY_BLOCK_SIZE' => array(13, 'var'), - 'MAX_ROWS' => array(14, 'var'), - 'MIN_ROWS' => array(15, 'var'), - 'PACK_KEYS' => array(16, 'var'), - 'PASSWORD' => array(17, 'var'), - 'ROW_FORMAT' => array(18, 'var'), - 'TABLESPACE' => array(19, 'var'), - 'STORAGE' => array(20, 'var'), - 'UNION' => array(21, 'var'), - ); + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ + 1, + 'var=', + ], + 'AUTO_INCREMENT' => [ + 2, + 'var=', + ], + 'AVG_ROW_LENGTH' => [ + 3, + 'var', + ], + 'CHARACTER SET' => [ + 4, + 'var=', + ], + 'CHARSET' => [ + 4, + 'var=', + ], + 'DEFAULT CHARACTER SET' => [ + 4, + 'var=', + ], + 'DEFAULT CHARSET' => [ + 4, + 'var=', + ], + 'CHECKSUM' => [ + 5, + 'var', + ], + 'DEFAULT COLLATE' => [ + 6, + 'var=', + ], + 'COLLATE' => [ + 6, + 'var=', + ], + 'COMMENT' => [ + 7, + 'var=', + ], + 'CONNECTION' => [ + 8, + 'var', + ], + 'DATA DIRECTORY' => [ + 9, + 'var', + ], + 'DELAY_KEY_WRITE' => [ + 10, + 'var', + ], + 'INDEX DIRECTORY' => [ + 11, + 'var', + ], + 'INSERT_METHOD' => [ + 12, + 'var', + ], + 'KEY_BLOCK_SIZE' => [ + 13, + 'var', + ], + 'MAX_ROWS' => [ + 14, + 'var', + ], + 'MIN_ROWS' => [ + 15, + 'var', + ], + 'PACK_KEYS' => [ + 16, + 'var', + ], + 'PASSWORD' => [ + 17, + 'var', + ], + 'ROW_FORMAT' => [ + 18, + 'var', + ], + 'TABLESPACE' => [ + 19, + 'var', + ], + 'STORAGE' => [ + 20, + 'var', + ], + 'UNION' => [ + 21, + 'var', + ], + ]; /** * All function options. * * @var array */ - public static $FUNC_OPTIONS = array( - 'COMMENT' => array(1, 'var='), + public static $FUNC_OPTIONS = [ + 'COMMENT' => [ + 1, + 'var=', + ], 'LANGUAGE SQL' => 2, 'DETERMINISTIC' => 3, 'NOT DETERMINISTIC' => 3, @@ -123,21 +228,24 @@ class CreateStatement extends Statement 'NO SQL' => 4, 'READS SQL DATA' => 4, 'MODIFIES SQL DATA' => 4, - 'SQL SECURITY DEFINER' => array(5, 'var'), - ); + 'SQL SECURITY DEFINER' => [ + 5, + 'var', + ], + ]; /** * All trigger options. * * @var array */ - public static $TRIGGER_OPTIONS = array( + public static $TRIGGER_OPTIONS = [ 'BEFORE' => 1, 'AFTER' => 1, 'INSERT' => 2, 'UPDATE' => 2, 'DELETE' => 2, - ); + ]; /** * The name of the entity that is created. @@ -259,7 +367,7 @@ class CreateStatement extends Statement * * @var Token[]|string */ - public $body = array(); + public $body = []; /** * @return string @@ -267,7 +375,7 @@ class CreateStatement extends Statement public function build() { $fields = ''; - if (!empty($this->fields)) { + if (! empty($this->fields)) { if (is_array($this->fields)) { $fields = CreateDefinition::build($this->fields) . ' '; } elseif ($this->fields instanceof ArrayObj) { @@ -280,12 +388,12 @@ class CreateStatement extends Statement . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions); } elseif ($this->options->has('TABLE')) { - if (!is_null($this->select)) { + if (! is_null($this->select)) { return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $this->select->build(); - } elseif (!is_null($this->like)) { + } elseif (! is_null($this->like)) { return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' LIKE ' @@ -293,19 +401,19 @@ class CreateStatement extends Statement } else { $partition = ''; - if (!empty($this->partitionBy)) { + if (! empty($this->partitionBy)) { $partition .= "\nPARTITION BY " . $this->partitionBy; } - if (!empty($this->partitionsNum)) { + if (! empty($this->partitionsNum)) { $partition .= "\nPARTITIONS " . $this->partitionsNum; } - if (!empty($this->subpartitionBy)) { + if (! empty($this->subpartitionBy)) { $partition .= "\nSUBPARTITION BY " . $this->subpartitionBy; } - if (!empty($this->subpartitionsNum)) { + if (! empty($this->subpartitionsNum)) { $partition .= "\nSUBPARTITIONS " . $this->subpartitionsNum; } - if (!empty($this->partitions)) { + if (! empty($this->partitions)) { $partition .= "\n" . PartitionDefinition::build($this->partitions); } @@ -366,13 +474,13 @@ class CreateStatement extends Statement $this->name = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); - if (!isset($this->name) || ($this->name === '')) { + if (! isset($this->name) || ($this->name === '')) { $parser->error( 'The name of the entity was expected.', $list->tokens[$list->idx] @@ -416,10 +524,10 @@ class CreateStatement extends Statement $this->like = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); // The 'LIKE' keyword was found, but no table_name was found next to it if (is_null($this->like)) { @@ -496,7 +604,7 @@ class CreateStatement extends Statement $token = $list->getNextOfType(Token::TYPE_NUMBER); --$list->idx; // `getNextOfType` also advances one position. $this->subpartitionsNum = $token->value; - } elseif (!empty($field)) { + } elseif (! empty($field)) { /* * Handling the content of `PARTITION BY` and `SUBPARTITION BY`. */ @@ -525,13 +633,13 @@ class CreateStatement extends Statement $field = null; } } elseif (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { - if (!empty($this->partitionBy)) { + if (! empty($this->partitionBy)) { $this->partitions = ArrayObj::parse( $parser, $list, - array( + [ 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', - ) + ] ); } break; @@ -606,10 +714,10 @@ class CreateStatement extends Statement $this->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); ++$list->idx; diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 7ff0025..879fe2e 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -54,11 +54,11 @@ class DeleteStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'QUICK' => 2, 'IGNORE' => 3, - ); + ]; /** * The clauses of this statement, in order. @@ -67,17 +67,41 @@ class DeleteStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DELETE' => array('DELETE', 2), + public static $CLAUSES = [ + 'DELETE' => [ + 'DELETE', + 2, + ], // Used for options. - '_OPTIONS' => array('_OPTIONS', 1), - 'FROM' => array('FROM', 3), - 'PARTITION' => array('PARTITION', 3), - 'USING' => array('USING', 3), - 'WHERE' => array('WHERE', 3), - 'ORDER BY' => array('ORDER BY', 3), - 'LIMIT' => array('LIMIT', 3), - ); + '_OPTIONS' => [ + '_OPTIONS', + 1, + ], + 'FROM' => [ + 'FROM', + 3, + ], + 'PARTITION' => [ + 'PARTITION', + 3, + ], + 'USING' => [ + 'USING', + 3, + ], + 'WHERE' => [ + 'WHERE', + 3, + ], + 'ORDER BY' => [ + 'ORDER BY', + 3, + ], + 'LIMIT' => [ + 'LIMIT', + 3, + ], + ]; /** * Table(s) used as sources for this statement. @@ -142,25 +166,25 @@ class DeleteStatement extends Statement { $ret = 'DELETE ' . OptionsArray::build($this->options); - if (!is_null($this->columns) && count($this->columns) > 0) { + if (! is_null($this->columns) && count($this->columns) > 0) { $ret .= ' ' . ExpressionArray::build($this->columns); } - if (!is_null($this->from) && count($this->from) > 0) { + if (! is_null($this->from) && count($this->from) > 0) { $ret .= ' FROM ' . ExpressionArray::build($this->from); } - if (!is_null($this->join) && count($this->join) > 0) { + if (! is_null($this->join) && count($this->join) > 0) { $ret .= ' ' . JoinKeyword::build($this->join); } - if (!is_null($this->using) && count($this->using) > 0) { + if (! is_null($this->using) && count($this->using) > 0) { $ret .= ' USING ' . ExpressionArray::build($this->using); } - if (!is_null($this->where) && count($this->where) > 0) { + if (! is_null($this->where) && count($this->where) > 0) { $ret .= ' WHERE ' . Condition::build($this->where); } - if (!is_null($this->order) && count($this->order) > 0) { + if (! is_null($this->order) && count($this->order) > 0) { $ret .= ' ORDER BY ' . ExpressionArray::build($this->order); } - if (!is_null($this->limit) && strlen($this->limit) > 0) { + if (! is_null($this->limit) && strlen($this->limit) > 0) { $ret .= ' LIMIT ' . Limit::build($this->limit); } @@ -257,34 +281,33 @@ class DeleteStatement extends Statement $this->join = JoinKeyword::parse($parser, $list); // remain in state = 2 - } - else { - switch($token->keyword) { + } else { + switch ($token->keyword) { case 'USING': ++$list->idx; // Skip 'USING' $this->using = ExpressionArray::parse($parser, $list); $state = 3; $multiTable = true; - break; + break; case 'WHERE': ++$list->idx; // Skip 'WHERE' $this->where = Condition::parse($parser, $list); $state = 4; - break; + break; case 'ORDER BY': ++$list->idx; // Skip 'ORDER BY' $this->order = OrderKeyword::parse($parser, $list); $state = 5; - break; + break; case 'LIMIT': ++$list->idx; // Skip 'LIMIT' $this->limit = Limit::parse($parser, $list); $state = 6; - break; + break; default: $parser->error('Unexpected keyword.', $token); - break 2; + break 2; } } } @@ -314,20 +337,20 @@ class DeleteStatement extends Statement } if ($token->type === Token::TYPE_KEYWORD) { - switch($token->keyword) { + switch ($token->keyword) { case 'ORDER BY': ++$list->idx; // Skip 'ORDER BY' $this->order = OrderKeyword::parse($parser, $list); $state = 5; - break; + break; case 'LIMIT': ++$list->idx; // Skip 'LIMIT' $this->limit = Limit::parse($parser, $list); $state = 6; - break; + break; default: $parser->error('Unexpected keyword.', $token); - break 2; + break 2; } } } elseif ($state === 5) { diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php index 1572a55..1ec1c72 100644 --- a/src/Statements/DropStatement.php +++ b/src/Statements/DropStatement.php @@ -23,7 +23,7 @@ class DropStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'DATABASE' => 1, 'EVENT' => 1, 'FUNCTION' => 1, @@ -39,7 +39,7 @@ class DropStatement extends Statement 'TEMPORARY' => 2, 'IF EXISTS' => 3, - ); + ]; /** * The clauses of this statement, in order. @@ -48,14 +48,26 @@ class DropStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DROP' => array('DROP', 2), + public static $CLAUSES = [ + 'DROP' => [ + 'DROP', + 2, + ], // Used for options. - '_OPTIONS' => array('_OPTIONS', 1), + '_OPTIONS' => [ + '_OPTIONS', + 1, + ], // Used for select expressions. - 'DROP_' => array('DROP', 1), - 'ON' => array('ON', 3), - ); + 'DROP_' => [ + 'DROP', + 1, + ], + 'ON' => [ + 'ON', + 3, + ], + ]; /** * Dropped elements. diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index 312b4e0..f2b6348 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -60,12 +60,12 @@ class InsertStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'DELAYED' => 2, 'HIGH_PRIORITY' => 3, 'IGNORE' => 4, - ); + ]; /** * Tables used as target for this statement. @@ -113,15 +113,15 @@ class InsertStatement extends Statement $ret = 'INSERT ' . $this->options . ' INTO ' . $this->into; - if (!is_null($this->values) && count($this->values) > 0) { + if (! is_null($this->values) && count($this->values) > 0) { $ret .= ' VALUES ' . Array2d::build($this->values); - } elseif (!is_null($this->set) && count($this->set) > 0) { + } elseif (! is_null($this->set) && count($this->set) > 0) { $ret .= ' SET ' . SetOperation::build($this->set); - } elseif (!is_null($this->select) && strlen($this->select) > 0) { + } elseif (! is_null($this->select) && strlen($this->select) > 0) { $ret .= ' ' . $this->select->build(); } - if (!is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) { + if (! is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) { $ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet); } @@ -195,7 +195,7 @@ class InsertStatement extends Statement $this->into = IntoKeyword::parse( $parser, $list, - array('fromInsert' => true) + ['fromInsert' => true] ); $state = 1; diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php index 45ad05f..c9179aa 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -49,33 +49,48 @@ class LoadStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'CONCURRENT' => 1, 'LOCAL' => 2, - ); + ]; /** * FIELDS/COLUMNS Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array(1, 'expr'), + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ + 1, + 'expr', + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array(3, 'expr'), - 'ESCAPED BY' => array(4, 'expr'), - ); + 'ENCLOSED BY' => [ + 3, + 'expr', + ], + 'ESCAPED BY' => [ + 4, + 'expr', + ], + ]; /** * LINES Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array(1, 'expr'), - 'TERMINATED BY' => array(2, 'expr'), - ); + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ + 1, + 'expr', + ], + 'TERMINATED BY' => [ + 2, + 'expr', + ], + ]; /** * File name being used to load data. @@ -266,7 +281,7 @@ class LoadStatement extends Statement $this->file_name = Expression::parse( $parser, $list, - array('parseField' => 'file') + ['parseField' => 'file'] ); $state = 1; } elseif ($state === 1) { @@ -283,7 +298,7 @@ class LoadStatement extends Statement && $token->keyword === 'TABLE' ) { ++$list->idx; - $this->table = Expression::parse($parser, $list, array('parseField' => 'table')); + $this->table = Expression::parse($parser, $list, ['parseField' => 'table']); $state = 3; } else { $parser->error('Unexpected token.', $token); @@ -292,7 +307,9 @@ class LoadStatement extends Statement } elseif ($state >= 3 && $state <= 7) { if ($token->type === Token::TYPE_KEYWORD) { $newState = $this->parseKeywordsAccordingToState( - $parser, $list, $state + $parser, + $list, + $state ); if ($newState === $state) { // Avoid infinite loop diff --git a/src/Statements/LockStatement.php b/src/Statements/LockStatement.php index 2ba70c4..354d446 100644 --- a/src/Statements/LockStatement.php +++ b/src/Statements/LockStatement.php @@ -26,7 +26,7 @@ class LockStatement extends Statement * * @var LockExpression[] */ - public $locked = array(); + public $locked = []; /** * Whether it's a LOCK statement @@ -95,7 +95,7 @@ class LockStatement extends Statement break; } } elseif ($state === 1) { - if (!$this->isLock) { + if (! $this->isLock) { // UNLOCK statement should not have any more tokens $parser->error('Unexpected token.', $token); break; diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php index e534cdf..f5da4a1 100644 --- a/src/Statements/NotImplementedStatement.php +++ b/src/Statements/NotImplementedStatement.php @@ -27,7 +27,7 @@ class NotImplementedStatement extends Statement * * @var Token[] */ - public $unknown = array(); + public $unknown = []; /** * @return string diff --git a/src/Statements/OptimizeStatement.php b/src/Statements/OptimizeStatement.php index 0d88e76..19c95e5 100644 --- a/src/Statements/OptimizeStatement.php +++ b/src/Statements/OptimizeStatement.php @@ -26,12 +26,12 @@ class OptimizeStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, 'LOCAL' => 3, - ); + ]; /** * Optimized tables. diff --git a/src/Statements/PurgeStatement.php b/src/Statements/PurgeStatement.php index 0374813..79a684f 100644 --- a/src/Statements/PurgeStatement.php +++ b/src/Statements/PurgeStatement.php @@ -92,19 +92,19 @@ class PurgeStatement extends Statement switch ($state) { case 0: // parse `{ BINARY | MASTER }` - $this->log_type = self::parseExpectedKeyword($parser, $token, array('BINARY', 'MASTER')); + $this->log_type = self::parseExpectedKeyword($parser, $token, ['BINARY', 'MASTER']); break; case 1: // parse `LOGS` - self::parseExpectedKeyword($parser, $token, array('LOGS')); + self::parseExpectedKeyword($parser, $token, ['LOGS']); break; case 2: // parse `{ TO | BEFORE }` - $this->end_option = self::parseExpectedKeyword($parser, $token, array('TO', 'BEFORE')); + $this->end_option = self::parseExpectedKeyword($parser, $token, ['TO', 'BEFORE']); break; case 3: // parse `expr` - $this->end_expr = Expression::parse($parser, $list, array()); + $this->end_expr = Expression::parse($parser, $list, []); break; default: $parser->error('Unexpected token.', $token); diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php index c16d603..a9e058a 100644 --- a/src/Statements/RepairStatement.php +++ b/src/Statements/RepairStatement.php @@ -24,7 +24,7 @@ class RepairStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, @@ -33,5 +33,5 @@ class RepairStatement extends MaintenanceStatement 'QUICK' => 4, 'EXTENDED' => 5, 'USE_FRM' => 6, - ); + ]; } diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index 40b1194..72e6841 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -47,10 +47,10 @@ class ReplaceStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'DELAYED' => 1, - ); + ]; /** * Tables used as target for this statement. @@ -89,11 +89,11 @@ class ReplaceStatement extends Statement { $ret = 'REPLACE ' . $this->options . ' INTO ' . $this->into; - if (!is_null($this->values) && count($this->values) > 0) { + if (! is_null($this->values) && count($this->values) > 0) { $ret .= ' VALUES ' . Array2d::build($this->values); - } elseif (!is_null($this->set) && count($this->set) > 0) { + } elseif (! is_null($this->set) && count($this->set) > 0) { $ret .= ' SET ' . SetOperation::build($this->set); - } elseif (!is_null($this->select) && strlen($this->select) > 0) { + } elseif (! is_null($this->select) && strlen($this->select) > 0) { $ret .= ' ' . $this->select->build(); } @@ -159,7 +159,7 @@ class ReplaceStatement extends Statement $this->into = IntoKeyword::parse( $parser, $list, - array('fromReplace' => true) + ['fromReplace' => true] ); $state = 1; diff --git a/src/Statements/RestoreStatement.php b/src/Statements/RestoreStatement.php index db07ac4..6a2b44f 100644 --- a/src/Statements/RestoreStatement.php +++ b/src/Statements/RestoreStatement.php @@ -22,9 +22,12 @@ class RestoreStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, - 'FROM' => array(2, 'var'), - ); + 'FROM' => [ + 2, + 'var', + ], + ]; } diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index fbcae48..1bff148 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -56,12 +56,15 @@ class SelectStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'ALL' => 1, 'DISTINCT' => 1, 'DISTINCTROW' => 1, 'HIGH_PRIORITY' => 2, - 'MAX_STATEMENT_TIME' => array(3, 'var='), + 'MAX_STATEMENT_TIME' => [ + 3, + 'var=', + ], 'STRAIGHT_JOIN' => 4, 'SQL_SMALL_RESULT' => 5, 'SQL_BIG_RESULT' => 6, @@ -69,12 +72,12 @@ class SelectStatement extends Statement 'SQL_CACHE' => 8, 'SQL_NO_CACHE' => 8, 'SQL_CALC_FOUND_ROWS' => 9, - ); + ]; - public static $END_OPTIONS = array( + public static $END_OPTIONS = [ 'FOR UPDATE' => 1, 'LOCK IN SHARE MODE' => 1, - ); + ]; /** * The clauses of this statement, in order. @@ -83,60 +86,153 @@ class SelectStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SELECT' => array('SELECT', 2), + public static $CLAUSES = [ + 'SELECT' => [ + 'SELECT', + 2, + ], // Used for options. - '_OPTIONS' => array('_OPTIONS', 1), + '_OPTIONS' => [ + '_OPTIONS', + 1, + ], // Used for selected expressions. - '_SELECT' => array('SELECT', 1), - 'INTO' => array('INTO', 3), - 'FROM' => array('FROM', 3), - 'FORCE' => array('FORCE', 1), - 'USE' => array('USE', 1), - 'IGNORE' => array('IGNORE', 3), - 'PARTITION' => array('PARTITION', 3), - - 'JOIN' => array('JOIN', 1), - 'FULL JOIN' => array('FULL JOIN', 1), - 'INNER JOIN' => array('INNER JOIN', 1), - 'LEFT JOIN' => array('LEFT JOIN', 1), - 'LEFT OUTER JOIN' => array('LEFT OUTER JOIN', 1), - 'RIGHT JOIN' => array('RIGHT JOIN', 1), - 'RIGHT OUTER JOIN' => array('RIGHT OUTER JOIN', 1), - 'NATURAL JOIN' => array('NATURAL JOIN', 1), - 'NATURAL LEFT JOIN' => array('NATURAL LEFT JOIN', 1), - 'NATURAL RIGHT JOIN' => array('NATURAL RIGHT JOIN', 1), - 'NATURAL LEFT OUTER JOIN' => array('NATURAL LEFT OUTER JOIN', 1), - 'NATURAL RIGHT OUTER JOIN' => array('NATURAL RIGHT JOIN', 1), - - 'WHERE' => array('WHERE', 3), - 'GROUP BY' => array('GROUP BY', 3), - 'HAVING' => array('HAVING', 3), - 'ORDER BY' => array('ORDER BY', 3), - 'LIMIT' => array('LIMIT', 3), - 'PROCEDURE' => array('PROCEDURE', 3), - 'UNION' => array('UNION', 1), - 'EXCEPT' => array('EXCEPT', 1), - 'INTERSECT' => array('INTERSECT', 1), - '_END_OPTIONS' => array('_END_OPTIONS', 1), + '_SELECT' => [ + 'SELECT', + 1, + ], + 'INTO' => [ + 'INTO', + 3, + ], + 'FROM' => [ + 'FROM', + 3, + ], + 'FORCE' => [ + 'FORCE', + 1, + ], + 'USE' => [ + 'USE', + 1, + ], + 'IGNORE' => [ + 'IGNORE', + 3, + ], + 'PARTITION' => [ + 'PARTITION', + 3, + ], + + 'JOIN' => [ + 'JOIN', + 1, + ], + 'FULL JOIN' => [ + 'FULL JOIN', + 1, + ], + 'INNER JOIN' => [ + 'INNER JOIN', + 1, + ], + 'LEFT JOIN' => [ + 'LEFT JOIN', + 1, + ], + 'LEFT OUTER JOIN' => [ + 'LEFT OUTER JOIN', + 1, + ], + 'RIGHT JOIN' => [ + 'RIGHT JOIN', + 1, + ], + 'RIGHT OUTER JOIN' => [ + 'RIGHT OUTER JOIN', + 1, + ], + 'NATURAL JOIN' => [ + 'NATURAL JOIN', + 1, + ], + 'NATURAL LEFT JOIN' => [ + 'NATURAL LEFT JOIN', + 1, + ], + 'NATURAL RIGHT JOIN' => [ + 'NATURAL RIGHT JOIN', + 1, + ], + 'NATURAL LEFT OUTER JOIN' => [ + 'NATURAL LEFT OUTER JOIN', + 1, + ], + 'NATURAL RIGHT OUTER JOIN' => [ + 'NATURAL RIGHT JOIN', + 1, + ], + + 'WHERE' => [ + 'WHERE', + 3, + ], + 'GROUP BY' => [ + 'GROUP BY', + 3, + ], + 'HAVING' => [ + 'HAVING', + 3, + ], + 'ORDER BY' => [ + 'ORDER BY', + 3, + ], + 'LIMIT' => [ + 'LIMIT', + 3, + ], + 'PROCEDURE' => [ + 'PROCEDURE', + 3, + ], + 'UNION' => [ + 'UNION', + 1, + ], + 'EXCEPT' => [ + 'EXCEPT', + 1, + ], + 'INTERSECT' => [ + 'INTERSECT', + 1, + ], + '_END_OPTIONS' => [ + '_END_OPTIONS', + 1, + ], // These are available only when `UNION` is present. // 'ORDER BY' => array('ORDER BY', 3), // 'LIMIT' => array('LIMIT', 3), - ); + ]; /** * Expressions that are being selected by this statement. * * @var Expression[] */ - public $expr = array(); + public $expr = []; /** * Tables used as sources for this statement. * * @var Expression[] */ - public $from = array(); + public $from = []; /** * Index hints @@ -213,7 +309,7 @@ class SelectStatement extends Statement * * @var SelectStatement[] */ - public $union = array(); + public $union = []; /** * The end options of this query. @@ -234,11 +330,17 @@ class SelectStatement extends Statement // This is a cheap fix for `SELECT` statements that contain `UNION`. // The `ORDER BY` and `LIMIT` clauses should be at the end of the // statement. - if (!empty($this->union)) { + if (! empty($this->union)) { $clauses = static::$CLAUSES; unset($clauses['ORDER BY'], $clauses['LIMIT']); - $clauses['ORDER BY'] = array('ORDER BY', 3); - $clauses['LIMIT'] = array('LIMIT', 3); + $clauses['ORDER BY'] = [ + 'ORDER BY', + 3, + ]; + $clauses['LIMIT'] = [ + 'LIMIT', + 3, + ]; return $clauses; } diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php index ef3a0c1..129cc14 100644 --- a/src/Statements/SetStatement.php +++ b/src/Statements/SetStatement.php @@ -26,27 +26,48 @@ class SetStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SET' => array('SET', 3), - '_END_OPTIONS' => array('_END_OPTIONS', 1), - ); + public static $CLAUSES = [ + 'SET' => [ + 'SET', + 3, + ], + '_END_OPTIONS' => [ + '_END_OPTIONS', + 1, + ], + ]; /** * Possible exceptions in SET statment. * * @var array */ - public static $OPTIONS = array( - 'CHARSET' => array(3, 'var'), - 'CHARACTER SET' => array(3, 'var'), - 'NAMES' => array(3, 'var'), - 'PASSWORD' => array(3, 'expr'), - ); + public static $OPTIONS = [ + 'CHARSET' => [ + 3, + 'var', + ], + 'CHARACTER SET' => [ + 3, + 'var', + ], + 'NAMES' => [ + 3, + 'var', + ], + 'PASSWORD' => [ + 3, + 'expr', + ], + ]; - public static $END_OPTIONS = array( - 'COLLATE' => array(1, 'var'), - 'DEFAULT' => 1 - ); + public static $END_OPTIONS = [ + 'COLLATE' => [ + 1, + 'var', + ], + 'DEFAULT' => 1, + ]; /** * Options used in current statement. diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php index 1568177..4205310 100644 --- a/src/Statements/ShowStatement.php +++ b/src/Statements/ShowStatement.php @@ -20,7 +20,7 @@ class ShowStatement extends NotImplementedStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'CREATE' => 1, 'AUTHORS' => 2, 'BINARY' => 2, @@ -62,5 +62,5 @@ class ShowStatement extends NotImplementedStatement 'VARIABLES' => 2, 'VIEW' => 2, 'WARNINGS' => 2, - ); + ]; } diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php index cfdc25c..fae935a 100644 --- a/src/Statements/TransactionStatement.php +++ b/src/Statements/TransactionStatement.php @@ -60,7 +60,7 @@ class TransactionStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'START TRANSACTION' => 1, 'BEGIN' => 1, 'COMMIT' => 1, @@ -71,7 +71,7 @@ class TransactionStatement extends Statement 'AND CHAIN' => 3, 'RELEASE' => 4, 'NO RELEASE' => 4, - ); + ]; /** * @param Parser $parser the instance that requests parsing diff --git a/src/Statements/TruncateStatement.php b/src/Statements/TruncateStatement.php index b625bc6..c95dfd0 100644 --- a/src/Statements/TruncateStatement.php +++ b/src/Statements/TruncateStatement.php @@ -23,9 +23,9 @@ class TruncateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, - ); + ]; /** * The name of the truncated table. diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php index b0aba01..2dee189 100644 --- a/src/Statements/UpdateStatement.php +++ b/src/Statements/UpdateStatement.php @@ -39,10 +39,10 @@ class UpdateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'IGNORE' => 2, - ); + ]; /** * The clauses of this statement, in order. @@ -51,17 +51,38 @@ class UpdateStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'UPDATE' => array('UPDATE', 2), + public static $CLAUSES = [ + 'UPDATE' => [ + 'UPDATE', + 2, + ], // Used for options. - '_OPTIONS' => array('_OPTIONS', 1), + '_OPTIONS' => [ + '_OPTIONS', + 1, + ], // Used for updated tables. - '_UPDATE' => array('UPDATE', 1), - 'SET' => array('SET', 3), - 'WHERE' => array('WHERE', 3), - 'ORDER BY' => array('ORDER BY', 3), - 'LIMIT' => array('LIMIT', 3), - ); + '_UPDATE' => [ + 'UPDATE', + 1, + ], + 'SET' => [ + 'SET', + 3, + ], + 'WHERE' => [ + 'WHERE', + 3, + ], + 'ORDER BY' => [ + 'ORDER BY', + 3, + ], + 'LIMIT' => [ + 'LIMIT', + 3, + ], + ]; /** * Tables used as sources for this statement. |