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/Utils | |
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/Utils')
-rw-r--r-- | src/Utils/BufferedQuery.php | 17 | ||||
-rw-r--r-- | src/Utils/CLI.php | 35 | ||||
-rw-r--r-- | src/Utils/Error.php | 12 | ||||
-rw-r--r-- | src/Utils/Formatter.php | 166 | ||||
-rw-r--r-- | src/Utils/Misc.php | 34 | ||||
-rw-r--r-- | src/Utils/Query.php | 103 | ||||
-rw-r--r-- | src/Utils/Routine.php | 50 | ||||
-rw-r--r-- | src/Utils/Table.php | 28 | ||||
-rw-r--r-- | src/Utils/Tokens.php | 6 |
9 files changed, 278 insertions, 173 deletions
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php index ee0dca4..5edf903 100644 --- a/src/Utils/BufferedQuery.php +++ b/src/Utils/BufferedQuery.php @@ -49,7 +49,7 @@ class BufferedQuery * * @var array */ - public $options = array(); + public $options = []; /** * The last delimiter used. @@ -85,11 +85,11 @@ class BufferedQuery * @param string $query the query to be parsed * @param array $options the options of this parser */ - public function __construct($query = '', array $options = array()) + public function __construct($query = '', array $options = []) { // Merges specified options with defaults. $this->options = array_merge( - array( + [ /* * The starting delimiter. * @@ -111,7 +111,7 @@ class BufferedQuery * @var bool */ 'add_delimiter' => false, - ), + ], $options ); @@ -268,8 +268,7 @@ class BufferedQuery $this->status = static::STATUS_COMMENT_SQL; $this->current .= $this->query[$i]; continue; - } - elseif (($this->query[$i] === '/') + } elseif (($this->query[$i] === '/') && ($this->query[$i + 1] === '*') && ($this->query[$i + 2] !== '!')) { $this->status = static::STATUS_COMMENT_C; @@ -314,7 +313,7 @@ class BufferedQuery // Parsing the delimiter. $delimiter = ''; - while (($i < $len) && (!Context::isWhitespace($this->query[$i]))) { + while (($i < $len) && (! Context::isWhitespace($this->query[$i]))) { $delimiter .= $this->query[$i++]; } @@ -328,7 +327,7 @@ class BufferedQuery // Whether this statement should be returned or not. $ret = ''; - if (!empty($this->options['parse_delimiter'])) { + if (! empty($this->options['parse_delimiter'])) { // Appending the `DELIMITER` statement that was just // found to the current statement. $ret = trim( @@ -370,7 +369,7 @@ class BufferedQuery $ret = $this->current; // If needed, adds a delimiter at the end of the statement. - if (!empty($this->options['add_delimiter'])) { + if (! empty($this->options['add_delimiter'])) { $ret .= $this->delimiter; } diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 3dc48a6..d2c27f2 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -41,18 +41,23 @@ class CLI public function parseHighlight() { - $longopts = array('help', 'query:', 'format:'); + $longopts = [ + 'help', + 'query:', + 'format:', + ]; $params = $this->getopt( - 'hq:f:', $longopts + 'hq:f:', + $longopts ); if ($params === false) { return false; } $this->mergeLongOpts($params, $longopts); - if (!isset($params['f'])) { + if (! isset($params['f'])) { $params['f'] = 'cli'; } - if (!in_array($params['f'], array('html', 'cli', 'text'))) { + if (! in_array($params['f'], ['html', 'cli', 'text'])) { echo "ERROR: Invalid value for format!\n"; return false; @@ -74,7 +79,8 @@ class CLI } if (isset($params['q'])) { echo Formatter::format( - $params['q'], array('type' => $params['f']) + $params['q'], + ['type' => $params['f']] ); echo "\n"; @@ -93,9 +99,14 @@ class CLI public function parseLint() { - $longopts = array('help', 'query:', 'context:'); + $longopts = [ + 'help', + 'query:', + 'context:', + ]; $params = $this->getopt( - 'hq:c:', $longopts + 'hq:c:', + $longopts ); $this->mergeLongOpts($params, $longopts); @@ -119,7 +130,7 @@ class CLI if (isset($params['q'])) { $lexer = new Lexer($params['q'], false); $parser = new Parser($lexer->list); - $errors = Error::get(array($lexer, $parser)); + $errors = Error::get([$lexer, $parser]); if (count($errors) === 0) { return 0; } @@ -142,9 +153,13 @@ class CLI public function parseTokenize() { - $longopts = array('help', 'query:'); + $longopts = [ + 'help', + 'query:', + ]; $params = $this->getopt( - 'hq:', $longopts + 'hq:', + $longopts ); $this->mergeLongOpts($params, $longopts); diff --git a/src/Utils/Error.php b/src/Utils/Error.php index f80daa3..af9706f 100644 --- a/src/Utils/Error.php +++ b/src/Utils/Error.php @@ -32,26 +32,26 @@ class Error */ public static function get($objs) { - $ret = array(); + $ret = []; foreach ($objs as $obj) { if ($obj instanceof Lexer) { foreach ($obj->errors as $err) { - $ret[] = array( + $ret[] = [ $err->getMessage(), $err->getCode(), $err->ch, $err->pos, - ); + ]; } } elseif ($obj instanceof Parser) { foreach ($obj->errors as $err) { - $ret[] = array( + $ret[] = [ $err->getMessage(), $err->getCode(), $err->token->token, $err->token->position, - ); + ]; } } } @@ -77,7 +77,7 @@ class Error $errors, $format = '#%1$d: %2$s (near "%4$s" at position %5$d)' ) { - $ret = array(); + $ret = []; $i = 0; foreach ($errors as $key => $err) { diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index c41c69c..2d2ca40 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -46,10 +46,10 @@ class Formatter * * @var array */ - public static $SHORT_CLAUSES = array( + public static $SHORT_CLAUSES = [ 'CREATE' => true, 'INSERT' => true, - ); + ]; /** * Clauses that must be inlined. @@ -58,7 +58,7 @@ class Formatter * * @var array */ - public static $INLINE_CLAUSES = array( + public static $INLINE_CLAUSES = [ 'CREATE' => true, 'INTO' => true, 'LIMIT' => true, @@ -67,14 +67,14 @@ class Formatter 'PROCEDURE' => true, 'SUBPARTITION BY' => true, 'VALUES' => true, - ); + ]; /** * Constructor. * * @param array $options the formatting options */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { $this->options = $this->getMergedOptions($options); } @@ -120,7 +120,7 @@ class Formatter */ protected function getDefaultOptions() { - return array( + return [ /* * The format of the result. * @@ -171,7 +171,7 @@ class Formatter * @var bool */ 'indent_parts' => true, - ); + ]; } /** @@ -182,74 +182,81 @@ class Formatter */ protected function getDefaultFormats() { - return array( - array( + return [ + [ 'type' => Token::TYPE_KEYWORD, 'flags' => Token::FLAG_KEYWORD_RESERVED, 'html' => 'class="sql-reserved"', 'cli' => "\x1b[35m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_KEYWORD, 'flags' => 0, 'html' => 'class="sql-keyword"', 'cli' => "\x1b[95m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_COMMENT, 'flags' => 0, 'html' => 'class="sql-comment"', 'cli' => "\x1b[37m", 'function' => '', - ), - array( + ], + [ 'type' => Token::TYPE_BOOL, 'flags' => 0, 'html' => 'class="sql-atom"', 'cli' => "\x1b[36m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_NUMBER, 'flags' => 0, 'html' => 'class="sql-number"', 'cli' => "\x1b[92m", 'function' => 'strtolower', - ), - array( + ], + [ 'type' => Token::TYPE_STRING, 'flags' => 0, 'html' => 'class="sql-string"', 'cli' => "\x1b[91m", 'function' => '', - ), - array( + ], + [ 'type' => Token::TYPE_SYMBOL, 'flags' => 0, 'html' => 'class="sql-variable"', 'cli' => "\x1b[36m", 'function' => '', - ), - ); + ], + ]; } private static function mergeFormats(array $formats, array $newFormats) { - $added = array(); - $integers = array('flags', 'type'); - $strings = array('html', 'cli', 'function'); + $added = []; + $integers = [ + 'flags', + 'type', + ]; + $strings = [ + 'html', + 'cli', + 'function', + ]; /* Sanitize the array so that we do not have to care later */ foreach ($newFormats as $j => $new) { foreach ($integers as $name) { - if (!isset($new[$name])) { + if (! isset($new[$name])) { $newFormats[$j][$name] = 0; } } foreach ($strings as $name) { - if (!isset($new[$name])) { + if (! isset($new[$name])) { $newFormats[$j][$name] = ''; } } @@ -269,7 +276,7 @@ class Formatter /* Add not already handled formats */ foreach ($newFormats as $j => $new) { - if (!in_array($j, $added)) { + if (! in_array($j, $added)) { $formats[] = $new; } } @@ -327,7 +334,7 @@ class Formatter * * @var array */ - $blocksIndentation = array(); + $blocksIndentation = []; /** * A stack that keeps track of the line endings every time a new block @@ -335,7 +342,7 @@ class Formatter * * @var array */ - $blocksLineEndings = array(); + $blocksLineEndings = []; /** * Whether clause's options were formatted. @@ -396,7 +403,7 @@ class Formatter // The options of a clause should stay on the same line and everything that follows. if ($this->options['parts_newline'] - && !$formattedOptions + && ! $formattedOptions && empty(self::$INLINE_CLAUSES[$lastClause]) && ( $curr->type !== Token::TYPE_KEYWORD @@ -423,7 +430,7 @@ class Formatter // Inline JOINs if (($prev->type === Token::TYPE_KEYWORD && isset(JoinKeyword::$JOINS[$prev->value])) - || (in_array($curr->value, array('ON', 'USING'), true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value])) + || (in_array($curr->value, ['ON', 'USING'], true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value])) || isset($list->tokens[$list->idx - 4], JoinKeyword::$JOINS[$list->tokens[$list->idx - 4]->value]) || isset($list->tokens[$list->idx - 6], JoinKeyword::$JOINS[$list->tokens[$list->idx - 6]->value]) ) { @@ -448,7 +455,7 @@ class Formatter if (end($blocksLineEndings) === true || ( empty(self::$INLINE_CLAUSES[$lastClause]) - && !$shortGroup + && ! $shortGroup && $this->options['parts_newline'] ) ) { @@ -486,10 +493,9 @@ class Formatter } else { // If the line ended there is no point in adding whitespaces. // Also, some tokens do not have spaces before or after them. - if ( - // A space after delimiters that are longer than 2 characters. + if (// A space after delimiters that are longer than 2 characters. $prev->keyword === 'DELIMITER' - || !( + || ! ( ($prev->type === Token::TYPE_OPERATOR && ($prev->value === '.' || $prev->value === '(')) // No space after . ( || ($curr->type === Token::TYPE_OPERATOR && ($curr->value === '.' || $curr->value === ',' || $curr->value === '(' || $curr->value === ')')) @@ -516,14 +522,74 @@ class Formatter public function escapeConsole($string) { return str_replace( - array( - "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", - "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F", - ), - array( - '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', - '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F', - ), + [ + "\x00", + "\x01", + "\x02", + "\x03", + "\x04", + "\x05", + "\x06", + "\x07", + "\x08", + "\x09", + "\x0A", + "\x0B", + "\x0C", + "\x0D", + "\x0E", + "\x0F", + "\x10", + "\x11", + "\x12", + "\x13", + "\x14", + "\x15", + "\x16", + "\x17", + "\x18", + "\x19", + "\x1A", + "\x1B", + "\x1C", + "\x1D", + "\x1E", + "\x1F", + ], + [ + '\x00', + '\x01', + '\x02', + '\x03', + '\x04', + '\x05', + '\x06', + '\x07', + '\x08', + '\x09', + '\x0A', + '\x0B', + '\x0C', + '\x0D', + '\x0E', + '\x0F', + '\x10', + '\x11', + '\x12', + '\x13', + '\x14', + '\x15', + '\x16', + '\x17', + '\x18', + '\x19', + '\x1A', + '\x1B', + '\x1C', + '\x1D', + '\x1E', + '\x1F', + ], $string ); } @@ -545,7 +611,7 @@ class Formatter && ($token->flags & $format['flags']) === $format['flags'] ) { // Running transformation function. - if (!empty($format['function'])) { + if (! empty($format['function'])) { $func = $format['function']; $text = $func($text); } @@ -590,7 +656,7 @@ class Formatter * * @return string the formatted string */ - public static function format($query, array $options = array()) + public static function format($query, array $options = []) { $lexer = new Lexer($query); $formatter = new self($options); @@ -655,13 +721,11 @@ class Formatter */ public static function isClause($token) { - if ( - ($token->type === Token::TYPE_KEYWORD && isset(Parser::$STATEMENT_PARSERS[$token->keyword])) + if (($token->type === Token::TYPE_KEYWORD && isset(Parser::$STATEMENT_PARSERS[$token->keyword])) || ($token->type === Token::TYPE_NONE && strtoupper($token->token) === 'DELIMITER') ) { return 2; - } elseif ( - $token->type === Token::TYPE_KEYWORD && isset(Parser::$KEYWORD_PARSERS[$token->keyword]) + } elseif ($token->type === Token::TYPE_KEYWORD && isset(Parser::$KEYWORD_PARSERS[$token->keyword]) ) { return 1; } diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index 387600f..aa9e13a 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -28,16 +28,16 @@ class Misc */ public static function getAliases($statement, $database) { - if (!($statement instanceof SelectStatement) + if (! ($statement instanceof SelectStatement) || empty($statement->expr) || empty($statement->from) ) { - return array(); + return []; } - $retval = array(); + $retval = []; - $tables = array(); + $tables = []; /** * Expressions that may contain aliases. @@ -48,43 +48,43 @@ class Misc $expressions = $statement->from; // Adding expressions from JOIN. - if (!empty($statement->join)) { + if (! empty($statement->join)) { foreach ($statement->join as $join) { $expressions[] = $join->expr; } } foreach ($expressions as $expr) { - if (!isset($expr->table) || ($expr->table === '')) { + if (! isset($expr->table) || ($expr->table === '')) { continue; } $thisDb = (isset($expr->database) && ($expr->database !== '')) ? $expr->database : $database; - if (!isset($retval[$thisDb])) { - $retval[$thisDb] = array( + if (! isset($retval[$thisDb])) { + $retval[$thisDb] = [ 'alias' => null, - 'tables' => array(), - ); + 'tables' => [], + ]; } - if (!isset($retval[$thisDb]['tables'][$expr->table])) { - $retval[$thisDb]['tables'][$expr->table] = array( + if (! isset($retval[$thisDb]['tables'][$expr->table])) { + $retval[$thisDb]['tables'][$expr->table] = [ 'alias' => (isset($expr->alias) && ($expr->alias !== '')) ? $expr->alias : null, - 'columns' => array(), - ); + 'columns' => [], + ]; } - if (!isset($tables[$thisDb])) { - $tables[$thisDb] = array(); + if (! isset($tables[$thisDb])) { + $tables[$thisDb] = []; } $tables[$thisDb][$expr->alias] = $expr->table; } foreach ($statement->expr as $expr) { - if (!isset($expr->column, $expr->alias) || ($expr->column === '') || ($expr->alias === '') + if (! isset($expr->column, $expr->alias) || ($expr->column === '') || ($expr->alias === '') ) { continue; } diff --git a/src/Utils/Query.php b/src/Utils/Query.php index b43a35e..1416629 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -47,11 +47,18 @@ class Query * * @var array */ - public static $FUNCTIONS = array( - 'SUM', 'AVG', 'STD', 'STDDEV', 'MIN', 'MAX', 'BIT_OR', 'BIT_AND', - ); - - public static $ALLFLAGS = array( + public static $FUNCTIONS = [ + 'SUM', + 'AVG', + 'STD', + 'STDDEV', + 'MIN', + 'MAX', + 'BIT_OR', + 'BIT_AND', + ]; + + public static $ALLFLAGS = [ /* * select ... DISTINCT ... */ @@ -205,7 +212,7 @@ class Query * ... UNION ... */ 'union' => false, - ); + ]; /** * Gets an array with flags select statement has. @@ -215,12 +222,12 @@ class Query * * @return array */ - private static function _getFlagsSelect($statement, $flags) + private static function getFlagsSelect($statement, $flags) { $flags['querytype'] = 'SELECT'; $flags['is_select'] = true; - if (!empty($statement->from)) { + if (! empty($statement->from)) { $flags['select_from'] = true; } @@ -228,55 +235,55 @@ class Query $flags['distinct'] = true; } - if (!empty($statement->group) || !empty($statement->having)) { + if (! empty($statement->group) || ! empty($statement->having)) { $flags['is_group'] = true; } - if (!empty($statement->into) + if (! empty($statement->into) && ($statement->into->type === 'OUTFILE') ) { $flags['is_export'] = true; } $expressions = $statement->expr; - if (!empty($statement->join)) { + if (! empty($statement->join)) { foreach ($statement->join as $join) { $expressions[] = $join->expr; } } foreach ($expressions as $expr) { - if (!empty($expr->function)) { + if (! empty($expr->function)) { if ($expr->function === 'COUNT') { $flags['is_count'] = true; } elseif (in_array($expr->function, static::$FUNCTIONS)) { $flags['is_func'] = true; } } - if (!empty($expr->subquery)) { + if (! empty($expr->subquery)) { $flags['is_subquery'] = true; } } - if (!empty($statement->procedure) + if (! empty($statement->procedure) && ($statement->procedure->name === 'ANALYSE') ) { $flags['is_analyse'] = true; } - if (!empty($statement->group)) { + if (! empty($statement->group)) { $flags['group'] = true; } - if (!empty($statement->having)) { + if (! empty($statement->having)) { $flags['having'] = true; } - if (!empty($statement->union)) { + if (! empty($statement->union)) { $flags['union'] = true; } - if (!empty($statement->join)) { + if (! empty($statement->join)) { $flags['join'] = true; } @@ -293,7 +300,7 @@ class Query */ public static function getFlags($statement, $all = false) { - $flags = array('querytype' => false); + $flags = ['querytype' => false]; if ($all) { $flags = self::$ALLFLAGS; } @@ -352,7 +359,7 @@ class Query $flags['is_replace'] = true; $flags['is_insert'] = true; } elseif ($statement instanceof SelectStatement) { - $flags = self::_getFlagsSelect($statement, $flags); + $flags = self::getFlagsSelect($statement, $flags); } elseif ($statement instanceof ShowStatement) { $flags['querytype'] = 'SHOW'; $flags['is_show'] = true; @@ -367,10 +374,10 @@ class Query || ($statement instanceof UpdateStatement) || ($statement instanceof DeleteStatement) ) { - if (!empty($statement->limit)) { + if (! empty($statement->limit)) { $flags['limit'] = true; } - if (!empty($statement->order)) { + if (! empty($statement->order)) { $flags['order'] = true; } } @@ -409,18 +416,18 @@ class Query $ret['statement'] = $statement; if ($statement instanceof SelectStatement) { - $ret['select_tables'] = array(); - $ret['select_expr'] = array(); + $ret['select_tables'] = []; + $ret['select_expr'] = []; // Finding tables' aliases and their associated real names. - $tableAliases = array(); + $tableAliases = []; foreach ($statement->from as $expr) { if (isset($expr->table, $expr->alias) && ($expr->table !== '') && ($expr->alias !== '') ) { - $tableAliases[$expr->alias] = array( + $tableAliases[$expr->alias] = [ $expr->table, isset($expr->database) ? $expr->database : null, - ); + ]; } } @@ -432,13 +439,13 @@ class Query if (isset($tableAliases[$expr->table])) { $arr = $tableAliases[$expr->table]; } else { - $arr = array( + $arr = [ $expr->table, (isset($expr->database) && ($expr->database !== '')) ? $expr->database : null, - ); + ]; } - if (!in_array($arr, $ret['select_tables'])) { + if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; } } else { @@ -452,12 +459,12 @@ class Query if (empty($ret['select_tables'])) { foreach ($statement->from as $expr) { if (isset($expr->table) && ($expr->table !== '')) { - $arr = array( + $arr = [ $expr->table, (isset($expr->database) && ($expr->database !== '')) ? $expr->database : null, - ); - if (!in_array($arr, $ret['select_tables'])) { + ]; + if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; } } @@ -477,12 +484,12 @@ class Query */ public static function getTables($statement) { - $expressions = array(); + $expressions = []; if (($statement instanceof InsertStatement) || ($statement instanceof ReplaceStatement) ) { - $expressions = array($statement->into->dest); + $expressions = [$statement->into->dest]; } elseif ($statement instanceof UpdateStatement) { $expressions = $statement->tables; } elseif (($statement instanceof SelectStatement) @@ -492,11 +499,11 @@ class Query } elseif (($statement instanceof AlterStatement) || ($statement instanceof TruncateStatement) ) { - $expressions = array($statement->table); + $expressions = [$statement->table]; } elseif ($statement instanceof DropStatement) { - if (!$statement->options->has('TABLE')) { + if (! $statement->options->has('TABLE')) { // No tables are dropped. - return array(); + return []; } $expressions = $statement->fields; } elseif ($statement instanceof RenameStatement) { @@ -505,9 +512,9 @@ class Query } } - $ret = array(); + $ret = []; foreach ($expressions as $expr) { - if (!empty($expr->table)) { + if (! empty($expr->table)) { $expr->expr = null; // Force rebuild. $expr->alias = null; // Aliases are not required. $ret[] = Expression::build($expr); @@ -779,7 +786,7 @@ class Query $statement .= $token->token; - if (($token->type === Token::TYPE_DELIMITER) && !empty($token->token)) { + if (($token->type === Token::TYPE_DELIMITER) && ! empty($token->token)) { $delimiter = $token->token; $fullStatement = true; break; @@ -788,8 +795,12 @@ class Query // No statement was found so we return the entire query as being the // remaining part. - if (!$fullStatement) { - return array(null, $query, $delimiter); + if (! $fullStatement) { + return [ + null, + $query, + $delimiter, + ]; } // At least one query was found so we have to build the rest of the @@ -799,7 +810,11 @@ class Query $query .= $list->tokens[$list->idx]->token; } - return array(trim($statement), $query, $delimiter); + return [ + trim($statement), + $query, + $delimiter, + ]; } /** diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 127d37b..50f319a 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -36,21 +36,27 @@ class Routine $type = DataType::parse(new Parser(), $lexer->list); if ($type === null) { - return array('', '', '', '', ''); + return [ + '', + '', + '', + '', + '', + ]; } - $options = array(); + $options = []; foreach ($type->options->options as $opt) { $options[] = is_string($opt) ? $opt : $opt['value']; } - return array( + return [ '', '', $type->name, implode(',', $type->parameters), implode(' ', $options), - ); + ]; } /** @@ -68,23 +74,29 @@ class Routine $param = ParameterDefinition::parse(new Parser(), $lexer->list); if (empty($param[0])) { - return array('', '', '', '', ''); + return [ + '', + '', + '', + '', + '', + ]; } $param = $param[0]; - $options = array(); + $options = []; foreach ($param->type->options->options as $opt) { $options[] = is_string($opt) ? $opt : $opt['value']; } - return array( + return [ empty($param->inOut) ? '' : $param->inOut, $param->name, $param->type->name, implode(',', $param->type->parameters), implode(' ', $options), - ); + ]; } /** @@ -96,17 +108,17 @@ class Routine */ public static function getParameters($statement) { - $retval = array( + $retval = [ 'num' => 0, - 'dir' => array(), - 'name' => array(), - 'type' => array(), - 'length' => array(), - 'length_arr' => array(), - 'opts' => array(), - ); - - if (!empty($statement->parameters)) { + 'dir' => [], + 'name' => [], + 'type' => [], + 'length' => [], + 'length_arr' => [], + 'opts' => [], + ]; + + if (! empty($statement->parameters)) { $idx = 0; foreach ($statement->parameters as $param) { $retval['dir'][$idx] = $param->inOut; @@ -114,7 +126,7 @@ class Routine $retval['type'][$idx] = $param->type->name; $retval['length'][$idx] = implode(',', $param->type->parameters); $retval['length_arr'][$idx] = $param->type->parameters; - $retval['opts'][$idx] = array(); + $retval['opts'][$idx] = []; foreach ($param->type->options->options as $opt) { $retval['opts'][$idx][] = is_string($opt) ? $opt : $opt['value']; diff --git a/src/Utils/Table.php b/src/Utils/Table.php index b90c17a..49e3f35 100644 --- a/src/Utils/Table.php +++ b/src/Utils/Table.php @@ -27,30 +27,30 @@ class Table public static function getForeignKeys($statement) { if (empty($statement->fields) - || (!is_array($statement->fields)) - || (!$statement->options->has('TABLE')) + || (! is_array($statement->fields)) + || (! $statement->options->has('TABLE')) ) { - return array(); + return []; } - $ret = array(); + $ret = []; foreach ($statement->fields as $field) { if (empty($field->key) || ($field->key->type !== 'FOREIGN KEY')) { continue; } - $columns = array(); + $columns = []; foreach ($field->key->columns as $column) { $columns[] = $column['name']; } - $tmp = array( + $tmp = [ 'constraint' => $field->name, 'index_list' => $columns, - ); + ]; - if (!empty($field->references)) { + if (! empty($field->references)) { $tmp['ref_db_name'] = $field->references->table->database; $tmp['ref_table_name'] = $field->references->table->table; $tmp['ref_index_list'] = $field->references->columns; @@ -84,13 +84,13 @@ class Table public static function getFields($statement) { if (empty($statement->fields) - || (!is_array($statement->fields)) - || (!$statement->options->has('TABLE')) + || (! is_array($statement->fields)) + || (! $statement->options->has('TABLE')) ) { - return array(); + return []; } - $ret = array(); + $ret = []; foreach ($statement->fields as $field) { // Skipping keys. @@ -98,10 +98,10 @@ class Table continue; } - $ret[$field->name] = array( + $ret[$field->name] = [ 'type' => $field->type->name, 'timestamp_not_null' => false, - ); + ]; if ($field->options) { if ($field->type->name === 'TIMESTAMP') { diff --git a/src/Utils/Tokens.php b/src/Utils/Tokens.php index 76ab14c..cde1a79 100644 --- a/src/Utils/Tokens.php +++ b/src/Utils/Tokens.php @@ -76,7 +76,7 @@ class Tokens $isList = $list instanceof TokensList; // Parsing the tokens. - if (!$isList) { + if (! $isList) { $list = Lexer::getTokens($list); } @@ -85,7 +85,7 @@ class Tokens * * @var array */ - $newList = array(); + $newList = []; /** * The length of the find pattern is calculated only once. @@ -136,7 +136,7 @@ class Tokens ++$j; } - if (!static::match($list->tokens[$j], $find[$k])) { + if (! static::match($list->tokens[$j], $find[$k])) { // This token does not match the pattern. break; } |