diff options
Diffstat (limited to 'src/Components')
25 files changed, 359 insertions, 497 deletions
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index e3a3f9f..09f928f 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an alter operation. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AlterOperation extends Component { @@ -25,67 +21,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 +118,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,11 +149,9 @@ class AlterOperation extends Component * * @var Token[]|string */ - public $unknown = array(); + public $unknown = []; /** - * Constructor. - * * @param OptionsArray $options options of alter operation * @param Expression $field altered field * @param array $unknown unparsed tokens found at the end of operation @@ -165,7 +159,7 @@ class AlterOperation extends Component public function __construct( $options = null, $field = null, - $unknown = array() + $unknown = [] ) { $this->options = $options; $this->field = $field; @@ -179,9 +173,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 +245,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,10 +309,10 @@ 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 !== '')) { + if (isset($component->field) && ($component->field !== '')) { $ret .= $component->field . ' '; } $ret .= TokensList::build($component->unknown); @@ -331,11 +325,12 @@ class AlterOperation extends Component * between column and table alteration * * @param string $tokenValue Value of current token + * * @return bool */ private static function checkIfColumnDefinitionKeyword($tokenValue) { - $common_options = array( + $common_options = [ 'AUTO_INCREMENT', 'COMMENT', 'DEFAULT', @@ -344,8 +339,8 @@ class AlterOperation extends Component 'PRIMARY', 'UNIQUE', 'PRIMARY KEY', - 'UNIQUE KEY' - ); + 'UNIQUE KEY', + ]; // 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..1ae5c30 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; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Translator; /** * `VALUES` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Array2d extends Component { @@ -28,9 +24,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 +120,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..ab1ad61 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an array. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ArrayObj extends Component { @@ -25,22 +21,20 @@ 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. - * * @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 +47,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 +138,7 @@ class ArrayObj extends Component $ret[] = $options['type']::parse( $parser, $list, - empty($options['typeOptions']) ? array() : $options['typeOptions'] + empty($options['typeOptions']) ? [] : $options['typeOptions'] ); } } @@ -153,14 +147,13 @@ class ArrayObj extends Component // // This is treated differently to treat the following cases: // - // => array() - // (,) => array('', '') - // () => array() - // (a,) => array('a', '') - // (a) => array('a') - // + // => [] + // [,] => ['', ''] + // [] => [] + // [a,] => ['a', ''] + // [a] => ['a'] $lastRaw = trim($lastRaw); - if ((empty($options['type'])) + if (empty($options['type']) && ((strlen($lastRaw) > 0) || ($isCommaLast)) ) { $ret->raw[] = $lastRaw; @@ -176,7 +169,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..26c044f 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; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to a CASE expression. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CaseExpression extends Component { @@ -33,21 +29,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. @@ -70,9 +66,6 @@ class CaseExpression extends Component */ public $expr = ''; - /** - * Constructor. - */ public function __construct() { } @@ -84,9 +77,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. @@ -279,7 +272,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..b719b28 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `WHERE` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Condition extends Component { @@ -25,20 +21,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 +52,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. @@ -81,13 +77,11 @@ class Condition extends Component public $expr; /** - * Constructor. - * * @param string $expr the condition or the operator */ public function __construct($expr = null) { - $this->expr = trim($expr); + $this->expr = trim((string) $expr); } /** @@ -97,11 +91,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 +153,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 +216,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..0cd29c9 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; @@ -18,10 +18,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the create definition of a column or a key. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CreateDefinition extends Component { @@ -30,61 +26,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 @@ -94,12 +90,12 @@ class CreateDefinition extends Component // // 'UNIQUE' => 4, // 'UNIQUE KEY' => 4, - // 'COMMENT' => array(5, 'var'), + // 'COMMENT' => [5, 'var'], // 'NOT NULL' => 1, // 'NULL' => 1, // 'PRIMARY' => 4, // 'PRIMARY KEY' => 4, - ); + ]; /** * The name of the new column. @@ -144,8 +140,6 @@ class CreateDefinition extends Component public $options; /** - * Constructor. - * * @param string $name the name of the field * @param OptionsArray $options the options of this field * @param DataType|Key $type the data type of this field or the key @@ -177,11 +171,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 +284,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 +325,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 +344,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 d19d434..484e559 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a data type. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DataType extends Component { @@ -25,23 +21,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 +59,7 @@ class DataType extends Component * * @var array */ - public $parameters = array(); + public $parameters = []; /** * The options of this data type. @@ -73,15 +69,13 @@ class DataType extends Component public $options; /** - * Constructor. - * * @param string $name the name of this data type * @param array $parameters the parameters (size or possible values) * @param OptionsArray $options the options of this data type */ public function __construct( $name = null, - array $parameters = array(), + array $parameters = [], $options = null ) { $this->name = $name; @@ -96,9 +90,9 @@ class DataType extends Component * * @return DataType|null */ - 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 +121,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); } @@ -136,7 +130,7 @@ class DataType extends Component if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { $parameters = ArrayObj::parse($parser, $list); ++$list->idx; - $ret->parameters = (($ret->name === 'ENUM') || ($ret->name === 'SET')) ? + $ret->parameters = ($ret->name === 'ENUM') || ($ret->name === 'SET') ? $parameters->raw : $parameters->values; } $ret->options = OptionsArray::parse($parser, $list, static::$DATA_TYPE_OPTIONS); @@ -160,7 +154,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 2cf119b..bf97937 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; @@ -16,10 +16,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to an expression (column, table or database name, function * call, mathematical expression, etc.). - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Expression extends Component { @@ -28,7 +24,7 @@ class Expression extends Component * * @var array */ - private static $ALLOWED_KEYWORDS = array( + private static $ALLOWED_KEYWORDS = [ 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, @@ -39,8 +35,8 @@ class Expression extends Component 'OR' => 1, 'XOR' => 1, 'NOT' => 1, - 'MOD' => 1 - ); + 'MOD' => 1, + ]; /** * The name of this database. @@ -92,8 +88,6 @@ class Expression extends Component public $subquery; /** - * Constructor. - * * Syntax: * new Expression('expr') * new Expression('expr', 'alias') @@ -155,9 +149,9 @@ class Expression extends Component * * @return Expression|null */ - 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 +186,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 +263,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 +407,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,16 +424,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 !== '' && $component->expr !== null) { $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..186693d 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a list of expressions delimited by a comma. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ExpressionArray extends Component { @@ -27,9 +23,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 +111,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..b41e6b2 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a function call. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class FunctionCall extends Component { @@ -35,8 +31,6 @@ class FunctionCall extends Component public $parameters; /** - * Constructor. - * * @param string $name the name of the function to be called * @param array|ArrayObj $parameters the parameters of this function */ @@ -57,9 +51,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 +106,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..888fb89 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; @@ -13,13 +13,11 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `GROUP BY` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class GroupKeyword extends Component { + public $type; + /** * The expression that is used for grouping. * @@ -28,8 +26,6 @@ class GroupKeyword extends Component public $expr; /** - * Constructor. - * * @param Expression $expr the expression that we are sorting by */ public function __construct($expr = null) @@ -44,11 +40,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 +92,7 @@ class GroupKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -120,12 +116,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..9b2f44e 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an Index hint. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class IndexHint extends Component { @@ -46,17 +42,15 @@ class IndexHint extends Component * * @var array */ - public $indexes = array(); + public $indexes = []; /** - * Constructor. - * * @param string $type the type of hint (USE/FORCE/IGNORE) * @param string $indexOrKey What the hint is for (INDEX/KEY) * @param string $for the clause for which this hint is (JOIN/ORDER BY/GROUP BY) - * @param string $indexes List of indexes in this hint + * @param array $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 +65,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. @@ -86,6 +80,7 @@ class IndexHint extends Component * 2 -------------------- [ expr_list ] --------------------> 0 * 3 -------------- [ JOIN/GROUP BY/ORDER BY ] -------------> 4 * 4 -------------------- [ expr_list ] --------------------> 0 + * * @var int */ $state = 0; @@ -143,7 +138,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 +158,7 @@ class IndexHint extends Component $expr->indexes = ExpressionArray::parse($parser, $list); $state = 0; $ret[] = $expr; - $expr = new self(); + $expr = new static(); break; } } @@ -173,12 +168,12 @@ class IndexHint extends Component } /** - * @param ArrayObj|ArrayObj[] $component the component to be built - * @param array $options parameters for building + * @param IndexHint|IndexHint[] $component the component to be built + * @param array $options parameters for building * * @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 dea5d9d..c3f8a43 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `INTO` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class IntoKeyword extends Component { @@ -25,37 +21,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). @@ -88,9 +84,9 @@ class IntoKeyword extends Component /** * Options for FIELDS/COLUMNS keyword. * - * @var OptionsArray - * * @see static::$FIELDS_OPTIONS + * + * @var OptionsArray */ public $fields_options; @@ -104,15 +100,13 @@ class IntoKeyword extends Component /** * Options for OPTIONS keyword. * - * @var OptionsArray - * * @see static::$LINES_OPTIONS + * + * @var OptionsArray */ public $lines_options; /** - * Constructor. - * * @param string $type type of destination (may be OUTFILE) * @param string|Expression $dest actual destination * @param array $columns column list of destination @@ -143,9 +137,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 +197,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 +263,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 +281,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..91bab01 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `JOIN` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class JoinKeyword extends Component { @@ -25,7 +21,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 +36,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. @@ -74,14 +70,12 @@ class JoinKeyword extends Component public $using; /** - * Constructor. + * @see JoinKeyword::$JOINS * * @param string $type Join type * @param Expression $expr join expression * @param Condition[] $on join conditions * @param ArrayObj $using columns joined - * - * @see JoinKeyword::$JOINS */ public function __construct($type = null, $expr = null, $on = null, $using = null) { @@ -98,11 +92,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 +153,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 +168,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 +181,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 +206,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..669a7c0 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; @@ -16,10 +16,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the definition of a key. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Key extends Component { @@ -28,24 +24,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. @@ -76,8 +72,6 @@ class Key extends Component public $options; /** - * Constructor. - * * @param string $name the name of the key * @param array $columns the columns covered by this key * @param string $type the type of this key @@ -85,7 +79,7 @@ class Key extends Component */ public function __construct( $name = null, - array $columns = array(), + array $columns = [], $type = null, $options = null ) { @@ -102,16 +96,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. @@ -161,10 +155,10 @@ class Key extends Component if ($token->value === '(') { $state = 3; } elseif (($token->value === ',') || ($token->value === ')')) { - $state = ($token->value === ',') ? 2 : 4; + $state = $token->value === ',' ? 2 : 4; if (! empty($lastColumn)) { $ret->columns[] = $lastColumn; - $lastColumn = array(); + $lastColumn = []; } } } else { @@ -194,14 +188,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 a3903b5..16dad29 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `LIMIT` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Limit extends Component { @@ -35,8 +31,6 @@ class Limit extends Component public $rowCount; /** - * Constructor. - * * @param int $rowCount the row count * @param int $offset the offset */ @@ -53,9 +47,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; @@ -126,7 +120,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..6184f2e 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to a LOCK expression. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class LockExpression extends Component { @@ -39,11 +35,11 @@ class LockExpression extends Component * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * - * @return CaseExpression + * @return LockExpression */ - 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 +73,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 +99,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..da73dc6 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; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Translator; /** * Parses a list of options. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptionsArray extends Component { @@ -26,16 +22,14 @@ class OptionsArray extends Component * * @var array */ - public $options = array(); + public $options = []; /** - * Constructor. - * * @param array $options The array of options. Options that have a value * 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 +41,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 +161,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 +170,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 +179,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 +205,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,19 +270,19 @@ 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; } else { $options[] = $option['name'] - . ((! empty($option['equals']) && $option['equals']) ? '=' : ' ') + . (! empty($option['equals']) && $option['equals'] ? '=' : ' ') . (! empty($option['expr']) ? $option['expr'] : $option['value']); } } diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 1e77f57..966758e 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `ORDER BY` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OrderKeyword extends Component { @@ -35,8 +31,6 @@ class OrderKeyword extends Component public $type; /** - * Constructor. - * * @param Expression $expr the expression that we are sorting by * @param string $type the sorting type */ @@ -53,11 +47,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 +99,7 @@ class OrderKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -129,7 +123,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..d7aa293 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; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * The definition of a parameter of a function or procedure. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ParameterDefinition extends Component { @@ -43,8 +39,6 @@ class ParameterDefinition extends Component public $type; /** - * Constructor. - * * @param string $name parameter's name * @param string $inOut parameter's directional type (IN / OUT or None) * @param DataType $type parameter's type @@ -63,11 +57,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 +121,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 +147,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 53da148..e67e92f 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; @@ -17,10 +17,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the create definition of a partition. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class PartitionDefinition extends Component { @@ -29,44 +25,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 +113,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. @@ -196,10 +192,10 @@ class PartitionDefinition extends Component $ret->expr = Expression::parse( $parser, $list, - array( + [ 'parenthesesDelimited' => true, - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); } $state = 5; @@ -211,9 +207,9 @@ class PartitionDefinition extends Component $ret->subpartitions = ArrayObj::parse( $parser, $list, - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition' - ) + [ + 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', + ] ); ++$list->idx; } @@ -232,7 +228,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)"; @@ -247,7 +243,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 38fc060..759f3ad 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; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `REFERENCES` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Reference extends Component { @@ -26,20 +22,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. @@ -63,13 +59,11 @@ class Reference extends Component public $options; /** - * Constructor. - * * @param Expression $table the name of the table referenced * @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 +77,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 +118,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 +145,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..a2a8d1f 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `RENAME TABLE` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RenameOperation extends Component { @@ -35,8 +31,6 @@ class RenameOperation extends Component public $new; /** - * Constructor. - * * @param Expression $old old expression * @param Expression $new new expression containing new name */ @@ -53,11 +47,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 +93,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 +119,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 +134,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 +165,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..1e44650 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; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `SET` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SetOperation extends Component { @@ -35,8 +31,6 @@ class SetOperation extends Component public $value; /** - * Constructor. - * * @param string $column Field's name.. * @param string $value new value */ @@ -53,11 +47,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,18 +112,18 @@ class SetOperation extends Component $tmp = Expression::parse( $parser, $list, - array( - 'breakOnAlias' => true - ) + [ + 'breakOnAlias' => true, + ] ); - if (is_null($tmp)) { + if ($tmp === null) { $parser->error('Missing expression.', $token); break; } $expr->column = trim($expr->column); $expr->value = $tmp->expr; $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; $commaLastSeenAt = null; } @@ -150,7 +144,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 6867615..55c9e29 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; @@ -10,10 +10,6 @@ use PhpMyAdmin\SqlParser\Component; /** * `UNION` keyword builder. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UnionKeyword extends Component { @@ -23,9 +19,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]; } |