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/Components | |
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/Components')
25 files changed, 423 insertions, 265 deletions
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index e3893f7..25a62a5 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -25,28 +25,67 @@ class AlterOperation extends Component * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array(1, 'var'), - 'CHARSET' => array(1, 'var'), - 'DEFAULT CHARACTER SET' => array(1, 'var'), - 'DEFAULT CHARSET' => array(1, 'var'), - 'UPGRADE' => array(1, 'var'), - 'COLLATE' => array(2, 'var'), - 'DEFAULT COLLATE' => array(2, 'var'), - ); + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ + 1, + 'var', + ], + 'CHARSET' => [ + 1, + 'var', + ], + 'DEFAULT CHARACTER SET' => [ + 1, + 'var', + ], + 'DEFAULT CHARSET' => [ + 1, + 'var', + ], + 'UPGRADE' => [ + 1, + 'var', + ], + 'COLLATE' => [ + 2, + 'var', + ], + 'DEFAULT COLLATE' => [ + 2, + 'var', + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array(1, 'var='), - 'AUTO_INCREMENT' => array(1, 'var='), - 'AVG_ROW_LENGTH' => array(1, 'var'), - 'MAX_ROWS' => array(1, 'var'), - 'ROW_FORMAT' => array(1, 'var'), - 'COMMENT' => array(1, 'var'), + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ + 1, + 'var=', + ], + 'AUTO_INCREMENT' => [ + 1, + 'var=', + ], + 'AVG_ROW_LENGTH' => [ + 1, + 'var', + ], + 'MAX_ROWS' => [ + 1, + 'var', + ], + 'ROW_FORMAT' => [ + 1, + 'var', + ], + 'COMMENT' => [ + 1, + 'var', + ], 'ADD' => 1, 'ALTER' => 1, 'ANALYZE' => 1, @@ -84,16 +123,16 @@ class AlterOperation extends Component 'SPATIAL' => 2, 'TABLESPACE' => 2, 'INDEX' => 2, - ); + ]; /** * All view options. * * @var array */ - public static $VIEW_OPTIONS = array( + public static $VIEW_OPTIONS = [ 'AS' => 1, - ); + ]; /** * Options of this operation. @@ -114,7 +153,7 @@ class AlterOperation extends Component * * @var Token[]|string */ - public $unknown = array(); + public $unknown = []; /** * Constructor. @@ -126,7 +165,7 @@ class AlterOperation extends Component public function __construct( $options = null, $field = null, - $unknown = array() + $unknown = [] ) { $this->options = $options; $this->field = $field; @@ -140,7 +179,7 @@ class AlterOperation extends Component * * @return AlterOperation */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -212,10 +251,10 @@ class AlterOperation extends Component $ret->field = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, 'parseField' => 'column', - ) + ] ); if ($ret->field === null) { // No field was read. We go back one token so the next @@ -232,11 +271,11 @@ class AlterOperation extends Component } elseif (($token->value === ',') && ($brackets === 0)) { break; } - } elseif (!empty(Parser::$STATEMENT_PARSERS[$token->value])) { + } elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) { // We have reached the end of ALTER operation and suddenly found // a start to new statement, but have not find a delimiter between them - if (!($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) { + if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) { $parser->error( 'A new statement was found, but no delimiter between it and the previous one.', $token @@ -245,7 +284,7 @@ class AlterOperation extends Component } } elseif (array_key_exists($token->value, self::$DB_OPTIONS) || (array_key_exists($token->value, self::$TABLE_OPTIONS) - && !self::checkIfColumnDefinitionKeyword($token->value)) + && ! self::checkIfColumnDefinitionKeyword($token->value)) ) { // This alter operation has finished, which means a comma was missing before start of new alter operation $parser->error( @@ -276,7 +315,7 @@ class AlterOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = $component->options . ' '; if ((isset($component->field)) && ($component->field !== '')) { @@ -293,8 +332,13 @@ class AlterOperation extends Component * * @param string $tokenValue Value of current token */ - private static function checkIfColumnDefinitionKeyword($tokenValue) { - $common_options = array('AUTO_INCREMENT', 'COMMENT', 'DEFAULT'); + private static function checkIfColumnDefinitionKeyword($tokenValue) + { + $common_options = [ + 'AUTO_INCREMENT', + 'COMMENT', + 'DEFAULT', + ]; // Since AUTO_INCREMENT and COMMENT can be used for // both table as well as a specific column in the table return in_array($tokenValue, $common_options); diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php index 984179c..ced529a 100644 --- a/src/Components/Array2d.php +++ b/src/Components/Array2d.php @@ -28,9 +28,9 @@ class Array2d extends Component * * @return ArrayObj[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; /** * The number of values in each set. @@ -124,7 +124,7 @@ class Array2d extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return ArrayObj::build($component); } diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index e86ddfd..f968d87 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -25,14 +25,14 @@ class ArrayObj extends Component * * @var array */ - public $raw = array(); + public $raw = []; /** * The array that contains the processed value of each token. * * @var array */ - public $values = array(); + public $values = []; /** * Constructor. @@ -40,7 +40,7 @@ class ArrayObj extends Component * @param array $raw the unprocessed values * @param array $values the processed values */ - public function __construct(array $raw = array(), array $values = array()) + public function __construct(array $raw = [], array $values = []) { $this->raw = $raw; $this->values = $values; @@ -53,9 +53,9 @@ class ArrayObj extends Component * * @return ArrayObj|Component[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = empty($options['type']) ? new self() : array(); + $ret = empty($options['type']) ? new self() : []; /** * The last raw expression. @@ -144,7 +144,7 @@ class ArrayObj extends Component $ret[] = $options['type']::parse( $parser, $list, - empty($options['typeOptions']) ? array() : $options['typeOptions'] + empty($options['typeOptions']) ? [] : $options['typeOptions'] ); } } @@ -176,11 +176,11 @@ class ArrayObj extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); - } elseif (!empty($component->raw)) { + } elseif (! empty($component->raw)) { return '(' . implode(', ', $component->raw) . ')'; } diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php index ab90768..d66ddc3 100644 --- a/src/Components/CaseExpression.php +++ b/src/Components/CaseExpression.php @@ -84,7 +84,7 @@ class CaseExpression extends Component * * @return CaseExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -121,26 +121,26 @@ class CaseExpression extends Component if ($state === 0) { if ($token->type === Token::TYPE_KEYWORD) { - switch($token->keyword) { + switch ($token->keyword) { case 'WHEN': ++$list->idx; // Skip 'WHEN' $new_condition = Condition::parse($parser, $list); $type = 1; $state = 1; $ret->conditions[] = $new_condition; - break; + break; case 'ELSE': ++$list->idx; // Skip 'ELSE' $ret->else_result = Expression::parse($parser, $list); $state = 0; // last clause of CASE expression - break; + break; case 'END': $state = 3; // end of CASE expression ++$list->idx; - break 2; + break 2; default: $parser->error('Unexpected keyword.', $token); - break 2; + break 2; } } else { $ret->value = Expression::parse($parser, $list); @@ -150,25 +150,25 @@ class CaseExpression extends Component } elseif ($state === 1) { if ($type === 0) { if ($token->type === Token::TYPE_KEYWORD) { - switch($token->keyword) { + switch ($token->keyword) { case 'WHEN': ++$list->idx; // Skip 'WHEN' $new_value = Expression::parse($parser, $list); $state = 2; $ret->compare_values[] = $new_value; - break; + break; case 'ELSE': ++$list->idx; // Skip 'ELSE' $ret->else_result = Expression::parse($parser, $list); $state = 0; // last clause of CASE expression - break; + break; case 'END': $state = 3; // end of CASE expression ++$list->idx; - break 2; + break 2; default: $parser->error('Unexpected keyword.', $token); - break 2; + break 2; } } } else { @@ -227,7 +227,7 @@ class CaseExpression extends Component // Handle optional AS keyword before alias if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'AS') { - if ($asFound || !empty($ret->alias)) { + if ($asFound || ! empty($ret->alias)) { $parser->error('Potential duplicate alias of CASE expression.', $token); break; } @@ -245,11 +245,11 @@ class CaseExpression extends Component if ($asFound || $token->type === Token::TYPE_STRING - || ($token->type === Token::TYPE_SYMBOL && !$token->flags & Token::FLAG_SYMBOL_VARIABLE) + || ($token->type === Token::TYPE_SYMBOL && ! $token->flags & Token::FLAG_SYMBOL_VARIABLE) || $token->type === Token::TYPE_NONE ) { // An alias is expected (the keyword `AS` was previously found). - if (!empty($ret->alias)) { + if (! empty($ret->alias)) { $parser->error('An alias was previously found.', $token); break; } @@ -279,7 +279,7 @@ class CaseExpression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = 'CASE '; if (isset($component->value)) { diff --git a/src/Components/Condition.php b/src/Components/Condition.php index 2be0abd..83b80b2 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -25,14 +25,20 @@ class Condition extends Component * * @var array */ - public static $DELIMITERS = array('&&', '||', 'AND', 'OR', 'XOR'); + public static $DELIMITERS = [ + '&&', + '||', + 'AND', + 'OR', + 'XOR', + ]; /** * List of allowed reserved keywords in conditions. * * @var array */ - public static $ALLOWED_KEYWORDS = array( + public static $ALLOWED_KEYWORDS = [ 'ALL' => 1, 'AND' => 1, 'BETWEEN' => 1, @@ -51,14 +57,14 @@ class Condition extends Component 'REGEXP' => 1, 'RLIKE' => 1, 'XOR' => 1, - ); + ]; /** * Identifiers recognized. * * @var array */ - public $identifiers = array(); + public $identifiers = []; /** * Whether this component is an operator. @@ -91,9 +97,9 @@ class Condition extends Component * * @return Condition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -148,7 +154,7 @@ class Condition extends Component } else { // The expression ended. $expr->expr = trim($expr->expr); - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } @@ -165,7 +171,7 @@ class Condition extends Component if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED) - && !($token->flags & Token::FLAG_KEYWORD_FUNCTION) + && ! ($token->flags & Token::FLAG_KEYWORD_FUNCTION) ) { if ($token->value === 'BETWEEN') { $betweenBefore = true; @@ -189,11 +195,11 @@ class Condition extends Component $expr->expr .= $token->token; if (($token->type === Token::TYPE_NONE) || (($token->type === Token::TYPE_KEYWORD) - && (!($token->flags & Token::FLAG_KEYWORD_RESERVED))) + && (! ($token->flags & Token::FLAG_KEYWORD_RESERVED))) || ($token->type === Token::TYPE_STRING) || ($token->type === Token::TYPE_SYMBOL) ) { - if (!in_array($token->value, $expr->identifiers)) { + if (! in_array($token->value, $expr->identifiers)) { $expr->identifiers[] = $token->value; } } @@ -201,7 +207,7 @@ class Condition extends Component // Last iteration was not processed. $expr->expr = trim($expr->expr); - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } @@ -216,7 +222,7 @@ class Condition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(' ', $component); diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index 21ddae9..ccf8497 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -30,30 +30,53 @@ class CreateDefinition extends Component * * @var array */ - public static $FIELD_OPTIONS = array( + public static $FIELD_OPTIONS = [ // Tells the `OptionsArray` to not sort the options. // See the note below. '_UNSORTED' => true, 'NOT NULL' => 1, 'NULL' => 1, - 'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)), + 'DEFAULT' => [ + 2, + 'expr', + ['breakOnAlias' => true], + ], /* Following are not according to grammar, but MySQL happily accepts * these at any location */ - 'CHARSET' => array(2, 'var'), - 'COLLATE' => array(3, 'var'), + 'CHARSET' => [ + 2, + 'var', + ], + 'COLLATE' => [ + 3, + 'var', + ], 'AUTO_INCREMENT' => 3, 'PRIMARY' => 4, 'PRIMARY KEY' => 4, 'UNIQUE' => 4, 'UNIQUE KEY' => 4, - 'COMMENT' => array(5, 'var'), - 'COLUMN_FORMAT' => array(6, 'var'), - 'ON UPDATE' => array(7, 'expr'), + 'COMMENT' => [ + 5, + 'var', + ], + 'COLUMN_FORMAT' => [ + 6, + 'var', + ], + 'ON UPDATE' => [ + 7, + 'expr', + ], // Generated columns options. 'GENERATED ALWAYS' => 8, - 'AS' => array(9, 'expr', array('parenthesesDelimited' => true)), + 'AS' => [ + 9, + 'expr', + ['parenthesesDelimited' => true], + ], 'VIRTUAL' => 10, 'PERSISTENT' => 11, 'STORED' => 11, @@ -71,7 +94,7 @@ class CreateDefinition extends Component // 'NULL' => 1, // 'PRIMARY' => 4, // 'PRIMARY KEY' => 4, - ); + ]; /** * The name of the new column. @@ -149,9 +172,9 @@ class CreateDefinition extends Component * * @return CreateDefinition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -216,7 +239,7 @@ class CreateDefinition extends Component $state = 4; } elseif ($token->type === Token::TYPE_SYMBOL || $token->type === Token::TYPE_NONE) { $expr->name = $token->value; - if (!$expr->isConstraint) { + if (! $expr->isConstraint) { $state = 2; } } elseif ($token->type === Token::TYPE_KEYWORD) { @@ -259,7 +282,7 @@ class CreateDefinition extends Component } $state = 5; } elseif ($state === 5) { - if (!empty($expr->type) || !empty($expr->key)) { + if (! empty($expr->type) || ! empty($expr->key)) { $ret[] = $expr; } $expr = new self(); @@ -281,7 +304,7 @@ class CreateDefinition extends Component } // Last iteration was not saved. - if (!empty($expr->type) || !empty($expr->key)) { + if (! empty($expr->type) || ! empty($expr->key)) { $ret[] = $expr; } @@ -303,7 +326,7 @@ class CreateDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return "(\n " . implode(",\n ", $component) . "\n)"; @@ -319,18 +342,18 @@ class CreateDefinition extends Component $tmp .= Context::escape($component->name) . ' '; } - if (!empty($component->type)) { + if (! empty($component->type)) { $tmp .= DataType::build( $component->type, - array('lowercase' => true) + ['lowercase' => true] ) . ' '; } - if (!empty($component->key)) { + if (! empty($component->key)) { $tmp .= $component->key . ' '; } - if (!empty($component->references)) { + if (! empty($component->references)) { $tmp .= 'REFERENCES ' . $component->references . ' '; } diff --git a/src/Components/DataType.php b/src/Components/DataType.php index 51f04fa..47fffba 100644 --- a/src/Components/DataType.php +++ b/src/Components/DataType.php @@ -25,14 +25,23 @@ class DataType extends Component * * @var array */ - public static $DATA_TYPE_OPTIONS = array( + public static $DATA_TYPE_OPTIONS = [ 'BINARY' => 1, - 'CHARACTER SET' => array(2, 'var'), - 'CHARSET' => array(2, 'var'), - 'COLLATE' => array(3, 'var'), + 'CHARACTER SET' => [ + 2, + 'var', + ], + 'CHARSET' => [ + 2, + 'var', + ], + 'COLLATE' => [ + 3, + 'var', + ], 'UNSIGNED' => 4, 'ZEROFILL' => 5, - ); + ]; /** * The name of the data type. @@ -54,7 +63,7 @@ class DataType extends Component * * @var array */ - public $parameters = array(); + public $parameters = []; /** * The options of this data type. @@ -72,7 +81,7 @@ class DataType extends Component */ public function __construct( $name = null, - array $parameters = array(), + array $parameters = [], $options = null ) { $this->name = $name; @@ -87,7 +96,7 @@ class DataType extends Component * * @return DataType */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -119,7 +128,7 @@ class DataType extends Component if ($state === 0) { $ret->name = strtoupper($token->value); - if (($token->type !== Token::TYPE_KEYWORD) || (!($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { + if (($token->type !== Token::TYPE_KEYWORD) || (! ($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { $parser->error('Unrecognized data type.', $token); } $state = 1; @@ -151,13 +160,13 @@ class DataType extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $name = empty($options['lowercase']) ? $component->name : strtolower($component->name); $parameters = ''; - if (!empty($component->parameters)) { + if (! empty($component->parameters)) { $parameters = '(' . implode(',', $component->parameters) . ')'; } diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 5350e36..7383275 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -28,10 +28,19 @@ class Expression extends Component * * @var array */ - private static $ALLOWED_KEYWORDS = array( - 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, 'REGEXP' => 1, 'CASE' => 1, - 'DIV' => 1, 'AND' => 1, 'OR' => 1, 'XOR' => 1, 'NOT' => 1, 'MOD' => 1, - ); + private static $ALLOWED_KEYWORDS = [ + 'AS' => 1, + 'DUAL' => 1, + 'NULL' => 1, + 'REGEXP' => 1, + 'CASE' => 1, + 'DIV' => 1, + 'AND' => 1, + 'OR' => 1, + 'XOR' => 1, + 'NOT' => 1, + 'MOD' => 1, + ]; /** * The name of this database. @@ -146,7 +155,7 @@ class Expression extends Component * * @return Expression */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -183,10 +192,13 @@ class Expression extends Component * * @var Token[] */ - $prev = array(null, null); + $prev = [ + null, + null, + ]; // When a field is parsed, no parentheses are expected. - if (!empty($options['parseField'])) { + if (! empty($options['parseField'])) { $options['breakOnParentheses'] = true; $options['field'] = $options['parseField']; } @@ -216,14 +228,14 @@ class Expression extends Component if ($token->type === Token::TYPE_KEYWORD) { if (($brackets > 0) && empty($ret->subquery) - && !empty(Parser::$STATEMENT_PARSERS[$token->keyword]) + && ! empty(Parser::$STATEMENT_PARSERS[$token->keyword]) ) { // A `(` was previously found and this keyword is the // beginning of a statement, so this is a subquery. $ret->subquery = $token->keyword; } elseif (($token->flags & Token::FLAG_KEYWORD_FUNCTION) && (empty($options['parseField']) - && !$alias) + && ! $alias) ) { $isExpr = true; } elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED) @@ -236,7 +248,7 @@ class Expression extends Component break; } if ($token->keyword === 'AS') { - if (!empty($options['breakOnAlias'])) { + if (! empty($options['breakOnAlias'])) { break; } if ($alias) { @@ -257,7 +269,7 @@ class Expression extends Component continue; } $isExpr = true; - } elseif ($brackets === 0 && strlen($ret->expr) > 0 && !$alias) { + } elseif ($brackets === 0 && strlen($ret->expr) > 0 && ! $alias) { /* End of expression */ break; } @@ -272,7 +284,7 @@ class Expression extends Component || (($token->type === Token::TYPE_OPERATOR) && ($token->value !== '.')) ) { - if (!empty($options['parseField'])) { + if (! empty($options['parseField'])) { break; } @@ -282,7 +294,7 @@ class Expression extends Component } if ($token->type === Token::TYPE_OPERATOR) { - if (!empty($options['breakOnParentheses']) + if (! empty($options['breakOnParentheses']) && (($token->value === '(') || ($token->value === ')')) ) { // No brackets were expected. @@ -305,7 +317,7 @@ class Expression extends Component } else { --$brackets; if ($brackets === 0) { - if (!empty($options['parenthesesDelimited'])) { + if (! empty($options['parenthesesDelimited'])) { // The current token is the last bracket, the next // one will be outside the expression. $ret->expr .= $token->token; @@ -332,7 +344,7 @@ class Expression extends Component if ($alias) { // An alias is expected (the keyword `AS` was previously found). - if (!empty($ret->alias)) { + if (! empty($ret->alias)) { $parser->error('An alias was previously found.', $token); break; } @@ -345,13 +357,13 @@ class Expression extends Component || ((($prev[0]->type !== Token::TYPE_OPERATOR) || ($prev[0]->token === ')')) && (($prev[0]->type !== Token::TYPE_KEYWORD) - || (!($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED))))) + || (! ($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED))))) && (($prev[1]->type === Token::TYPE_STRING) || (($prev[1]->type === Token::TYPE_SYMBOL) - && (!($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE))) + && (! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE))) || ($prev[1]->type === Token::TYPE_NONE)) ) { - if (!empty($ret->alias)) { + if (! empty($ret->alias)) { $parser->error('An alias was previously found.', $token); break; } @@ -359,12 +371,12 @@ class Expression extends Component } else { $ret->expr .= $token->token; } - } elseif (!$isExpr) { + } elseif (! $isExpr) { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '.')) { // Found a `.` which means we expect a column name and // the column name we parsed is actually the table name // and the table name is actually a database name. - if (!empty($ret->database) || $dot) { + if (! empty($ret->database) || $dot) { $parser->error('Unexpected dot.', $token); } $ret->database = $ret->table; @@ -380,10 +392,10 @@ class Expression extends Component $dot = false; } else { // No alias is expected. - if (!empty($options['breakOnAlias'])) { + if (! empty($options['breakOnAlias'])) { break; } - if (!empty($ret->alias)) { + if (! empty($ret->alias)) { $parser->error('An alias was previously found.', $token); break; } @@ -418,16 +430,16 @@ class Expression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode($component, ', '); } - if ($component->expr !== '' && !is_null($component->expr)) { + if ($component->expr !== '' && ! is_null($component->expr)) { $ret = $component->expr; } else { - $fields = array(); + $fields = []; if (isset($component->database) && ($component->database !== '')) { $fields[] = $component->database; } @@ -440,7 +452,7 @@ class Expression extends Component $ret = implode('.', Context::escape($fields)); } - if (!empty($component->alias)) { + if (! empty($component->alias)) { $ret .= ' AS ' . Context::escape($component->alias); } diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index ab6988d..5d94681 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -27,9 +27,9 @@ class ExpressionArray extends Component * * @return Expression[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; /** * The state of the parser. @@ -115,9 +115,9 @@ class ExpressionArray extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $ret = array(); + $ret = []; foreach ($component as $frag) { $ret[] = $frag::build($frag); } diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php index 8334676..067987f 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -57,7 +57,7 @@ class FunctionCall extends Component * * @return FunctionCall */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -112,7 +112,7 @@ class FunctionCall extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return $component->name . $component->parameters; } diff --git a/src/Components/GroupKeyword.php b/src/Components/GroupKeyword.php index 314201b..86de663 100644 --- a/src/Components/GroupKeyword.php +++ b/src/Components/GroupKeyword.php @@ -44,9 +44,9 @@ class GroupKeyword extends Component * * @return GroupKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -93,7 +93,7 @@ class GroupKeyword extends Component } elseif (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',') ) { - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } $expr = new self(); @@ -105,7 +105,7 @@ class GroupKeyword extends Component } // Last iteration was not processed. - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } @@ -120,7 +120,7 @@ class GroupKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/IndexHint.php b/src/Components/IndexHint.php index 9534d2d..12edda7 100644 --- a/src/Components/IndexHint.php +++ b/src/Components/IndexHint.php @@ -44,9 +44,9 @@ class IndexHint extends Component /** * List of indexes in this hint * - * @var array + * @var array */ - public $indexes = array(); + public $indexes = []; /** * Constructor. @@ -56,7 +56,7 @@ class IndexHint extends Component * @param string $for the clause for which this hint is (JOIN/ORDER BY/GROUP BY) * @param string $indexes List of indexes in this hint */ - public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = array()) + public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = []) { $this->type = $type; $this->indexOrKey = $indexOrKey; @@ -71,9 +71,9 @@ class IndexHint extends Component * * @return IndexHint|Component[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); $expr->type = isset($options['type']) ? $options['type'] : null; /** @@ -178,7 +178,7 @@ class IndexHint extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(' ', $component); diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index c0fa390..524d94c 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -25,22 +25,37 @@ class IntoKeyword extends Component * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array(1, 'expr'), + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ + 1, + 'expr', + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array(3, 'expr'), - 'ESCAPED BY' => array(4, 'expr'), - ); + 'ENCLOSED BY' => [ + 3, + 'expr', + ], + 'ESCAPED BY' => [ + 4, + 'expr', + ], + ]; /** * LINES Options for `SELECT...INTO` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array(1, 'expr'), - 'TERMINATED BY' => array(2, 'expr'), - ); + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ + 1, + 'expr', + ], + 'TERMINATED BY' => [ + 2, + 'expr', + ], + ]; /** * Type of target (OUTFILE or SYMBOL). @@ -128,7 +143,7 @@ class IntoKeyword extends Component * * @return IntoKeyword */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -188,10 +203,10 @@ class IntoKeyword extends Component $ret->dest = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); } else { $ret->values = ExpressionArray::parse($parser, $list); @@ -254,10 +269,10 @@ class IntoKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if ($component->dest instanceof Expression) { - $columns = !empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; + $columns = ! empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; return $component->dest . $columns; } elseif (isset($component->values)) { @@ -272,7 +287,7 @@ class IntoKeyword extends Component $ret .= ' ' . $fields_options_str; } - $lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true)); + $lines_options_str = OptionsArray::build($component->lines_options, ['expr' => true]); if (trim($lines_options_str) !== '') { $ret .= ' LINES ' . $lines_options_str; } diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php index 786092d..6a13177 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -25,7 +25,7 @@ class JoinKeyword extends Component * * @var array */ - public static $JOINS = array( + public static $JOINS = [ 'CROSS JOIN' => 'CROSS', 'FULL JOIN' => 'FULL', 'FULL OUTER JOIN' => 'FULL', @@ -41,7 +41,7 @@ class JoinKeyword extends Component 'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER', 'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER', 'STRAIGHT_JOIN' => 'STRAIGHT', - ); + ]; /** * Type of this join. @@ -98,9 +98,9 @@ class JoinKeyword extends Component * * @return JoinKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -151,7 +151,7 @@ class JoinKeyword extends Component if ($state === 0) { if (($token->type === Token::TYPE_KEYWORD) - && !empty(static::$JOINS[$token->keyword]) + && ! empty(static::$JOINS[$token->keyword]) ) { $expr->type = static::$JOINS[$token->keyword]; $state = 1; @@ -159,19 +159,19 @@ class JoinKeyword extends Component break; } } elseif ($state === 1) { - $expr->expr = Expression::parse($parser, $list, array('field' => 'table')); + $expr->expr = Expression::parse($parser, $list, ['field' => 'table']); $state = 2; } elseif ($state === 2) { if ($token->type === Token::TYPE_KEYWORD) { - switch($token->keyword) { + switch ($token->keyword) { case 'ON': $state = 3; - break; + break; case 'USING': $state = 4; - break; + break; default: - if (!empty(static::$JOINS[$token->keyword]) + if (! empty(static::$JOINS[$token->keyword]) ) { $ret[] = $expr; $expr = new self(); @@ -181,7 +181,7 @@ class JoinKeyword extends Component /* Next clause is starting */ break 2; } - break; + break; } } } elseif ($state === 3) { @@ -197,7 +197,7 @@ class JoinKeyword extends Component } } - if (!empty($expr->type)) { + if (! empty($expr->type)) { $ret[] = $expr; } @@ -212,14 +212,14 @@ class JoinKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $ret = array(); + $ret = []; foreach ($component as $c) { $ret[] = array_search($c->type, static::$JOINS) . ' ' . $c->expr - . (!empty($c->on) + . (! empty($c->on) ? ' ON ' . Condition::build($c->on) : '') - . (!empty($c->using) + . (! empty($c->using) ? ' USING ' . ArrayObj::build($c->using) : ''); } diff --git a/src/Components/Key.php b/src/Components/Key.php index bd3bbd1..3093f01 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -28,12 +28,24 @@ class Key extends Component * * @var array */ - public static $KEY_OPTIONS = array( - 'KEY_BLOCK_SIZE' => array(1, 'var'), - 'USING' => array(2, 'var'), - 'WITH PARSER' => array(3, 'var'), - 'COMMENT' => array(4, 'var='), - ); + public static $KEY_OPTIONS = [ + 'KEY_BLOCK_SIZE' => [ + 1, + 'var', + ], + 'USING' => [ + 2, + 'var', + ], + 'WITH PARSER' => [ + 3, + 'var', + ], + 'COMMENT' => [ + 4, + 'var=', + ], + ]; /** * The name of this key. @@ -73,7 +85,7 @@ class Key extends Component */ public function __construct( $name = null, - array $columns = array(), + array $columns = [], $type = null, $options = null ) { @@ -90,7 +102,7 @@ class Key extends Component * * @return Key */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -99,7 +111,7 @@ class Key extends Component * * @var array */ - $lastColumn = array(); + $lastColumn = []; /** * The state of the parser. @@ -150,9 +162,9 @@ class Key extends Component $state = 3; } elseif (($token->value === ',') || ($token->value === ')')) { $state = ($token->value === ',') ? 2 : 4; - if (!empty($lastColumn)) { + if (! empty($lastColumn)) { $ret->columns[] = $lastColumn; - $lastColumn = array(); + $lastColumn = []; } } } else { @@ -182,14 +194,14 @@ class Key extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = $component->type . ' '; - if (!empty($component->name)) { + if (! empty($component->name)) { $ret .= Context::escape($component->name) . ' '; } - $columns = array(); + $columns = []; foreach ($component->columns as $column) { $tmp = Context::escape($column['name']); if (isset($column['length'])) { diff --git a/src/Components/Limit.php b/src/Components/Limit.php index 17423e2..d02ce49 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -53,7 +53,7 @@ class Limit extends Component * * @return Limit */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -121,7 +121,7 @@ class Limit extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return $component->offset . ', ' . $component->rowCount; } diff --git a/src/Components/LockExpression.php b/src/Components/LockExpression.php index 644e3ca..7cbfa72 100644 --- a/src/Components/LockExpression.php +++ b/src/Components/LockExpression.php @@ -35,13 +35,13 @@ class LockExpression extends Component public $type; /** - * @param Parser $parser the parser that serves as context - * @param TokensList $list the list of tokens that are being parsed + * @param Parser $parser the parser that serves as context + * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * * @return CaseExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -77,7 +77,7 @@ class LockExpression extends Component } if ($state === 0) { - $ret->table = Expression::parse($parser, $list, array('parseField' => 'table')); + $ret->table = Expression::parse($parser, $list, ['parseField' => 'table']); $state = 1; } elseif ($state === 1) { // parse lock type @@ -103,7 +103,7 @@ class LockExpression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); @@ -112,7 +112,8 @@ class LockExpression extends Component return $component->table . ' ' . $component->type; } - private static function parseLockType(Parser $parser, TokensList $list) { + private static function parseLockType(Parser $parser, TokensList $list) + { $lockType = ''; /** diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index fd02d22..2b17cdd 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -26,7 +26,7 @@ class OptionsArray extends Component * * @var array */ - public $options = array(); + public $options = []; /** * Constructor. @@ -35,7 +35,7 @@ class OptionsArray extends Component * must be an array with at least two keys `name` and * `expr` or `value`. */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { $this->options = $options; } @@ -47,7 +47,7 @@ class OptionsArray extends Component * * @return OptionsArray */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -156,7 +156,7 @@ class OptionsArray extends Component } if ($state === 0) { - if (!is_array($lastOption)) { + if (! is_array($lastOption)) { // This is a just keyword option without any value. // This is the beginning and the end of it. $ret->options[$lastOptionId] = $token->value; @@ -167,7 +167,7 @@ class OptionsArray extends Component // This is only the beginning. The value is parsed in state // 1 and 2. State 1 is used to skip the first equals sign // and state 2 to parse the actual value. - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. @@ -177,7 +177,7 @@ class OptionsArray extends Component 'expr' => '', // @var string Processed value. 'value' => '', - ); + ]; $state = 1; } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { // This is a keyword that is followed by an expression. @@ -185,7 +185,7 @@ class OptionsArray extends Component // Skipping this option in order to parse the expression. ++$list->idx; - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. @@ -193,7 +193,7 @@ class OptionsArray extends Component 'equals' => $lastOption[1] === 'expr=', // @var Expression The parsed expression. 'expr' => '', - ); + ]; $state = 1; } } elseif ($state === 1) { @@ -211,7 +211,7 @@ class OptionsArray extends Component $ret->options[$lastOptionId]['expr'] = Expression::parse( $parser, $list, - empty($lastOption[2]) ? array() : $lastOption[2] + empty($lastOption[2]) ? [] : $lastOption[2] ); $ret->options[$lastOptionId]['value'] = $ret->options[$lastOptionId]['expr']->expr; @@ -226,7 +226,7 @@ class OptionsArray extends Component $ret->options[$lastOptionId]['expr'] .= $token->token; - if (!((($token->token === '(') && ($brackets === 1)) + if (! ((($token->token === '(') && ($brackets === 1)) || (($token->token === ')') && ($brackets === 0))) ) { // First pair of brackets is being skipped. @@ -276,20 +276,20 @@ class OptionsArray extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (empty($component->options)) { return ''; } - $options = array(); + $options = []; foreach ($component->options as $option) { - if (!is_array($option)) { + if (! is_array($option)) { $options[] = $option; } else { $options[] = $option['name'] - . ((!empty($option['equals']) && $option['equals']) ? '=' : ' ') - . (!empty($option['expr']) ? $option['expr'] : $option['value']); + . ((! empty($option['equals']) && $option['equals']) ? '=' : ' ') + . (! empty($option['expr']) ? $option['expr'] : $option['value']); } } @@ -309,10 +309,10 @@ class OptionsArray extends Component { foreach ($this->options as $option) { if (is_array($option)) { - if (!strcasecmp($key, $option['name'])) { + if (! strcasecmp($key, $option['name'])) { return $getExpr ? $option['expr'] : $option['value']; } - } elseif (!strcasecmp($key, $option)) { + } elseif (! strcasecmp($key, $option)) { return true; } } @@ -331,12 +331,12 @@ class OptionsArray extends Component { foreach ($this->options as $idx => $option) { if (is_array($option)) { - if (!strcasecmp($key, $option['name'])) { + if (! strcasecmp($key, $option['name'])) { unset($this->options[$idx]); return true; } - } elseif (!strcasecmp($key, $option)) { + } elseif (! strcasecmp($key, $option)) { unset($this->options[$idx]); return true; diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 77d5a3d..f6d60eb 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -53,9 +53,9 @@ class OrderKeyword extends Component * * @return OrderKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -102,7 +102,7 @@ class OrderKeyword extends Component } elseif (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',') ) { - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } $expr = new self(); @@ -114,7 +114,7 @@ class OrderKeyword extends Component } // Last iteration was not processed. - if (!empty($expr->expr)) { + if (! empty($expr->expr)) { $ret[] = $expr; } @@ -129,7 +129,7 @@ class OrderKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php index 1f810f5..f45d6ac 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -63,9 +63,9 @@ class ParameterDefinition extends Component * * @return ParameterDefinition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -153,14 +153,14 @@ class ParameterDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return '(' . implode(', ', $component) . ')'; } $tmp = ''; - if (!empty($component->inOut)) { + if (! empty($component->inOut)) { $tmp .= $component->inOut . ' '; } diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 2fc769e..03f4aa6 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -29,17 +29,44 @@ class PartitionDefinition extends Component * * @var array */ - public static $OPTIONS = array( - 'STORAGE ENGINE' => array(1, 'var'), - 'ENGINE' => array(1, 'var'), - 'COMMENT' => array(2, 'var'), - 'DATA DIRECTORY' => array(3, 'var'), - 'INDEX DIRECTORY' => array(4, 'var'), - 'MAX_ROWS' => array(5, 'var'), - 'MIN_ROWS' => array(6, 'var'), - 'TABLESPACE' => array(7, 'var'), - 'NODEGROUP' => array(8, 'var'), - ); + public static $OPTIONS = [ + 'STORAGE ENGINE' => [ + 1, + 'var', + ], + 'ENGINE' => [ + 1, + 'var', + ], + 'COMMENT' => [ + 2, + 'var', + ], + 'DATA DIRECTORY' => [ + 3, + 'var', + ], + 'INDEX DIRECTORY' => [ + 4, + 'var', + ], + 'MAX_ROWS' => [ + 5, + 'var', + ], + 'MIN_ROWS' => [ + 6, + 'var', + ], + 'TABLESPACE' => [ + 7, + 'var', + ], + 'NODEGROUP' => [ + 8, + 'var', + ], + ]; /** * Whether this entry is a subpartition or a partition. @@ -90,7 +117,7 @@ class PartitionDefinition extends Component * * @return PartitionDefinition */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -163,10 +190,10 @@ class PartitionDefinition extends Component $ret->expr = Expression::parse( $parser, $list, - array( + [ 'parenthesesDelimited' => true, 'breakOnAlias' => true, - ) + ] ); } $state = 5; @@ -178,9 +205,9 @@ class PartitionDefinition extends Component $ret->subpartitions = ArrayObj::parse( $parser, $list, - array( + [ 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', - ) + ] ); ++$list->idx; } @@ -199,7 +226,7 @@ class PartitionDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return "(\n" . implode(",\n", $component) . "\n)"; @@ -214,7 +241,7 @@ class PartitionDefinition extends Component return trim( 'PARTITION ' . $component->name . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') - . ((!empty($component->options) && !empty($component->type)) ? '' : ' ') . $component->options . $subpartitions + . ((! empty($component->options) && ! empty($component->type)) ? '' : ' ') . $component->options . $subpartitions ); } } diff --git a/src/Components/Reference.php b/src/Components/Reference.php index 798eb68..3f8e453 100644 --- a/src/Components/Reference.php +++ b/src/Components/Reference.php @@ -26,11 +26,20 @@ class Reference extends Component * * @var array */ - public static $REFERENCES_OPTIONS = array( - 'MATCH' => array(1, 'var'), - 'ON DELETE' => array(2, 'var'), - 'ON UPDATE' => array(3, 'var'), - ); + public static $REFERENCES_OPTIONS = [ + 'MATCH' => [ + 1, + 'var', + ], + 'ON DELETE' => [ + 2, + 'var', + ], + 'ON UPDATE' => [ + 3, + 'var', + ], + ]; /** * The referenced table. @@ -60,7 +69,7 @@ class Reference extends Component * @param array $columns the columns referenced * @param OptionsArray $options the options */ - public function __construct($table = null, array $columns = array(), $options = null) + public function __construct($table = null, array $columns = [], $options = null) { $this->table = $table; $this->columns = $columns; @@ -74,7 +83,7 @@ class Reference extends Component * * @return Reference */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { $ret = new self(); @@ -115,10 +124,10 @@ class Reference extends Component $ret->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', 'breakOnAlias' => true, - ) + ] ); $state = 1; } elseif ($state === 1) { @@ -142,7 +151,7 @@ class Reference extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return trim( $component->table diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php index e9bd9ce..4bdb67e 100644 --- a/src/Components/RenameOperation.php +++ b/src/Components/RenameOperation.php @@ -53,9 +53,9 @@ class RenameOperation extends Component * * @return RenameOperation[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -99,10 +99,10 @@ class RenameOperation extends Component $expr->old = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, 'parseField' => 'table', - ) + ] ); if (empty($expr->old)) { $parser->error( @@ -125,10 +125,10 @@ class RenameOperation extends Component $expr->new = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, 'parseField' => 'table', - ) + ] ); if (empty($expr->new)) { $parser->error( @@ -156,7 +156,7 @@ class RenameOperation extends Component } // Last iteration was not saved. - if (!empty($expr->old)) { + if (! empty($expr->old)) { $ret[] = $expr; } @@ -171,7 +171,7 @@ class RenameOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index 2945a8e..68f2297 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -53,9 +53,9 @@ class SetOperation extends Component * * @return SetOperation[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; $expr = new self(); @@ -118,9 +118,9 @@ class SetOperation extends Component $tmp = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - ) + ] ); if (is_null($tmp)) { $parser->error('Missing expression.', $token); @@ -150,7 +150,7 @@ class SetOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php index 2de5126..220f86e 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -23,9 +23,9 @@ class UnionKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $tmp = array(); + $tmp = []; foreach ($component as $componentPart) { $tmp[] = $componentPart[0] . ' ' . $componentPart[1]; } |