diff options
author | Damian Dlugosz <bigfootdd@gmail.com> | 2017-01-03 22:06:01 +0100 |
---|---|---|
committer | Damian Dlugosz <bigfootdd@gmail.com> | 2017-01-06 00:11:32 +0100 |
commit | a6e45c5e2e006bbd90306e1e947e25e601965657 (patch) | |
tree | 07fbbdbe95d08721e97b6683226ad3a26a6e9886 /src/Utils | |
parent | 082a1fad6c64f455ac42698cb9c7a08f0347a2c0 (diff) | |
download | sql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.zip sql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.tar.gz sql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.tar.bz2 |
Apply php-cs-fixer
Diffstat (limited to 'src/Utils')
-rw-r--r-- | src/Utils/BufferedQuery.php | 46 | ||||
-rw-r--r-- | src/Utils/CLI.php | 24 | ||||
-rw-r--r-- | src/Utils/Error.php | 43 | ||||
-rw-r--r-- | src/Utils/Formatter.php | 111 | ||||
-rw-r--r-- | src/Utils/Misc.php | 14 | ||||
-rw-r--r-- | src/Utils/Query.php | 214 | ||||
-rw-r--r-- | src/Utils/Routine.php | 18 | ||||
-rw-r--r-- | src/Utils/Table.php | 14 | ||||
-rw-r--r-- | src/Utils/Tokens.php | 14 |
9 files changed, 232 insertions, 266 deletions
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php index b1ef46d..045513d 100644 --- a/src/Utils/BufferedQuery.php +++ b/src/Utils/BufferedQuery.php @@ -2,10 +2,8 @@ /** * Buffered query utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Context; @@ -20,26 +18,24 @@ use SqlParser\Context; * All comments are skipped, with one exception: MySQL commands inside `/*!`. * * @category Lexer - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class BufferedQuery { - // Constants that describe the current status of the parser. // A string is being parsed. - const STATUS_STRING = 16; // 0001 0000 - const STATUS_STRING_SINGLE_QUOTES = 17; // 0001 0001 - const STATUS_STRING_DOUBLE_QUOTES = 18; // 0001 0010 - const STATUS_STRING_BACKTICK = 20; // 0001 0100 + const STATUS_STRING = 16; // 0001 0000 + const STATUS_STRING_SINGLE_QUOTES = 17; // 0001 0001 + const STATUS_STRING_DOUBLE_QUOTES = 18; // 0001 0010 + const STATUS_STRING_BACKTICK = 20; // 0001 0100 // A comment is being parsed. - const STATUS_COMMENT = 32; // 0010 0000 - const STATUS_COMMENT_BASH = 33; // 0010 0001 - const STATUS_COMMENT_C = 34; // 0010 0010 - const STATUS_COMMENT_SQL = 36; // 0010 0100 + const STATUS_COMMENT = 32; // 0010 0000 + const STATUS_COMMENT_BASH = 33; // 0010 0001 + const STATUS_COMMENT_C = 34; // 0010 0010 + const STATUS_COMMENT_SQL = 36; // 0010 0100 /** * The query that is being processed. @@ -88,30 +84,29 @@ class BufferedQuery /** * Constructor. * - * @param string $query The query to be parsed. - * @param array $options The options of this parser. + * @param string $query the query to be parsed + * @param array $options the options of this parser */ public function __construct($query = '', array $options = array()) { // Merges specified options with defaults. $this->options = array_merge( array( - - /** + /* * The starting delimiter. * * @var string */ 'delimiter' => ';', - /** + /* * Whether `DELIMITER` statements should be parsed. * * @var bool */ 'parse_delimiter' => false, - /** + /* * Whether a delimiter should be added at the end of the * statement. * @@ -142,7 +137,7 @@ class BufferedQuery /** * Extracts a statement from the buffer. * - * @param bool $end Whether the end of the buffer was reached. + * @param bool $end whether the end of the buffer was reached * * @return string */ @@ -166,7 +161,7 @@ class BufferedQuery /** * The length of the buffer. * - * @var int $len + * @var int */ $len = strlen($this->query); @@ -186,12 +181,12 @@ class BufferedQuery * Those extra characters are required only if there is more data * expected (the end of the buffer was not reached). * - * @var int $loopLen + * @var int */ $loopLen = $end ? $len : $len - 16; for (; $i < $loopLen; ++$i) { - /** + /* * Handling backslash. * * Even if the next character is a special character that should be @@ -294,7 +289,7 @@ class BufferedQuery * statement. This is the reason for the last condition. */ if (($i + 9 < $len) - && (($this->query[$i ] === 'D') || ($this->query[$i ] === 'd')) + && (($this->query[$i] === 'D') || ($this->query[$i] === 'd')) && (($this->query[$i + 1] === 'E') || ($this->query[$i + 1] === 'e')) && (($this->query[$i + 2] === 'L') || ($this->query[$i + 2] === 'l')) && (($this->query[$i + 3] === 'I') || ($this->query[$i + 3] === 'i')) @@ -353,6 +348,7 @@ class BufferedQuery // Incomplete statement. Reverting $i = $iBak; + return false; } diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 9ec7b85..a5ed0be 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -1,22 +1,19 @@ <?php /** - * CLI interface - * - * @package SqlParser - * @subpackage Utils + * CLI interface. */ + namespace SqlParser\Utils; use SqlParser\Parser; use SqlParser\Lexer; /** - * CLI interface + * CLI interface. * * @category Exceptions - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CLI @@ -51,13 +48,15 @@ class CLI 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'], array('html', 'cli', 'text'))) { echo "ERROR: Invalid value for format!\n"; + return false; } + return $params; } @@ -69,6 +68,7 @@ class CLI } if (isset($params['h'])) { $this->usageHighlight(); + return 0; } if (isset($params['q'])) { @@ -76,10 +76,12 @@ class CLI $params['q'], array('type' => $params['f']) ); echo "\n"; + return 0; } echo "ERROR: Missing parameters!\n"; $this->usageHighlight(); + return 1; } @@ -95,6 +97,7 @@ class CLI 'hq:', $longopts ); $this->mergeLongOpts($params, $longopts); + return $params; } @@ -106,6 +109,7 @@ class CLI } if (isset($params['h'])) { $this->usageLint(); + return 0; } if (isset($params['q'])) { @@ -118,10 +122,12 @@ class CLI $output = Error::format($errors); echo implode("\n", $output); echo "\n"; + return 10; } echo "ERROR: Missing parameters!\n"; $this->usageLint(); + return 1; } } diff --git a/src/Utils/Error.php b/src/Utils/Error.php index 2e942c4..568af0a 100644 --- a/src/Utils/Error.php +++ b/src/Utils/Error.php @@ -2,10 +2,8 @@ /** * Error related utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Lexer; @@ -15,24 +13,22 @@ use SqlParser\Parser; * Error related utilities. * * @category Exceptions - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Error { - /** * Gets the errors of a lexer and a parser. * - * @param array $objs Objects from where the errors will be extracted. + * @param array $objs objects from where the errors will be extracted * * @return array Each element of the array represents an error. - * `$err[0]` holds the error message. - * `$err[1]` holds the error code. - * `$err[2]` holds the string that caused the issue. - * `$err[3]` holds the position of the string. - * (i.e. `array($msg, $code, $str, $pos)`) + * `$err[0]` holds the error message. + * `$err[1]` holds the error code. + * `$err[2]` holds the string that caused the issue. + * `$err[3]` holds the position of the string. + * (i.e. `array($msg, $code, $str, $pos)`) */ public static function get($objs) { @@ -45,7 +41,7 @@ class Error $err->getMessage(), $err->getCode(), $err->ch, - $err->pos + $err->pos, ); } } elseif ($obj instanceof Parser) { @@ -54,7 +50,7 @@ class Error $err->getMessage(), $err->getCode(), $err->token->token, - $err->token->position + $err->token->position, ); } } @@ -64,16 +60,17 @@ class Error } /** - * Formats the specified errors + * Formats the specified errors. + * + * @param array $errors the errors to be formatted + * @param string $format The format of an error. + * '$1$d' is replaced by the position of this error. + * '$2$s' is replaced by the error message. + * '$3$d' is replaced by the error code. + * '$4$s' is replaced by the string that caused the + * issue. + * '$5$d' is replaced by the position of the string. * - * @param array $errors The errors to be formatted. - * @param string $format The format of an error. - * '$1$d' is replaced by the position of this error. - * '$2$s' is replaced by the error message. - * '$3$d' is replaced by the error code. - * '$4$s' is replaced by the string that caused the - * issue. - * '$5$d' is replaced by the position of the string. * @return array */ public static function format( diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index e459b60..ec23ba9 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -2,10 +2,8 @@ /** * Utilities that are used for formatting queries. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Lexer; @@ -17,13 +15,11 @@ use SqlParser\TokensList; * Utilities that are used for formatting queries. * * @category Misc - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Formatter { - /** * The formatting options. * @@ -39,19 +35,19 @@ class Formatter * @var array */ public static $INLINE_CLAUSES = array( - 'CREATE' => true, - 'LIMIT' => true, - 'PARTITION BY' => true, - 'PARTITION' => true, - 'PROCEDURE' => true, - 'SUBPARTITION BY' => true, - 'VALUES' => true, + 'CREATE' => true, + 'LIMIT' => true, + 'PARTITION BY' => true, + 'PARTITION' => true, + 'PROCEDURE' => true, + 'SUBPARTITION BY' => true, + 'VALUES' => true, ); /** * Constructor. * - * @param array $options The formatting options. + * @param array $options the formatting options */ public function __construct(array $options = array()) { @@ -62,6 +58,7 @@ class Formatter * The specified formatting options are merged with the default values. * * @param array $options + * * @return array */ private function getMergedOptions(array $options) @@ -95,43 +92,43 @@ class Formatter protected function getDefaultOptions() { return array( - /** + /* * The format of the result. * * @var string The type ('text', 'cli' or 'html') */ 'type' => php_sapi_name() === 'cli' ? 'cli' : 'text', - /** + /* * The line ending used. * By default, for text this is "\n" and for HTML this is "<br/>". * * @var string */ - 'line_ending' => NULL, + 'line_ending' => null, - /** + /* * The string used for indentation. * * @var string */ 'indentation' => ' ', - /** + /* * Whether comments should be removed or not. * * @var bool */ 'remove_comments' => false, - /** + /* * Whether each clause should be on a new line. * * @var bool */ 'clause_newline' => true, - /** + /* * Whether each part should be on a new line. * Parts are delimited by brackets and commas. * @@ -139,7 +136,7 @@ class Formatter */ 'parts_newline' => true, - /** + /* * Whether each part of each clause should be indented. * * @var bool @@ -150,7 +147,7 @@ class Formatter /** * The styles used for HTML formatting. - * array($type, $flags, $span, $callback) + * array($type, $flags, $span, $callback). * * @return array */ @@ -218,12 +215,12 @@ class Formatter /* 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] = ''; } } @@ -243,7 +240,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; } } @@ -254,45 +251,44 @@ class Formatter /** * Formats the given list of tokens. * - * @param TokensList $list The list of tokens. + * @param TokensList $list the list of tokens * * @return string */ public function formatList($list) { - /** * The query to be returned. * - * @var string $ret + * @var string */ $ret = ''; /** * The indentation level. * - * @var int $indent + * @var int */ $indent = 0; /** * Whether the line ended. * - * @var bool $lineEnded + * @var bool */ $lineEnded = false; /** - * Whether current group is short (no linebreaks) + * Whether current group is short (no linebreaks). * - * @var bool $shortGroup + * @var bool */ $shortGroup = false; /** * The name of the last clause. * - * @var string $lastClause + * @var string */ $lastClause = ''; @@ -300,7 +296,7 @@ class Formatter * A stack that keeps track of the indentation level every time a new * block is found. * - * @var array $blocksIndentation + * @var array */ $blocksIndentation = array(); @@ -308,21 +304,21 @@ class Formatter * A stack that keeps track of the line endings every time a new block * is found. * - * @var array $blocksLineEndings + * @var array */ $blocksLineEndings = array(); /** * Whether clause's options were formatted. * - * @var bool $formattedOptions + * @var bool */ $formattedOptions = false; /** * Previously parsed token. * - * @var Token $prev + * @var Token */ $prev = null; @@ -330,7 +326,7 @@ class Formatter * Comments are being formatted separately to maintain the whitespaces * before and after them. * - * @var string $comment + * @var string */ $comment = ''; @@ -342,7 +338,7 @@ class Formatter /** * Token parsed at this moment. * - * @var Token $curr + * @var Token */ $curr = $list->tokens[$list->idx]; @@ -421,7 +417,7 @@ class Formatter // pieces only if the clause is not inlined or this fragment // is between brackets that are on new line. if (((empty(self::$INLINE_CLAUSES[$lastClause])) - && ! $shortGroup + && !$shortGroup && ($this->options['parts_newline'])) || (end($blocksLineEndings) === true) ) { @@ -505,18 +501,12 @@ class Formatter { 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" + "\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', ), $string ); @@ -525,7 +515,7 @@ class Formatter /** * Tries to print the query and returns the result. * - * @param Token $token The token to be printed. + * @param Token $token the token to be printed * * @return string */ @@ -559,6 +549,7 @@ class Formatter } elseif ($this->options['type'] === 'html') { return htmlspecialchars($text, ENT_NOQUOTES); } + return $text; } @@ -566,14 +557,15 @@ class Formatter * Formats a query. * * @param string $query The query to be formatted - * @param array $options The formatting options. + * @param array $options the formatting options * - * @return string The formatted string. + * @return string the formatted string */ public static function format($query, array $options = array()) { $lexer = new Lexer($query); - $formatter = new Formatter($options); + $formatter = new self($options); + return $formatter->formatList($lexer->list); } @@ -582,7 +574,7 @@ class Formatter * * A group is delimited by a pair of brackets. * - * @param TokensList $list The list of tokens. + * @param TokensList $list the list of tokens * * @return int */ @@ -594,14 +586,14 @@ class Formatter * the list already advanced one position and the opening bracket was * already parsed. * - * @var int $count + * @var int */ $count = 1; /** * The length of this group. * - * @var int $length + * @var int */ $length = 0; @@ -628,7 +620,7 @@ class Formatter /** * Checks if a token is a statement or a clause inside a statement. * - * @param Token $token The token to be checked. + * @param Token $token the token to be checked * * @return int|bool */ @@ -641,6 +633,7 @@ class Formatter } elseif (($token->type === Token::TYPE_KEYWORD) && (isset(Parser::$KEYWORD_PARSERS[$token->value]))) { return 1; } + return false; } } diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index 8166c45..84ec3d1 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -2,10 +2,8 @@ /** * Miscellaneous utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Components\Expression; @@ -15,18 +13,16 @@ use SqlParser\Statements\SelectStatement; * Miscellaneous utilities. * * @category Misc - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Misc { - /** * Gets a list of all aliases and their original names. * - * @param SelectStatement $statement The statement to be processed. - * @param string $database The name of the database. + * @param SelectStatement $statement the statement to be processed + * @param string $database the name of the database * * @return array */ @@ -47,7 +43,7 @@ class Misc * Expressions that may contain aliases. * These are extracted from `FROM` and `JOIN` keywords. * - * @var Expression[] $expressions + * @var Expression[] */ $expressions = $statement->from; diff --git a/src/Utils/Query.php b/src/Utils/Query.php index bfd10a9..1a5162d 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -2,10 +2,8 @@ /** * Statement utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Lexer; @@ -37,27 +35,25 @@ use SqlParser\Statements\UpdateStatement; * Statement utilities. * * @category Statement - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Query { - /** * Functions that set the flag `is_func`. * * @var array */ public static $FUNCTIONS = array( - 'SUM', 'AVG', 'STD', 'STDDEV', 'MIN', 'MAX', 'BIT_OR', 'BIT_AND' + 'SUM', 'AVG', 'STD', 'STDDEV', 'MIN', 'MAX', 'BIT_OR', 'BIT_AND', ); /** * Gets an array with flags this statement has. * - * @param Statement|null $statement The statement to be processed. - * @param bool $all If `false`, false values will not be included. + * @param Statement|null $statement the statement to be processed + * @param bool $all if `false`, false values will not be included * * @return array */ @@ -66,83 +62,82 @@ class Query $flags = array(); if ($all) { $flags = array( - - /** + /* * select ... DISTINCT ... */ - 'distinct' => false, + 'distinct' => false, - /** + /* * drop ... DATABASE ... */ 'drop_database' => false, - /** + /* * ... GROUP BY ... */ - 'group' => false, + 'group' => false, - /** + /* * ... HAVING ... */ - 'having' => false, + 'having' => false, - /** + /* * INSERT ... * or * REPLACE ... * or * DELETE ... */ - 'is_affected' => false, + 'is_affected' => false, - /** + /* * select ... PROCEDURE ANALYSE( ... ) ... */ - 'is_analyse' => false, + 'is_analyse' => false, - /** + /* * select COUNT( ... ) ... */ - 'is_count' => false, + 'is_count' => false, - /** + /* * DELETE ... */ - 'is_delete' => false, // @deprecated; use `querytype` + 'is_delete' => false, // @deprecated; use `querytype` - /** + /* * EXPLAIN ... */ - 'is_explain' => false, // @deprecated; use `querytype` + 'is_explain' => false, // @deprecated; use `querytype` - /** + /* * select ... INTO OUTFILE ... */ - 'is_export' => false, + 'is_export' => false, - /** + /* * select FUNC( ... ) ... */ - 'is_func' => false, + 'is_func' => false, - /** + /* * select ... GROUP BY ... * or * select ... HAVING ... */ - 'is_group' => false, + 'is_group' => false, - /** + /* * INSERT ... * or * REPLACE ... * or * TODO: LOAD DATA ... */ - 'is_insert' => false, + 'is_insert' => false, - /** + /* * ANALYZE ... * or * CHECK ... @@ -153,73 +148,73 @@ class Query * or * REPAIR ... */ - 'is_maint' => false, + 'is_maint' => false, - /** + /* * CALL ... */ - 'is_procedure' => false, + 'is_procedure' => false, - /** + /* * REPLACE ... */ - 'is_replace' => false, // @deprecated; use `querytype` + 'is_replace' => false, // @deprecated; use `querytype` - /** + /* * SELECT ... */ - 'is_select' => false, // @deprecated; use `querytype` + 'is_select' => false, // @deprecated; use `querytype` - /** + /* * SHOW ... */ - 'is_show' => false, // @deprecated; use `querytype` + 'is_show' => false, // @deprecated; use `querytype` - /** + /* * Contains a subquery. */ - 'is_subquery' => false, + 'is_subquery' => false, - /** + /* * ... JOIN ... */ - 'join' => false, + 'join' => false, - /** + /* * ... LIMIT ... */ - 'limit' => false, + 'limit' => false, - /** + /* * TODO */ - 'offset' => false, + 'offset' => false, - /** + /* * ... ORDER ... */ - 'order' => false, + 'order' => false, - /** + /* * The type of the query (which is usually the first keyword of * the statement). */ - 'querytype' => false, + 'querytype' => false, - /** + /* * Whether a page reload is required. */ - 'reload' => false, + 'reload' => false, - /** + /* * SELECT ... FROM ... */ - 'select_from' => false, + 'select_from' => false, - /** + /* * ... UNION ... */ - 'union' => false + 'union' => false, ); } @@ -335,7 +330,6 @@ class Query if (!empty($statement->join)) { $flags['join'] = true; } - } elseif ($statement instanceof ShowStatement) { $flags['querytype'] = 'SHOW'; $flags['is_show'] = true; @@ -362,17 +356,17 @@ class Query /** * Parses a query and gets all information about it. * - * @param string $query The query to be parsed. + * @param string $query the query to be parsed * * @return array The array returned is the one returned by * `static::getFlags()`, with the following keys added: - * - parser - the parser used to analyze the query; - * - statement - the first statement resulted from parsing; - * - select_tables - the real name of the tables selected; - * if there are no table names in the `SELECT` - * expressions, the table names are fetched from the - * `FROM` expressions - * - select_expr - selected expressions + * - parser - the parser used to analyze the query; + * - statement - the first statement resulted from parsing; + * - select_tables - the real name of the tables selected; + * if there are no table names in the `SELECT` + * expressions, the table names are fetched from the + * `FROM` expressions + * - select_expr - selected expressions */ public static function getAll($query) { @@ -401,7 +395,7 @@ class Query ) { $tableAliases[$expr->alias] = array( $expr->table, - isset($expr->database) ? $expr->database : null + isset($expr->database) ? $expr->database : null, ); } } @@ -417,7 +411,7 @@ class Query $arr = array( $expr->table, ((isset($expr->database)) && ($expr->database !== '')) ? - $expr->database : null + $expr->database : null, ); } if (!in_array($arr, $ret['select_tables'])) { @@ -437,7 +431,7 @@ class Query $arr = array( $expr->table, ((isset($expr->database)) && ($expr->database !== '')) ? - $expr->database : null + $expr->database : null, ); if (!in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; @@ -453,7 +447,7 @@ class Query /** * Gets a list of all tables used in this statement. * - * @param Statement $statement Statement to be scanned. + * @param Statement $statement statement to be scanned * * @return array */ @@ -495,33 +489,33 @@ class Query $ret[] = Expression::build($expr); } } + return $ret; } /** * Gets a specific clause. * - * @param Statement $statement The parsed query that has to be modified. - * @param TokensList $list The list of tokens. - * @param string $clause The clause to be returned. + * @param Statement $statement the parsed query that has to be modified + * @param TokensList $list the list of tokens + * @param string $clause the clause to be returned * @param int|string $type The type of the search. * If int, - * -1 for everything that was before - * 0 only for the clause - * 1 for everything after + * -1 for everything that was before + * 0 only for the clause + * 1 for everything after * If string, the name of the first clause that * should not be included. - * @param bool $skipFirst Whether to skip the first keyword in clause. + * @param bool $skipFirst whether to skip the first keyword in clause * * @return string */ public static function getClause($statement, $list, $clause, $type = 0, $skipFirst = true) { - /** * The index of the current clause. * - * @var int $currIdx + * @var int */ $currIdx = 0; @@ -529,42 +523,42 @@ class Query * The count of brackets. * We keep track of them so we won't insert the clause in a subquery. * - * @var int $brackets + * @var int */ $brackets = 0; /** * The string to be returned. * - * @var string $ret + * @var string */ $ret = ''; /** * The clauses of this type of statement and their index. * - * @var array $clauses + * @var array */ $clauses = array_flip(array_keys($statement->getClauses())); /** * Lexer used for lexing the clause. * - * @var Lexer $lexer + * @var Lexer */ $lexer = new Lexer($clause); /** * The type of this clause. * - * @var string $clauseType + * @var string */ $clauseType = $lexer->list->getNextOfType(Token::TYPE_KEYWORD)->value; /** * The index of this clause. * - * @var int $clauseIdx + * @var int */ $clauseIdx = $clauses[$clauseType]; @@ -637,14 +631,14 @@ class Query * * It is a very basic version of a query builder. * - * @param Statement $statement The parsed query that has to be modified. - * @param TokensList $list The list of tokens. + * @param Statement $statement the parsed query that has to be modified + * @param TokensList $list the list of tokens * @param string $old The type of the clause that should be * replaced. This can be an entire clause. * @param string $new The new clause. If this parameter is omitted * it is considered to be equal with `$old`. - * @param bool $onlyType Whether only the type of the clause should - * be replaced or the entire clause. + * @param bool $onlyType whether only the type of the clause should + * be replaced or the entire clause * * @return string */ @@ -670,8 +664,8 @@ class Query * Builds a query by rebuilding the statement from the tokens list supplied * and replaces multiple clauses. * - * @param Statement $statement The parsed query that has to be modified. - * @param TokensList $list The list of tokens. + * @param Statement $statement the parsed query that has to be modified + * @param TokensList $list the list of tokens * @param array $ops Clauses to be replaced. Contains multiple * arrays having two values: array($old, $new). * Clauses must be sorted. @@ -690,7 +684,7 @@ class Query /** * Value to be returned. * - * @var string $ret + * @var string */ $ret = ''; @@ -726,12 +720,12 @@ class Query /** * Gets the first full statement in the query. * - * @param string $query The query to be analyzed. - * @param string $delimiter The delimiter to be used. + * @param string $query the query to be analyzed + * @param string $delimiter the delimiter to be used * - * @return array Array containing the first full query, the - * remaining part of the query and the last - * delimiter. + * @return array array containing the first full query, the + * remaining part of the query and the last + * delimiter */ public static function getFirstStatement($query, $delimiter = null) { @@ -741,14 +735,14 @@ class Query /** * Whether a full statement was found. * - * @var bool $fullStatement + * @var bool */ $fullStatement = false; /** * The first full statement. * - * @var string $statement + * @var string */ $statement = ''; @@ -787,9 +781,9 @@ class Query /** * Gets a starting offset of a specific clause. * - * @param Statement $statement The parsed query that has to be modified. - * @param TokensList $list The list of tokens. - * @param string $clause The clause to be returned. + * @param Statement $statement the parsed query that has to be modified + * @param TokensList $list the list of tokens + * @param string $clause the clause to be returned * * @return int */ @@ -799,14 +793,14 @@ class Query * The count of brackets. * We keep track of them so we won't insert the clause in a subquery. * - * @var int $brackets + * @var int */ $brackets = 0; /** * The clauses of this type of statement and their index. * - * @var array $clauses + * @var array */ $clauses = array_flip(array_keys($statement->getClauses())); diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index d5a7891..5b0d5b9 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -2,10 +2,8 @@ /** * Routine utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Lexer; @@ -18,17 +16,15 @@ use SqlParser\Statements\CreateStatement; * Routine utilities. * * @category Routines - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Routine { - /** * Parses a parameter of a routine. * - * @param string $param Parameter's definition. + * @param string $param parameter's definition * * @return array */ @@ -53,14 +49,14 @@ class Routine '', $type->name, implode(',', $type->parameters), - implode(' ', $options) + implode(' ', $options), ); } /** * Parses a parameter of a routine. * - * @param string $param Parameter's definition. + * @param string $param parameter's definition * * @return array */ @@ -87,14 +83,14 @@ class Routine $param->name, $param->type->name, implode(',', $param->type->parameters), - implode(' ', $options) + implode(' ', $options), ); } /** * Gets the parameters of a routine from the parse tree. * - * @param CreateStatement $statement The statement to be processed. + * @param CreateStatement $statement the statement to be processed * * @return array */ diff --git a/src/Utils/Table.php b/src/Utils/Table.php index a31ddf2..58d4366 100644 --- a/src/Utils/Table.php +++ b/src/Utils/Table.php @@ -2,10 +2,8 @@ /** * Table utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Statements\CreateStatement; @@ -14,17 +12,15 @@ use SqlParser\Statements\CreateStatement; * Table utilities. * * @category Statement - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Table { - /** * Gets the foreign keys of the table. * - * @param CreateStatement $statement The statement to be processed. + * @param CreateStatement $statement the statement to be processed * * @return array */ @@ -73,7 +69,6 @@ class Table } $ret[] = $tmp; - } return $ret; @@ -82,7 +77,7 @@ class Table /** * Gets fields of the table. * - * @param CreateStatement $statement The statement to be processed. + * @param CreateStatement $statement the statement to be processed * * @return array */ @@ -133,7 +128,6 @@ class Table $ret[$field->name]['expr'] = $option; } } - } return $ret; diff --git a/src/Utils/Tokens.php b/src/Utils/Tokens.php index acec369..4637ed1 100644 --- a/src/Utils/Tokens.php +++ b/src/Utils/Tokens.php @@ -2,10 +2,8 @@ /** * Token utilities. - * - * @package SqlParser - * @subpackage Utils */ + namespace SqlParser\Utils; use SqlParser\Lexer; @@ -16,18 +14,16 @@ use SqlParser\TokensList; * Token utilities. * * @category Token - * @package SqlParser - * @subpackage Utils + * * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Tokens { - /** * Checks if a pattern is a match for the specified token. * - * @param Token $token The token to be matched. - * @param array $pattern The pattern to be matches. + * @param Token $token the token to be matched + * @param array $pattern the pattern to be matches * * @return bool */ @@ -72,7 +68,6 @@ class Tokens public static function replaceTokens($list, array $find, array $replace) { - /** * Whether the first parameter is a list. * @@ -151,7 +146,6 @@ class Tokens ++$k; } - // Checking if the sequence was found. if ($k === $findCount) { // Inserting new tokens. |