summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamian Dlugosz <bigfootdd@gmail.com>2017-01-03 22:06:01 +0100
committerDamian Dlugosz <bigfootdd@gmail.com>2017-01-06 00:11:32 +0100
commita6e45c5e2e006bbd90306e1e947e25e601965657 (patch)
tree07fbbdbe95d08721e97b6683226ad3a26a6e9886
parent082a1fad6c64f455ac42698cb9c7a08f0347a2c0 (diff)
downloadsql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.zip
sql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.tar.gz
sql-parser-a6e45c5e2e006bbd90306e1e947e25e601965657.tar.bz2
Apply php-cs-fixer
-rw-r--r--.php_cs20
-rw-r--r--src/Component.php20
-rw-r--r--src/Components/AlterOperation.php135
-rw-r--r--src/Components/Array2d.php25
-rw-r--r--src/Components/ArrayObj.php34
-rw-r--r--src/Components/CaseExpression.php47
-rw-r--r--src/Components/Condition.php70
-rw-r--r--src/Components/CreateDefinition.php78
-rw-r--r--src/Components/DataType.php44
-rw-r--r--src/Components/Expression.php50
-rw-r--r--src/Components/ExpressionArray.php24
-rw-r--r--src/Components/FunctionCall.php31
-rw-r--r--src/Components/IntoKeyword.php57
-rw-r--r--src/Components/JoinKeyword.php66
-rw-r--r--src/Components/Key.php42
-rw-r--r--src/Components/Limit.php27
-rw-r--r--src/Components/OptionsArray.php52
-rw-r--r--src/Components/OrderKeyword.php32
-rw-r--r--src/Components/ParameterDefinition.php27
-rw-r--r--src/Components/PartitionDefinition.php48
-rw-r--r--src/Components/Reference.php38
-rw-r--r--src/Components/RenameOperation.php27
-rw-r--r--src/Components/SetOperation.php27
-rw-r--r--src/Components/UnionKeyword.php13
-rw-r--r--src/Context.php142
-rw-r--r--src/Exceptions/LexerException.php16
-rw-r--r--src/Exceptions/ParserException.php14
-rw-r--r--src/Lexer.php82
-rw-r--r--src/Parser.php508
-rw-r--r--src/Statement.php70
-rw-r--r--src/Statements/AlterStatement.php42
-rw-r--r--src/Statements/AnalyzeStatement.php15
-rw-r--r--src/Statements/BackupStatement.php17
-rw-r--r--src/Statements/CallStatement.php8
-rw-r--r--src/Statements/CheckStatement.php23
-rw-r--r--src/Statements/ChecksumStatement.php15
-rw-r--r--src/Statements/CreateStatement.php168
-rw-r--r--src/Statements/DeleteStatement.php65
-rw-r--r--src/Statements/DropStatement.php45
-rw-r--r--src/Statements/ExplainStatement.php8
-rw-r--r--src/Statements/InsertStatement.php52
-rw-r--r--src/Statements/MaintenanceStatement.php16
-rw-r--r--src/Statements/NotImplementedStatement.php14
-rw-r--r--src/Statements/OptimizeStatement.php15
-rw-r--r--src/Statements/RenameStatement.php16
-rw-r--r--src/Statements/RepairStatement.php21
-rw-r--r--src/Statements/ReplaceStatement.php34
-rw-r--r--src/Statements/RestoreStatement.php13
-rw-r--r--src/Statements/SelectStatement.php94
-rw-r--r--src/Statements/SetStatement.php22
-rw-r--r--src/Statements/ShowStatement.php90
-rw-r--r--src/Statements/TransactionStatement.php51
-rw-r--r--src/Statements/TruncateStatement.php10
-rw-r--r--src/Statements/UpdateStatement.php26
-rw-r--r--src/Token.php117
-rw-r--r--src/TokensList.php42
-rw-r--r--src/UtfString.php29
-rw-r--r--src/Utils/BufferedQuery.php46
-rw-r--r--src/Utils/CLI.php24
-rw-r--r--src/Utils/Error.php43
-rw-r--r--src/Utils/Formatter.php111
-rw-r--r--src/Utils/Misc.php14
-rw-r--r--src/Utils/Query.php214
-rw-r--r--src/Utils/Routine.php18
-rw-r--r--src/Utils/Table.php14
-rw-r--r--src/Utils/Tokens.php14
-rw-r--r--src/common.php5
-rw-r--r--tests/Builder/AlterStatementTest.php2
-rw-r--r--tests/Builder/CreateStatementTest.php32
-rw-r--r--tests/Builder/DeleteStatementTest.php8
-rw-r--r--tests/Builder/ExplainStatement.php2
-rw-r--r--tests/Builder/InsertStatementTest.php2
-rw-r--r--tests/Builder/ReplaceStatementTest.php2
-rw-r--r--tests/Builder/SelectStatementTest.php3
-rw-r--r--tests/Builder/SetStatementTest.php2
-rw-r--r--tests/Builder/StatementTest.php2
-rw-r--r--tests/Builder/TransactionStatementTest.php2
-rw-r--r--tests/Components/Array2dTest.php6
-rw-r--r--tests/Components/ArrayObjTest.php2
-rw-r--r--tests/Components/CaseExpressionTest.php2
-rw-r--r--tests/Components/ComponentTest.php2
-rw-r--r--tests/Components/ConditionTest.php2
-rw-r--r--tests/Components/CreateDefinitionTest.php2
-rw-r--r--tests/Components/ExpressionArrayTest.php2
-rw-r--r--tests/Components/ExpressionTest.php4
-rw-r--r--tests/Components/FunctionCallTest.php2
-rw-r--r--tests/Components/IntoKeywordTest.php2
-rw-r--r--tests/Components/JoinKeywordTest.php6
-rw-r--r--tests/Components/KeyTest.php2
-rw-r--r--tests/Components/LimitTest.php2
-rw-r--r--tests/Components/OptionsArrayTest.php2
-rw-r--r--tests/Components/OrderKeywordTest.php5
-rw-r--r--tests/Components/ParameterDefinitionTest.php2
-rw-r--r--tests/Components/PartitionDefinitionTest.php2
-rw-r--r--tests/Components/ReferenceTest.php2
-rw-r--r--tests/Components/RenameOperationTest.php2
-rw-r--r--tests/Lexer/ContextTest.php4
-rw-r--r--tests/Lexer/IsMethodsTest.php6
-rw-r--r--tests/Lexer/LexerTest.php4
-rw-r--r--tests/Lexer/TokenTest.php2
-rw-r--r--tests/Lexer/TokensListTest.php2
-rw-r--r--tests/Misc/BugsTest.php1
-rw-r--r--tests/Misc/UtfStringTest.php2
-rw-r--r--tests/Parser/AlterStatementTest.php1
-rw-r--r--tests/Parser/CallStatementTest.php1
-rw-r--r--tests/Parser/CreateStatementTest.php1
-rw-r--r--tests/Parser/DeleteStatementTest.php1
-rw-r--r--tests/Parser/ExplainStatement.php1
-rw-r--r--tests/Parser/InsertStatementTest.php1
-rw-r--r--tests/Parser/ParserTest.php4
-rw-r--r--tests/Parser/RenameStatementTest.php1
-rw-r--r--tests/Parser/ReplaceStatementTest.php1
-rw-r--r--tests/Parser/RestoreStatementTest.php1
-rw-r--r--tests/Parser/SelectStatementTest.php2
-rw-r--r--tests/Parser/SetStatementTest.php1
-rw-r--r--tests/Parser/TransactionStatementTest.php1
-rw-r--r--tests/Parser/UpdateStatementTest.php1
-rw-r--r--tests/Utils/BufferedQueryTest.php35
-rw-r--r--tests/Utils/CLITest.php1
-rw-r--r--tests/Utils/ErrorTest.php2
-rw-r--r--tests/Utils/FormatterTest.php23
-rw-r--r--tests/Utils/MiscTest.php54
-rw-r--r--tests/Utils/QueryTest.php114
-rw-r--r--tests/Utils/RoutineTest.php80
-rw-r--r--tests/Utils/TableTest.php8
-rw-r--r--tests/Utils/TokensTest.php25
-rw-r--r--tests/bootstrap.php22
-rw-r--r--tools/ContextGenerator.php124
-rw-r--r--tools/TestGenerator.php37
129 files changed, 1872 insertions, 2237 deletions
diff --git a/.php_cs b/.php_cs
new file mode 100644
index 0000000..e1894b3
--- /dev/null
+++ b/.php_cs
@@ -0,0 +1,20 @@
+<?php
+
+// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer
+
+$finder = PhpCsFixer\Finder::create()
+ ->in(array(__DIR__.'/bin', __DIR__.'/src', __DIR__.'/tests', __DIR__.'/tools'))
+;
+
+return PhpCsFixer\Config::create()
+ ->setRules(array(
+ '@PSR1' => true,
+ '@PSR2' => true,
+ '@Symfony' => true,
+ 'array_syntax' => array('syntax' => 'long'),
+ 'concat_space' => array('spacing' => true),
+ 'no_trailing_whitespace' => true,
+ 'phpdoc_order' => true,
+ ))
+ ->setFinder($finder)
+;
diff --git a/src/Component.php b/src/Component.php
index 08720cf..107756c 100644
--- a/src/Component.php
+++ b/src/Component.php
@@ -7,9 +7,8 @@
* There is a small difference between *Component and *Keyword classes: usually,
* *Component parsers can be reused in multiple situations and *Keyword parsers
* count on the *Component classes to do their job.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
require_once 'common.php';
@@ -19,21 +18,20 @@ require_once 'common.php';
* multiple query types.
*
* @category Components
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class Component
{
-
/**
* Parses the tokens contained in the given list in the context of the given
* parser.
*
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
- * @throws \Exception Not implemented yet.
+ * @throws \Exception not implemented yet
*
* @return mixed
*/
@@ -53,10 +51,10 @@ abstract class Component
* In other words, this function represents the inverse function of
* `static::parse`.
*
- * @param mixed $component The component to be built.
- * @param array $options Parameters for building.
+ * @param mixed $component the component to be built
+ * @param array $options parameters for building
*
- * @throws \Exception Not implemented yet.
+ * @throws \Exception not implemented yet
*
* @return string
*/
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php
index c2344c6..43bd14a 100644
--- a/src/Components/AlterOperation.php
+++ b/src/Components/AlterOperation.php
@@ -2,10 +2,8 @@
/**
* Parses an alter operation.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,86 +15,84 @@ use SqlParser\TokensList;
* Parses an alter operation.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class AlterOperation extends Component
{
-
/**
- * All database options
+ * All database options.
*
* @var array
*/
public static $DB_OPTIONS = array(
- 'CHARACTER SET' => array(1, 'var'),
- 'CHARSET' => array(1, 'var'),
- 'DEFAULT CHARACTER SET' => array(1, 'var'),
- 'DEFAULT CHARSET' => array(1, 'var'),
- 'UPGRADE' => array(1, 'var'),
- 'COLLATE' => array(2, 'var'),
- 'DEFAULT COLLATE' => array(2, 'var'),
+ 'CHARACTER SET' => array(1, 'var'),
+ 'CHARSET' => array(1, 'var'),
+ 'DEFAULT CHARACTER SET' => array(1, 'var'),
+ 'DEFAULT CHARSET' => array(1, 'var'),
+ 'UPGRADE' => array(1, 'var'),
+ 'COLLATE' => array(2, 'var'),
+ 'DEFAULT COLLATE' => array(2, 'var'),
);
/**
- * All table options
+ * All table options.
*
* @var array
*/
public static $TABLE_OPTIONS = array(
- 'ENGINE' => array(1, 'var='),
- 'AUTO_INCREMENT' => array(1, 'var='),
- 'AVG_ROW_LENGTH' => array(1, 'var'),
- 'MAX_ROWS' => array(1, 'var'),
- 'ROW_FORMAT' => array(1, 'var'),
- 'COMMENT' => array(1, 'var'),
- 'ADD' => 1,
- 'ALTER' => 1,
- 'ANALYZE' => 1,
- 'CHANGE' => 1,
- 'CHECK' => 1,
- 'COALESCE' => 1,
- 'CONVERT' => 1,
- 'DISABLE' => 1,
- 'DISCARD' => 1,
- 'DROP' => 1,
- 'ENABLE' => 1,
- 'IMPORT' => 1,
- 'MODIFY' => 1,
- 'OPTIMIZE' => 1,
- 'ORDER' => 1,
- 'PARTITION' => 1,
- 'REBUILD' => 1,
- 'REMOVE' => 1,
- 'RENAME' => 1,
- 'REORGANIZE' => 1,
- 'REPAIR' => 1,
- 'UPGRADE' => 1,
+ 'ENGINE' => array(1, 'var='),
+ 'AUTO_INCREMENT' => array(1, 'var='),
+ 'AVG_ROW_LENGTH' => array(1, 'var'),
+ 'MAX_ROWS' => array(1, 'var'),
+ 'ROW_FORMAT' => array(1, 'var'),
+ 'COMMENT' => array(1, 'var'),
+ 'ADD' => 1,
+ 'ALTER' => 1,
+ 'ANALYZE' => 1,
+ 'CHANGE' => 1,
+ 'CHECK' => 1,
+ 'COALESCE' => 1,
+ 'CONVERT' => 1,
+ 'DISABLE' => 1,
+ 'DISCARD' => 1,
+ 'DROP' => 1,
+ 'ENABLE' => 1,
+ 'IMPORT' => 1,
+ 'MODIFY' => 1,
+ 'OPTIMIZE' => 1,
+ 'ORDER' => 1,
+ 'PARTITION' => 1,
+ 'REBUILD' => 1,
+ 'REMOVE' => 1,
+ 'RENAME' => 1,
+ 'REORGANIZE' => 1,
+ 'REPAIR' => 1,
+ 'UPGRADE' => 1,
- 'COLUMN' => 2,
- 'CONSTRAINT' => 2,
- 'DEFAULT' => 2,
- 'TO' => 2,
- 'BY' => 2,
- 'FOREIGN' => 2,
- 'FULLTEXT' => 2,
- 'KEY' => 2,
- 'KEYS' => 2,
- 'PARTITIONING' => 2,
- 'PRIMARY KEY' => 2,
- 'SPATIAL' => 2,
- 'TABLESPACE' => 2,
- 'INDEX' => 2,
+ 'COLUMN' => 2,
+ 'CONSTRAINT' => 2,
+ 'DEFAULT' => 2,
+ 'TO' => 2,
+ 'BY' => 2,
+ 'FOREIGN' => 2,
+ 'FULLTEXT' => 2,
+ 'KEY' => 2,
+ 'KEYS' => 2,
+ 'PARTITIONING' => 2,
+ 'PRIMARY KEY' => 2,
+ 'SPATIAL' => 2,
+ 'TABLESPACE' => 2,
+ 'INDEX' => 2,
);
/**
- * All view options
+ * All view options.
*
* @var array
*/
public static $VIEW_OPTIONS = array(
- 'AS' => 1,
+ 'AS' => 1,
);
/**
@@ -121,20 +117,20 @@ class AlterOperation extends Component
public $unknown = array();
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return AlterOperation
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new AlterOperation();
+ $ret = new self();
/**
* Counts brackets.
*
- * @var int $brackets
+ * @var int
*/
$brackets = 0;
@@ -149,7 +145,7 @@ class AlterOperation extends Component
*
* 2 -------------------------[ , ]-----------------------> 0
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -157,7 +153,7 @@ class AlterOperation extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -223,7 +219,7 @@ class AlterOperation extends Component
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them
- if (! ($token->value == 'SET' && $list->tokens[$list->idx - 1]->value == 'CHARACTER')) {
+ if (!($token->value == 'SET' && $list->tokens[$list->idx - 1]->value == 'CHARACTER')) {
$parser->error(
__('A new statement was found, but no delimiter between it and the previous one.'),
$token
@@ -248,8 +244,8 @@ class AlterOperation extends Component
}
/**
- * @param AlterOperation $component The component to be built.
- * @param array $options Parameters for building.
+ * @param AlterOperation $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -260,6 +256,7 @@ class AlterOperation extends Component
$ret .= $component->field . ' ';
}
$ret .= TokensList::build($component->unknown);
+
return $ret;
}
}
diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php
index 2199efe..e8da84b 100644
--- a/src/Components/Array2d.php
+++ b/src/Components/Array2d.php
@@ -2,10 +2,8 @@
/**
* `VALUES` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,17 +15,15 @@ use SqlParser\TokensList;
* `VALUES` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Array2d extends Component
{
-
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return ArrayObj[]
*/
@@ -38,7 +34,7 @@ class Array2d extends Component
/**
* The number of values in each set.
*
- * @var int $count
+ * @var int
*/
$count = -1;
@@ -52,7 +48,7 @@ class Array2d extends Component
* 1 ------------------------[ , ]------------------------> 0
* 1 -----------------------[ else ]----------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -60,7 +56,7 @@ class Array2d extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -117,12 +113,13 @@ class Array2d extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param ArrayObj[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param ArrayObj[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php
index bed7fc7..8a046a8 100644
--- a/src/Components/ArrayObj.php
+++ b/src/Components/ArrayObj.php
@@ -2,10 +2,8 @@
/**
* Parses an array.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* Parses an array.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ArrayObj extends Component
{
-
/**
* The array that contains the unprocessed value of each token.
*
@@ -41,8 +37,8 @@ class ArrayObj extends Component
/**
* Constructor.
*
- * @param array $raw The unprocessed values.
- * @param array $values The processed values.
+ * @param array $raw the unprocessed values
+ * @param array $values the processed values
*/
public function __construct(array $raw = array(), array $values = array())
{
@@ -51,41 +47,41 @@ class ArrayObj extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return ArrayObj|Component[]
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = empty($options['type']) ? new ArrayObj() : array();
+ $ret = empty($options['type']) ? new self() : array();
/**
* The last raw expression.
*
- * @var string $lastRaw
+ * @var string
*/
$lastRaw = '';
/**
* The last value.
*
- * @var string $lastValue
+ * @var string
*/
$lastValue = '';
/**
* Counts brackets.
*
- * @var int $brackets
+ * @var int
*/
$brackets = 0;
/**
* Last separator (bracket or comma).
*
- * @var boolean $isCommaLast
+ * @var bool
*/
$isCommaLast = false;
@@ -93,7 +89,7 @@ class ArrayObj extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -175,8 +171,8 @@ class ArrayObj extends Component
}
/**
- * @param ArrayObj|ArrayObj[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param ArrayObj|ArrayObj[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php
index df5a1bd..0971ed8 100644
--- a/src/Components/CaseExpression.php
+++ b/src/Components/CaseExpression.php
@@ -1,11 +1,9 @@
<?php
/**
- * Parses a reference to a CASE expression
- *
- * @package SqlParser
- * @subpackage Components
+ * Parses a reference to a CASE expression.
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -13,48 +11,45 @@ use SqlParser\Parser;
use SqlParser\Token;
use SqlParser\TokensList;
-
/**
- * Parses a reference to a CASE expression
+ * Parses a reference to a CASE expression.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CaseExpression extends Component
{
-
/**
- * The value to be compared
+ * The value to be compared.
*
* @var Expression
*/
public $value;
/**
- * The conditions in WHEN clauses
+ * The conditions in WHEN clauses.
*
* @var array
*/
public $conditions;
/**
- * The results matching with the WHEN clauses
+ * The results matching with the WHEN clauses.
*
* @var array
*/
public $results;
/**
- * The values to be compared against
+ * The values to be compared against.
*
* @var array
*/
public $compare_values;
/**
- * The result in ELSE section of expr
+ * The result in ELSE section of expr.
*
* @var array
*/
@@ -62,45 +57,42 @@ class CaseExpression extends Component
/**
* Constructor.
- *
*/
public function __construct()
{
}
/**
- *
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
*
* @return Expression
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new CaseExpression();
+ $ret = new self();
/**
- * State of parser
+ * State of parser.
*
- * @var int $parser
+ * @var int
*/
$state = 0;
/**
- * Syntax type (type 0 or type 1)
+ * Syntax type (type 0 or type 1).
*
- * @var int $type
+ * @var int
*/
$type = 0;
++$list->idx; // Skip 'CASE'
for (; $list->idx < $list->count; ++$list->idx) {
-
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -205,12 +197,13 @@ class CaseExpression extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Expression $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Expression $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/Condition.php b/src/Components/Condition.php
index c69441a..1971c09 100644
--- a/src/Components/Condition.php
+++ b/src/Components/Condition.php
@@ -2,10 +2,8 @@
/**
* `WHERE` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* `WHERE` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Condition extends Component
{
-
/**
* Logical operators that can be used to delimit expressions.
*
@@ -37,24 +33,24 @@ class Condition extends Component
* @var array
*/
public static $ALLOWED_KEYWORDS = array(
- 'ALL' => 1,
- 'AND' => 1,
- 'BETWEEN' => 1,
- 'EXISTS' => 1,
- 'IF' => 1,
- 'IN' => 1,
- 'INTERVAL' => 1,
- 'IS' => 1,
- 'LIKE' => 1,
- 'MATCH' => 1,
- 'NOT IN' => 1,
- 'NOT NULL' => 1,
- 'NOT' => 1,
- 'NULL' => 1,
- 'OR' => 1,
- 'REGEXP' => 1,
- 'RLIKE' => 1,
- 'XOR' => 1,
+ 'ALL' => 1,
+ 'AND' => 1,
+ 'BETWEEN' => 1,
+ 'EXISTS' => 1,
+ 'IF' => 1,
+ 'IN' => 1,
+ 'INTERVAL' => 1,
+ 'IS' => 1,
+ 'LIKE' => 1,
+ 'MATCH' => 1,
+ 'NOT IN' => 1,
+ 'NOT NULL' => 1,
+ 'NOT' => 1,
+ 'NULL' => 1,
+ 'OR' => 1,
+ 'REGEXP' => 1,
+ 'RLIKE' => 1,
+ 'XOR' => 1,
);
/**
@@ -81,7 +77,7 @@ class Condition extends Component
/**
* Constructor.
*
- * @param string $expr The condition or the operator.
+ * @param string $expr the condition or the operator
*/
public function __construct($expr = null)
{
@@ -89,9 +85,9 @@ class Condition extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Condition[]
*/
@@ -99,12 +95,12 @@ class Condition extends Component
{
$ret = array();
- $expr = new Condition();
+ $expr = new self();
/**
* Counts brackets.
*
- * @var int $brackets
+ * @var int
*/
$brackets = 0;
@@ -115,16 +111,15 @@ class Condition extends Component
* the keyword `AND`, which is also an operator that delimits
* expressions.
*
- * @var bool $betweenBefore
+ * @var bool
*/
$betweenBefore = false;
for (; $list->idx < $list->count; ++$list->idx) {
-
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -158,12 +153,12 @@ class Condition extends Component
}
// Adding the operator.
- $expr = new Condition($token->value);
+ $expr = new self($token->value);
$expr->isOperator = true;
$ret[] = $expr;
// Preparing to parse another condition.
- $expr = new Condition();
+ $expr = new self();
continue;
}
}
@@ -211,12 +206,13 @@ class Condition extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Condition[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Condition[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php
index 86bb315..567602a 100644
--- a/src/Components/CreateDefinition.php
+++ b/src/Components/CreateDefinition.php
@@ -4,10 +4,8 @@
* Parses the create definition of a column or a key.
*
* Used for parsing `CREATE TABLE` statement.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Context;
@@ -22,42 +20,39 @@ use SqlParser\TokensList;
* Used for parsing `CREATE TABLE` statement.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CreateDefinition extends Component
{
-
/**
* All field options.
*
* @var array
*/
public static $FIELD_OPTIONS = array(
-
// Tells the `OptionsArray` to not sort the options.
// See the note below.
- '_UNSORTED' => true,
-
- 'NOT NULL' => 1,
- 'NULL' => 1,
- 'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)),
- 'AUTO_INCREMENT' => 3,
- 'PRIMARY' => 4,
- 'PRIMARY KEY' => 4,
- 'UNIQUE' => 4,
- 'UNIQUE KEY' => 4,
- 'COMMENT' => array(5, 'var'),
- 'COLUMN_FORMAT' => array(6, 'var'),
- 'ON UPDATE' => array(7, 'expr'),
+ '_UNSORTED' => true,
+
+ 'NOT NULL' => 1,
+ 'NULL' => 1,
+ 'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)),
+ 'AUTO_INCREMENT' => 3,
+ 'PRIMARY' => 4,
+ 'PRIMARY KEY' => 4,
+ 'UNIQUE' => 4,
+ 'UNIQUE KEY' => 4,
+ 'COMMENT' => array(5, 'var'),
+ 'COLUMN_FORMAT' => array(6, 'var'),
+ 'ON UPDATE' => array(7, 'expr'),
// Generated columns options.
- 'GENERATED ALWAYS' => 8,
- 'AS' => array(9, 'expr', array('parenthesesDelimited' => true)),
- 'VIRTUAL' => 10,
- 'PERSISTENT' => 11,
- 'STORED' => 11,
+ 'GENERATED ALWAYS' => 8,
+ 'AS' => array(9, 'expr', array('parenthesesDelimited' => true)),
+ 'VIRTUAL' => 10,
+ 'PERSISTENT' => 11,
+ 'STORED' => 11,
// Common entries.
//
// NOTE: Some of the common options are not in the same order which
@@ -119,11 +114,11 @@ class CreateDefinition extends Component
/**
* 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.
- * @param bool $isConstraint Whether this field is a constraint or not.
- * @param Reference $references References.
+ * @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
+ * @param bool $isConstraint whether this field is a constraint or not
+ * @param Reference $references references
*/
public function __construct(
$name = null,
@@ -144,9 +139,9 @@ class CreateDefinition extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return CreateDefinition[]
*/
@@ -154,7 +149,7 @@ class CreateDefinition extends Component
{
$ret = array();
- $expr = new CreateDefinition();
+ $expr = new self();
/**
* The state of the parser.
@@ -176,7 +171,7 @@ class CreateDefinition extends Component
* 5 ------------------------[ , ]-----------------------> 1
* 5 ------------------------[ ) ]-----------------------> 6 (-1)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -184,7 +179,7 @@ class CreateDefinition extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -219,7 +214,7 @@ class CreateDefinition extends Component
if (!$expr->isConstraint) {
$state = 2;
}
- } else if ($token->type === Token::TYPE_KEYWORD) {
+ } elseif ($token->type === Token::TYPE_KEYWORD) {
if ($token->flags & Token::FLAG_KEYWORD_RESERVED) {
// Reserved keywords can't be used
// as field names without backquotes
@@ -230,6 +225,7 @@ class CreateDefinition extends Component
),
$token
);
+
return $ret;
} else {
// Non-reserved keywords are allowed without backquotes
@@ -241,6 +237,7 @@ class CreateDefinition extends Component
__('A symbol name was expected!'),
$token
);
+
return $ret;
}
} elseif ($state === 2) {
@@ -261,7 +258,7 @@ class CreateDefinition extends Component
if ((!empty($expr->type)) || (!empty($expr->key))) {
$ret[] = $expr;
}
- $expr = new CreateDefinition();
+ $expr = new self();
if ($token->value === ',') {
$state = 1;
} elseif ($token->value === ')') {
@@ -292,12 +289,13 @@ class CreateDefinition extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param CreateDefinition|CreateDefinition[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param CreateDefinition|CreateDefinition[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/DataType.php b/src/Components/DataType.php
index 378ec9d..04ec79d 100644
--- a/src/Components/DataType.php
+++ b/src/Components/DataType.php
@@ -2,10 +2,8 @@
/**
* Parses a data type.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,25 +15,23 @@ use SqlParser\TokensList;
* Parses a data type.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class DataType extends Component
{
-
/**
* All data type options.
*
* @var array
*/
public static $DATA_TYPE_OPTIONS = array(
- 'BINARY' => 1,
- 'CHARACTER SET' => array(2, 'var'),
- 'CHARSET' => array(2, 'var'),
- 'COLLATE' => array(3, 'var'),
- 'UNSIGNED' => 4,
- 'ZEROFILL' => 5,
+ 'BINARY' => 1,
+ 'CHARACTER SET' => array(2, 'var'),
+ 'CHARSET' => array(2, 'var'),
+ 'COLLATE' => array(3, 'var'),
+ 'UNSIGNED' => 4,
+ 'ZEROFILL' => 5,
);
/**
@@ -70,9 +66,9 @@ class DataType extends Component
/**
* 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.
+ * @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,
@@ -85,15 +81,15 @@ class DataType extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return DataType
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new DataType();
+ $ret = new self();
/**
* The state of the parser.
@@ -104,7 +100,7 @@ class DataType extends Component
*
* 1 ----------------[ size and options ]----------------> 2
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -112,7 +108,7 @@ class DataType extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -138,7 +134,6 @@ class DataType extends Component
++$list->idx;
break;
}
-
}
if (empty($ret->name)) {
@@ -146,12 +141,13 @@ class DataType extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param DataType $component The component to be built.
- * @param array $options Parameters for building.
+ * @param DataType $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/Expression.php b/src/Components/Expression.php
index 7a7a333..b0c45df 100644
--- a/src/Components/Expression.php
+++ b/src/Components/Expression.php
@@ -3,10 +3,8 @@
/**
* Parses a reference to an expression (column, table or database name, function
* call, mathematical expression, etc.).
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Context;
@@ -20,20 +18,18 @@ use SqlParser\TokensList;
* call, mathematical expression, etc.).
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Expression extends Component
{
-
/**
* List of allowed reserved keywords in expressions.
*
* @var array
*/
private static $ALLOWED_KEYWORDS = array(
- 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, 'REGEXP' => 1, 'CASE' => 1
+ 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, 'REGEXP' => 1, 'CASE' => 1,
);
/**
@@ -98,11 +94,11 @@ class Expression extends Component
* string.
*
* @param string $database The name of the database or the the expression.
- * the the expression.
+ * the the expression.
* @param string $table The name of the table or the alias of the expression.
- * the alias of the expression.
- * @param string $column The name of the column.
- * @param string $alias The name of the alias.
+ * the alias of the expression.
+ * @param string $column the name of the column
+ * @param string $alias the name of the alias
*/
public function __construct($database = null, $table = null, $column = null, $alias = null)
{
@@ -118,7 +114,7 @@ class Expression extends Component
}
/**
- * Possible options:
+ * Possible options:.
*
* `field`
*
@@ -143,48 +139,48 @@ class Expression extends Component
*
* If not empty, breaks after last parentheses occurred.
*
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Expression
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new Expression();
+ $ret = new self();
/**
* Whether current tokens make an expression or a table reference.
*
- * @var bool $isExpr
+ * @var bool
*/
$isExpr = false;
/**
* Whether a period was previously found.
*
- * @var bool $dot
+ * @var bool
*/
$dot = false;
/**
* Whether an alias is expected. Is 2 if `AS` keyword was found.
*
- * @var bool $alias
+ * @var bool
*/
$alias = false;
/**
* Counts brackets.
*
- * @var int $brackets
+ * @var int
*/
$brackets = 0;
/**
* Keeps track of the last two previous tokens.
*
- * @var Token[] $prev
+ * @var Token[]
*/
$prev = array(null, null);
@@ -195,11 +191,10 @@ class Expression extends Component
}
for (; $list->idx < $list->count; ++$list->idx) {
-
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -227,7 +222,7 @@ class Expression extends Component
$ret->subquery = $token->value;
} elseif (($token->flags & Token::FLAG_KEYWORD_FUNCTION)
&& (empty($options['parseField'])
- && ! $alias)
+ && !$alias)
) {
$isExpr = true;
} elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED)
@@ -261,7 +256,7 @@ class Expression extends Component
continue;
}
$isExpr = true;
- } elseif ($brackets === 0 && strlen($ret->expr) > 0 && ! $alias) {
+ } elseif ($brackets === 0 && strlen($ret->expr) > 0 && !$alias) {
/* End of expression */
break;
}
@@ -408,12 +403,13 @@ class Expression extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Expression|Expression[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Expression|Expression[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php
index e2aa86e..1901048 100644
--- a/src/Components/ExpressionArray.php
+++ b/src/Components/ExpressionArray.php
@@ -2,10 +2,8 @@
/**
* Parses a list of expressions delimited by a comma.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,17 +15,15 @@ use SqlParser\TokensList;
* Parses a list of expressions delimited by a comma.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ExpressionArray extends Component
{
-
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Expression[]
*/
@@ -45,7 +41,7 @@ class ExpressionArray extends Component
* 1 ------------------------[ , ]------------------------> 0
* 1 -----------------------[ else ]----------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -53,7 +49,7 @@ class ExpressionArray extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -109,12 +105,13 @@ class ExpressionArray extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Expression[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Expression[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -124,6 +121,7 @@ class ExpressionArray extends Component
foreach ($component as $frag) {
$ret[] = $frag::build($frag);
}
+
return implode($ret, ', ');
}
}
diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php
index e260532..3d9b33b 100644
--- a/src/Components/FunctionCall.php
+++ b/src/Components/FunctionCall.php
@@ -2,10 +2,8 @@
/**
* Parses a function call.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* Parses a function call.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class FunctionCall extends Component
{
-
/**
* The name of this function.
*
@@ -32,7 +28,7 @@ class FunctionCall extends Component
public $name;
/**
- * The list of parameters
+ * The list of parameters.
*
* @var ArrayObj
*/
@@ -41,8 +37,8 @@ class FunctionCall extends Component
/**
* Constructor.
*
- * @param string $name The name of the function to be called.
- * @param array|ArrayObj $parameters The parameters of this function.
+ * @param string $name the name of the function to be called
+ * @param array|ArrayObj $parameters the parameters of this function
*/
public function __construct($name = null, $parameters = null)
{
@@ -55,15 +51,15 @@ class FunctionCall extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return FunctionCall
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new FunctionCall();
+ $ret = new self();
/**
* The state of the parser.
@@ -74,7 +70,7 @@ class FunctionCall extends Component
*
* 1 --------------------[ parameters ]-------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -82,7 +78,7 @@ class FunctionCall extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -105,15 +101,14 @@ class FunctionCall extends Component
}
break;
}
-
}
return $ret;
}
/**
- * @param FunctionCall $component The component to be built.
- * @param array $options Parameters for building.
+ * @param FunctionCall $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php
index 1a182ff..c7d0d40 100644
--- a/src/Components/IntoKeyword.php
+++ b/src/Components/IntoKeyword.php
@@ -2,10 +2,8 @@
/**
* `INTO` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,24 +15,21 @@ use SqlParser\TokensList;
* `INTO` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class IntoKeyword extends Component
{
-
/**
* FIELDS/COLUMNS Options for `SELECT...INTO` statements.
*
* @var array
*/
public static $FIELDS_OPTIONS = array(
-
- 'TERMINATED BY' => array(1, 'expr'),
- 'OPTIONALLY' => 2,
- 'ENCLOSED BY' => array(3, 'expr'),
- 'ESCAPED BY' => array(4, 'expr'),
+ 'TERMINATED BY' => array(1, 'expr'),
+ 'OPTIONALLY' => 2,
+ 'ENCLOSED BY' => array(3, 'expr'),
+ 'ESCAPED BY' => array(4, 'expr'),
);
/**
@@ -43,9 +38,8 @@ class IntoKeyword extends Component
* @var array
*/
public static $LINES_OPTIONS = array(
-
- 'STARTING BY' => array(1, 'expr'),
- 'TERMINATED BY' => array(2, 'expr'),
+ 'STARTING BY' => array(1, 'expr'),
+ 'TERMINATED BY' => array(2, 'expr'),
);
/**
@@ -70,45 +64,47 @@ class IntoKeyword extends Component
public $columns;
/**
- * The values to be selected into (SELECT .. INTO @var1)
+ * The values to be selected into (SELECT .. INTO @var1).
*
* @var ExpressionArray
*/
public $values;
/**
- * Options for FIELDS/COLUMNS keyword
+ * Options for FIELDS/COLUMNS keyword.
*
* @var OptionsArray
+ *
* @see static::$FIELDS_OPTIONS
*/
public $fields_options;
/**
- * Whether to use `FIELDS` or `COLUMNS` while building
+ * Whether to use `FIELDS` or `COLUMNS` while building.
*
- * @var boolean
+ * @var bool
*/
public $fields_keyword;
/**
- * Options for OPTIONS keyword
+ * Options for OPTIONS keyword.
*
* @var OptionsArray
+ *
* @see static::$LINES_OPTIONS
*/
public $lines_options;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return IntoKeyword
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new IntoKeyword();
+ $ret = new self();
/**
* The state of the parser.
@@ -122,7 +118,7 @@ class IntoKeyword extends Component
*
* 2 ---------------------[ filename ]--------------------> 1
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -130,7 +126,7 @@ class IntoKeyword extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -199,10 +195,12 @@ class IntoKeyword extends Component
}
--$list->idx;
+
return $ret;
}
- public function parseFileOptions(Parser $parser, TokensList $list, $keyword='FIELDS') {
+ public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'FIELDS')
+ {
++$list->idx;
if ($keyword === 'FIELDS' || $keyword === 'COLUMNS') {
@@ -229,8 +227,8 @@ class IntoKeyword extends Component
}
/**
- * @param IntoKeyword $component The component to be built.
- * @param array $options Parameters for building.
+ * @param IntoKeyword $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -239,6 +237,7 @@ class IntoKeyword extends Component
if ($component->dest instanceof Expression) {
$columns = !empty($component->columns) ?
'(`' . implode('`, `', $component->columns) . '`)' : '';
+
return $component->dest . $columns;
} elseif (isset($component->values)) {
return ExpressionArray::build($component->values);
@@ -259,4 +258,4 @@ class IntoKeyword extends Component
return $ret;
}
}
-} \ No newline at end of file
+}
diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php
index 60711ce..8954482 100644
--- a/src/Components/JoinKeyword.php
+++ b/src/Components/JoinKeyword.php
@@ -2,10 +2,8 @@
/**
* `JOIN` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,40 +15,39 @@ use SqlParser\TokensList;
* `JOIN` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class JoinKeyword extends Component
{
-
/**
* Types of join.
*
* @var array
*/
public static $JOINS = array(
- 'CROSS JOIN' => 'CROSS',
- 'FULL JOIN' => 'FULL',
- 'FULL OUTER JOIN' => 'FULL',
- 'INNER JOIN' => 'INNER',
- 'JOIN' => 'JOIN',
- 'LEFT JOIN' => 'LEFT',
- 'LEFT OUTER JOIN' => 'LEFT',
- 'RIGHT JOIN' => 'RIGHT',
- 'RIGHT OUTER JOIN' => 'RIGHT',
- 'NATURAL JOIN' => 'NATURAL',
- 'NATURAL LEFT JOIN' => 'NATURAL LEFT',
- 'NATURAL RIGHT JOIN' => 'NATURAL RIGHT',
- 'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER',
- 'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER',
- 'STRAIGHT_JOIN' => 'STRAIGHT',
+ 'CROSS JOIN' => 'CROSS',
+ 'FULL JOIN' => 'FULL',
+ 'FULL OUTER JOIN' => 'FULL',
+ 'INNER JOIN' => 'INNER',
+ 'JOIN' => 'JOIN',
+ 'LEFT JOIN' => 'LEFT',
+ 'LEFT OUTER JOIN' => 'LEFT',
+ 'RIGHT JOIN' => 'RIGHT',
+ 'RIGHT OUTER JOIN' => 'RIGHT',
+ 'NATURAL JOIN' => 'NATURAL',
+ 'NATURAL LEFT JOIN' => 'NATURAL LEFT',
+ 'NATURAL RIGHT JOIN' => 'NATURAL RIGHT',
+ 'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER',
+ 'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER',
+ 'STRAIGHT_JOIN' => 'STRAIGHT',
);
/**
* Type of this join.
*
* @see static::$JOINS
+ *
* @var string
*/
public $type;
@@ -70,16 +67,16 @@ class JoinKeyword extends Component
public $on;
/**
- * Columns in Using clause
+ * Columns in Using clause.
*
* @var ArrayObj
*/
public $using;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return JoinKeyword[]
*/
@@ -87,7 +84,7 @@ class JoinKeyword extends Component
{
$ret = array();
- $expr = new JoinKeyword();
+ $expr = new self();
/**
* The state of the parser.
@@ -105,7 +102,7 @@ class JoinKeyword extends Component
*
* 4 ----------------------[ columns ]--------------------> 0
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -120,7 +117,7 @@ class JoinKeyword extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -157,7 +154,7 @@ class JoinKeyword extends Component
&& (!empty(static::$JOINS[$token->value]))
) {
$ret[] = $expr;
- $expr = new JoinKeyword();
+ $expr = new self();
$expr->type = static::$JOINS[$token->value];
$state = 1;
} else {
@@ -169,15 +166,14 @@ class JoinKeyword extends Component
} elseif ($state === 3) {
$expr->on = Condition::parse($parser, $list);
$ret[] = $expr;
- $expr = new JoinKeyword();
+ $expr = new self();
$state = 0;
} elseif ($state === 4) {
$expr->using = ArrayObj::parse($parser, $list);
$ret[] = $expr;
- $expr = new JoinKeyword();
+ $expr = new self();
$state = 0;
}
-
}
if (!empty($expr->type)) {
@@ -185,12 +181,13 @@ class JoinKeyword extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param JoinKeyword[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param JoinKeyword[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -204,6 +201,7 @@ class JoinKeyword extends Component
. (!empty($c->using)
? ' USING ' . ArrayObj::build($c->using) : '');
}
+
return implode(' ', $ret);
}
}
diff --git a/src/Components/Key.php b/src/Components/Key.php
index 24cc363..a33122a 100644
--- a/src/Components/Key.php
+++ b/src/Components/Key.php
@@ -2,10 +2,8 @@
/**
* Parses the definition of a key.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Context;
@@ -20,23 +18,21 @@ use SqlParser\TokensList;
* Used for parsing `CREATE TABLE` statement.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Key extends Component
{
-
/**
* All key options.
*
* @var array
*/
public static $KEY_OPTIONS = array(
- 'KEY_BLOCK_SIZE' => array(1, 'var'),
- 'USING' => array(2, 'var'),
- 'WITH PARSER' => array(3, 'var'),
- 'COMMENT' => array(4, 'var='),
+ 'KEY_BLOCK_SIZE' => array(1, 'var'),
+ 'USING' => array(2, 'var'),
+ 'WITH PARSER' => array(3, 'var'),
+ 'COMMENT' => array(4, 'var='),
);
/**
@@ -70,10 +66,10 @@ class Key extends Component
/**
* 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.
- * @param OptionsArray $options The options of this key.
+ * @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
+ * @param OptionsArray $options the options of this key
*/
public function __construct(
$name = null,
@@ -88,15 +84,15 @@ class Key extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Key
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new Key();
+ $ret = new self();
/**
* Last parsed column.
@@ -117,7 +113,7 @@ class Key extends Component
*
* 2 ---------------------[ options ]---------------------> 3
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -125,7 +121,7 @@ class Key extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -176,12 +172,13 @@ class Key extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Key $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Key $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -202,6 +199,7 @@ class Key extends Component
}
$ret .= '(' . implode(',', $columns) . ') ' . $component->options;
+
return trim($ret);
}
}
diff --git a/src/Components/Limit.php b/src/Components/Limit.php
index 13a1127..d192949 100644
--- a/src/Components/Limit.php
+++ b/src/Components/Limit.php
@@ -2,10 +2,8 @@
/**
* `LIMIT` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* `LIMIT` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Limit extends Component
{
-
/**
* The number of rows skipped.
*
@@ -41,8 +37,8 @@ class Limit extends Component
/**
* Constructor.
*
- * @param int $rowCount The row count.
- * @param int $offset The offset.
+ * @param int $rowCount the row count
+ * @param int $offset the offset
*/
public function __construct($rowCount = 0, $offset = 0)
{
@@ -51,15 +47,15 @@ class Limit extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Limit
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new Limit();
+ $ret = new self();
$offset = false;
@@ -67,7 +63,7 @@ class Limit extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -115,12 +111,13 @@ class Limit extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param Limit $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Limit $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php
index 315237f..e7694b3 100644
--- a/src/Components/OptionsArray.php
+++ b/src/Components/OptionsArray.php
@@ -2,10 +2,8 @@
/**
* Parses a list of options.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* Parses a list of options.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class OptionsArray extends Component
{
-
/**
* ArrayObj of selected options.
*
@@ -44,41 +40,41 @@ class OptionsArray extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return OptionsArray
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new OptionsArray();
+ $ret = new self();
/**
* The ID that will be assigned to duplicate options.
*
- * @var int $lastAssignedId
+ * @var int
*/
$lastAssignedId = count($options) + 1;
/**
* The option that was processed last time.
*
- * @var array $lastOption
+ * @var array
*/
$lastOption = null;
/**
* The index of the option that was processed last time.
*
- * @var int $lastOptionId
+ * @var int
*/
$lastOptionId = 0;
/**
* Counts brackets.
*
- * @var int $brackets
+ * @var int
*/
$brackets = 0;
@@ -93,7 +89,7 @@ class OptionsArray extends Component
*
* 2 ----------------------[ value ]----------------------> 0
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -101,7 +97,7 @@ class OptionsArray extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -182,7 +178,7 @@ class OptionsArray extends Component
'value' => '',
);
$state = 1;
- } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') {
+ } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') {
// This is a keyword that is followed by an expression.
// The expression is used by the specialized parser.
@@ -269,12 +265,13 @@ class OptionsArray extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param OptionsArray $component The component to be built.
- * @param array $options Parameters for building.
+ * @param OptionsArray $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -294,13 +291,14 @@ class OptionsArray extends Component
. (!empty($option['expr']) ? $option['expr'] : $option['value']);
}
}
+
return implode(' ', $options);
}
/**
* Checks if it has the specified option and returns it value or true.
*
- * @param string $key The key to be checked.
+ * @param string $key the key to be checked
* @param bool $getExpr Gets the expression instead of the value.
* The value is the processed form of the expression.
*
@@ -317,15 +315,16 @@ class OptionsArray extends Component
return true;
}
}
+
return false;
}
/**
* Removes the option from the array.
*
- * @param string $key The key to be removed.
+ * @param string $key the key to be removed
*
- * @return bool Whether the key was found and deleted or not.
+ * @return bool whether the key was found and deleted or not
*/
public function remove($key)
{
@@ -333,13 +332,16 @@ class OptionsArray extends Component
if (is_array($option)) {
if (!strcasecmp($key, $option['name'])) {
unset($this->options[$idx]);
+
return true;
}
} elseif (!strcasecmp($key, $option)) {
unset($this->options[$idx]);
+
return true;
}
}
+
return false;
}
@@ -347,15 +349,13 @@ class OptionsArray extends Component
* Merges the specified options with these ones. Values with same ID will be
* replaced.
*
- * @param array|OptionsArray $options The options to be merged.
- *
- * @return void
+ * @param array|OptionsArray $options the options to be merged
*/
public function merge($options)
{
if (is_array($options)) {
$this->options = array_merge_recursive($this->options, $options);
- } elseif ($options instanceof OptionsArray) {
+ } elseif ($options instanceof self) {
$this->options = array_merge_recursive($this->options, $options->options);
}
}
diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php
index ba773a8..1a7a5f2 100644
--- a/src/Components/OrderKeyword.php
+++ b/src/Components/OrderKeyword.php
@@ -2,10 +2,8 @@
/**
* `ORDER BY` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* `ORDER BY` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class OrderKeyword extends Component
{
-
/**
* The expression that is used for ordering.
*
@@ -41,8 +37,8 @@ class OrderKeyword extends Component
/**
* Constructor.
*
- * @param Expression $expr The expression that we are sorting by.
- * @param string $type The sorting type.
+ * @param Expression $expr the expression that we are sorting by
+ * @param string $type the sorting type
*/
public function __construct($expr = null, $type = 'ASC')
{
@@ -51,9 +47,9 @@ class OrderKeyword extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return OrderKeyword[]
*/
@@ -61,7 +57,7 @@ class OrderKeyword extends Component
{
$ret = array();
- $expr = new OrderKeyword();
+ $expr = new self();
/**
* The state of the parser.
@@ -73,7 +69,7 @@ class OrderKeyword extends Component
* 1 ------------------------[ , ]------------------------> 0
* 1 -------------------[ ASC / DESC ]--------------------> 1
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -81,7 +77,7 @@ class OrderKeyword extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -109,13 +105,12 @@ class OrderKeyword extends Component
if (!empty($expr->expr)) {
$ret[] = $expr;
}
- $expr = new OrderKeyword();
+ $expr = new self();
$state = 0;
} else {
break;
}
}
-
}
// Last iteration was not processed.
@@ -124,12 +119,13 @@ class OrderKeyword extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param OrderKeyword|OrderKeyword[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param OrderKeyword|OrderKeyword[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php
index 274555e..bc74776 100644
--- a/src/Components/ParameterDefinition.php
+++ b/src/Components/ParameterDefinition.php
@@ -2,10 +2,8 @@
/**
* The definition of a parameter of a function or procedure.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Context;
@@ -18,13 +16,11 @@ use SqlParser\TokensList;
* The definition of a parameter of a function or procedure.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ParameterDefinition extends Component
{
-
/**
* The name of the new column.
*
@@ -47,9 +43,9 @@ class ParameterDefinition extends Component
public $type;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return ParameterDefinition[]
*/
@@ -57,7 +53,7 @@ class ParameterDefinition extends Component
{
$ret = array();
- $expr = new ParameterDefinition();
+ $expr = new self();
/**
* The state of the parser.
@@ -74,7 +70,7 @@ class ParameterDefinition extends Component
* 3 ------------------------[ , ]-----------------------> 1
* 3 ------------------------[ ) ]-----------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -82,7 +78,7 @@ class ParameterDefinition extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -117,7 +113,7 @@ class ParameterDefinition extends Component
$state = 3;
} elseif ($state === 3) {
$ret[] = $expr;
- $expr = new ParameterDefinition();
+ $expr = new self();
if ($token->value === ',') {
$state = 1;
} elseif ($token->value === ')') {
@@ -133,12 +129,13 @@ class ParameterDefinition extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param ParameterDefinition[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param ParameterDefinition[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php
index 33c3692..c688f55 100644
--- a/src/Components/PartitionDefinition.php
+++ b/src/Components/PartitionDefinition.php
@@ -4,10 +4,8 @@
* Parses the create definition of a partition.
*
* Used for parsing `CREATE TABLE` statement.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -21,28 +19,26 @@ use SqlParser\TokensList;
* Used for parsing `CREATE TABLE` statement.
*
* @category Components
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class PartitionDefinition extends Component
{
-
/**
* All field options.
*
* @var array
*/
public static $OPTIONS = array(
- 'STORAGE ENGINE' => array(1, 'var'),
- 'ENGINE' => array(1, 'var'),
- 'COMMENT' => array(2, 'var'),
- 'DATA DIRECTORY' => array(3, 'var'),
- 'INDEX DIRECTORY' => array(4, 'var'),
- 'MAX_ROWS' => array(5, 'var'),
- 'MIN_ROWS' => array(6, 'var'),
- 'TABLESPACE' => array(7, 'var'),
- 'NODEGROUP' => array(8, 'var'),
+ 'STORAGE ENGINE' => array(1, 'var'),
+ 'ENGINE' => array(1, 'var'),
+ 'COMMENT' => array(2, 'var'),
+ 'DATA DIRECTORY' => array(3, 'var'),
+ 'INDEX DIRECTORY' => array(4, 'var'),
+ 'MAX_ROWS' => array(5, 'var'),
+ 'MIN_ROWS' => array(6, 'var'),
+ 'TABLESPACE' => array(7, 'var'),
+ 'NODEGROUP' => array(8, 'var'),
);
/**
@@ -88,15 +84,15 @@ class PartitionDefinition extends Component
public $options;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return PartitionDefinition
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new PartitionDefinition();
+ $ret = new self();
/**
* The state of the parser.
@@ -118,7 +114,7 @@ class PartitionDefinition extends Component
*
* 6 ------------------[ subpartitions ]------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -126,7 +122,7 @@ class PartitionDefinition extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -183,7 +179,7 @@ class PartitionDefinition extends Component
$parser,
$list,
array(
- 'type' => 'SqlParser\\Components\\PartitionDefinition'
+ 'type' => 'SqlParser\\Components\\PartitionDefinition',
)
);
++$list->idx;
@@ -193,12 +189,13 @@ class PartitionDefinition extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param PartitionDefinition|PartitionDefinition[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param PartitionDefinition|PartitionDefinition[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -211,7 +208,8 @@ class PartitionDefinition extends Component
return trim('SUBPARTITION ' . $component->name . ' ' . $component->options);
} else {
$subpartitions = empty($component->subpartitions)
- ? '' : ' ' . PartitionDefinition::build($component->subpartitions);
+ ? '' : ' ' . self::build($component->subpartitions);
+
return trim(
'PARTITION ' . $component->name
. (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ')
diff --git a/src/Components/Reference.php b/src/Components/Reference.php
index 24d633c..447e3cf 100644
--- a/src/Components/Reference.php
+++ b/src/Components/Reference.php
@@ -2,10 +2,8 @@
/**
* `REFERENCES` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Context;
@@ -18,22 +16,20 @@ use SqlParser\TokensList;
* `REFERENCES` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Reference extends Component
{
-
/**
* All references options.
*
* @var array
*/
public static $REFERENCES_OPTIONS = array(
- 'MATCH' => array(1, 'var'),
- 'ON DELETE' => array(2, 'var'),
- 'ON UPDATE' => array(3, 'var'),
+ 'MATCH' => array(1, 'var'),
+ 'ON DELETE' => array(2, 'var'),
+ 'ON UPDATE' => array(3, 'var'),
);
/**
@@ -60,9 +56,9 @@ class Reference extends Component
/**
* Constructor.
*
- * @param Expression $table The name of the table referenced.
- * @param array $columns The columns referenced.
- * @param OptionsArray $options The options.
+ * @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)
{
@@ -72,15 +68,15 @@ class Reference extends Component
}
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return Reference
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
- $ret = new Reference();
+ $ret = new self();
/**
* The state of the parser.
@@ -93,7 +89,7 @@ class Reference extends Component
*
* 2 ---------------------[ options ]--------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -101,7 +97,7 @@ class Reference extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -133,16 +129,16 @@ class Reference extends Component
++$list->idx;
break;
}
-
}
--$list->idx;
+
return $ret;
}
/**
- * @param Reference $component The component to be built.
- * @param array $options Parameters for building.
+ * @param Reference $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php
index 291bd43..84c4aed 100644
--- a/src/Components/RenameOperation.php
+++ b/src/Components/RenameOperation.php
@@ -2,10 +2,8 @@
/**
* `RENAME TABLE` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* `RENAME TABLE` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class RenameOperation extends Component
{
-
/**
* The old table name.
*
@@ -39,9 +35,9 @@ class RenameOperation extends Component
public $new;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return RenameOperation[]
*/
@@ -49,7 +45,7 @@ class RenameOperation extends Component
{
$ret = array();
- $expr = new RenameOperation();
+ $expr = new self();
/**
* The state of the parser.
@@ -65,7 +61,7 @@ class RenameOperation extends Component
* 3 ------------------------[ , ]------------------------> 0
* 3 -----------------------[ else ]----------------------> (END)
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -73,7 +69,7 @@ class RenameOperation extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -132,7 +128,7 @@ class RenameOperation extends Component
} elseif ($state === 3) {
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) {
$ret[] = $expr;
- $expr = new RenameOperation();
+ $expr = new self();
$state = 0;
} else {
break;
@@ -153,12 +149,13 @@ class RenameOperation extends Component
}
--$list->idx;
+
return $ret;
}
/**
- * @param RenameOperation $component The component to be built.
- * @param array $options Parameters for building.
+ * @param RenameOperation $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php
index cd8b854..2bd600b 100644
--- a/src/Components/SetOperation.php
+++ b/src/Components/SetOperation.php
@@ -2,10 +2,8 @@
/**
* `SET` keyword parser.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -17,13 +15,11 @@ use SqlParser\TokensList;
* `SET` keyword parser.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class SetOperation extends Component
{
-
/**
* The name of the column that is being updated.
*
@@ -39,9 +35,9 @@ class SetOperation extends Component
public $value;
/**
- * @param Parser $parser The parser that serves as context.
- * @param TokensList $list The list of tokens that are being parsed.
- * @param array $options Parameters for parsing.
+ * @param Parser $parser the parser that serves as context
+ * @param TokensList $list the list of tokens that are being parsed
+ * @param array $options parameters for parsing
*
* @return SetOperation[]
*/
@@ -49,7 +45,7 @@ class SetOperation extends Component
{
$ret = array();
- $expr = new SetOperation();
+ $expr = new self();
/**
* The state of the parser.
@@ -61,7 +57,7 @@ class SetOperation extends Component
* 1 ------------------------[ , ]------------------------> 0
* 1 ----------------------[ value ]----------------------> 1
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -69,7 +65,7 @@ class SetOperation extends Component
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -112,18 +108,19 @@ class SetOperation extends Component
$expr->column = trim($expr->column);
$expr->value = $tmp->expr;
$ret[] = $expr;
- $expr = new SetOperation();
+ $expr = new self();
$state = 0;
}
}
--$list->idx;
+
return $ret;
}
/**
- * @param SetOperation|SetOperation[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param SetOperation|SetOperation[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php
index 138a79e..8e4923a 100644
--- a/src/Components/UnionKeyword.php
+++ b/src/Components/UnionKeyword.php
@@ -2,10 +2,8 @@
/**
* `UNION` keyword builder.
- *
- * @package SqlParser
- * @subpackage Components
*/
+
namespace SqlParser\Components;
use SqlParser\Component;
@@ -15,16 +13,14 @@ use SqlParser\Statements\SelectStatement;
* `UNION` keyword builder.
*
* @category Keywords
- * @package SqlParser
- * @subpackage Components
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class UnionKeyword extends Component
{
-
/**
- * @param SelectStatement[] $component The component to be built.
- * @param array $options Parameters for building.
+ * @param SelectStatement[] $component the component to be built
+ * @param array $options parameters for building
*
* @return string
*/
@@ -34,6 +30,7 @@ class UnionKeyword extends Component
foreach ($component as $component) {
$tmp[] = $component[0] . ' ' . $component[1];
}
+
return implode(' ', $tmp);
}
}
diff --git a/src/Context.php b/src/Context.php
index 3685857..3ea42de 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -5,21 +5,19 @@
*
* A context is a collection of keywords, operators and functions used for
* parsing.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
/**
* Holds the configuration of the context that is currently used.
*
* @category Contexts
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class Context
{
-
/**
* The maximum length of a keyword.
*
@@ -92,7 +90,6 @@ abstract class Context
* @var array
*/
public static $OPERATORS = array(
-
// Some operators (*, =) may have ambiguous flags, because they depend on
// the context they are being used in.
// For example: 1. SELECT * FROM table; # SQL specific (wildcard)
@@ -101,22 +98,22 @@ abstract class Context
// SET @i = 0;
// @see Token::FLAG_OPERATOR_ARITHMETIC
- '%' => 1, '*' => 1, '+' => 1, '-' => 1, '/' => 1,
+ '%' => 1, '*' => 1, '+' => 1, '-' => 1, '/' => 1,
// @see Token::FLAG_OPERATOR_LOGICAL
- '!' => 2, '!=' => 2, '&&' => 2, '<' => 2, '<=' => 2,
- '<=>' => 2, '<>' => 2, '=' => 2, '>' => 2, '>=' => 2,
- '||' => 2,
+ '!' => 2, '!=' => 2, '&&' => 2, '<' => 2, '<=' => 2,
+ '<=>' => 2, '<>' => 2, '=' => 2, '>' => 2, '>=' => 2,
+ '||' => 2,
// @see Token::FLAG_OPERATOR_BITWISE
- '&' => 4, '<<' => 4, '>>' => 4, '^' => 4, '|' => 4,
- '~' => 4,
+ '&' => 4, '<<' => 4, '>>' => 4, '^' => 4, '|' => 4,
+ '~' => 4,
// @see Token::FLAG_OPERATOR_ASSIGNMENT
- ':=' => 8,
+ ':=' => 8,
// @see Token::FLAG_OPERATOR_SQL
- '(' => 16, ')' => 16, '.' => 16, ',' => 16, ';' => 16,
+ '(' => 16, ')' => 16, '.' => 16, ',' => 16, ';' => 16,
);
/**
@@ -134,77 +131,77 @@ abstract class Context
// Compatibility mode for Microsoft's SQL server.
// This is the equivalent of ANSI_QUOTES.
- const COMPAT_MYSQL = 2;
+ const COMPAT_MYSQL = 2;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_allow_invalid_dates
- const ALLOW_INVALID_DATES = 1;
+ const ALLOW_INVALID_DATES = 1;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_ansi_quotes
- const ANSI_QUOTES = 2;
+ const ANSI_QUOTES = 2;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_error_for_division_by_zero
- const ERROR_FOR_DIVISION_BY_ZERO = 4;
+ const ERROR_FOR_DIVISION_BY_ZERO = 4;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_high_not_precedence
- const HIGH_NOT_PRECEDENCE = 8;
+ const HIGH_NOT_PRECEDENCE = 8;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_ignore_space
- const IGNORE_SPACE = 16;
+ const IGNORE_SPACE = 16;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_auto_create_user
- const NO_AUTO_CREATE_USER = 32;
+ const NO_AUTO_CREATE_USER = 32;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_auto_value_on_zero
- const NO_AUTO_VALUE_ON_ZERO = 64;
+ const NO_AUTO_VALUE_ON_ZERO = 64;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_backslash_escapes
- const NO_BACKSLASH_ESCAPES = 128;
+ const NO_BACKSLASH_ESCAPES = 128;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_dir_in_create
- const NO_DIR_IN_CREATE = 256;
+ const NO_DIR_IN_CREATE = 256;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_dir_in_create
- const NO_ENGINE_SUBSTITUTION = 512;
+ const NO_ENGINE_SUBSTITUTION = 512;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_field_options
- const NO_FIELD_OPTIONS = 1024;
+ const NO_FIELD_OPTIONS = 1024;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_key_options
- const NO_KEY_OPTIONS = 2048;
+ const NO_KEY_OPTIONS = 2048;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_table_options
- const NO_TABLE_OPTIONS = 4096;
+ const NO_TABLE_OPTIONS = 4096;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_unsigned_subtraction
- const NO_UNSIGNED_SUBTRACTION = 8192;
+ const NO_UNSIGNED_SUBTRACTION = 8192;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_zero_date
- const NO_ZERO_DATE = 16384;
+ const NO_ZERO_DATE = 16384;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_zero_in_date
- const NO_ZERO_IN_DATE = 32768;
+ const NO_ZERO_IN_DATE = 32768;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_only_full_group_by
- const ONLY_FULL_GROUP_BY = 65536;
+ const ONLY_FULL_GROUP_BY = 65536;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_pipes_as_concat
- const PIPES_AS_CONCAT = 131072;
+ const PIPES_AS_CONCAT = 131072;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_real_as_float
- const REAL_AS_FLOAT = 262144;
+ const REAL_AS_FLOAT = 262144;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_all_tables
- const STRICT_ALL_TABLES = 524288;
+ const STRICT_ALL_TABLES = 524288;
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_trans_tables
- const STRICT_TRANS_TABLES = 1048576;
+ const STRICT_TRANS_TABLES = 1048576;
// Custom modes.
// The table and column names and any other field that must be escaped will
// not be.
// Reserved keywords are being escaped regardless this mode is used or not.
- const NO_ENCLOSING_QUOTES = 1073741824;
+ const NO_ENCLOSING_QUOTES = 1073741824;
/*
* Combination SQL Modes
@@ -212,31 +209,31 @@ abstract class Context
*/
// REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE
- const SQL_MODE_ANSI = 393234;
+ const SQL_MODE_ANSI = 393234;
// PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
// NO_TABLE_OPTIONS, NO_FIELD_OPTIONS,
- const SQL_MODE_DB2 = 138258;
+ const SQL_MODE_DB2 = 138258;
// PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
// NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER
- const SQL_MODE_MAXDB = 138290;
+ const SQL_MODE_MAXDB = 138290;
// PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
// NO_TABLE_OPTIONS, NO_FIELD_OPTIONS
- const SQL_MODE_MSSQL = 138258;
+ const SQL_MODE_MSSQL = 138258;
// PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
// NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER
- const SQL_MODE_ORACLE = 138290;
+ const SQL_MODE_ORACLE = 138290;
// PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
// NO_TABLE_OPTIONS, NO_FIELD_OPTIONS
- const SQL_MODE_POSTGRESQL = 138258;
+ const SQL_MODE_POSTGRESQL = 138258;
// STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE,
// ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER
- const SQL_MODE_TRADITIONAL = 1622052;
+ const SQL_MODE_TRADITIONAL = 1622052;
// -------------------------------------------------------------------------
// Keyword.
@@ -244,8 +241,8 @@ abstract class Context
/**
* Checks if the given string is a keyword.
*
- * @param string $str String to be checked.
- * @param bool $isReserved Checks if the keyword is reserved.
+ * @param string $str string to be checked
+ * @param bool $isReserved checks if the keyword is reserved
*
* @return int
*/
@@ -259,6 +256,7 @@ abstract class Context
return null;
}
}
+
return static::$KEYWORDS[$str];
}
@@ -271,15 +269,16 @@ abstract class Context
/**
* Checks if the given string is an operator.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
- * @return int The appropriate flag for the operator.
+ * @return int the appropriate flag for the operator
*/
public static function isOperator($str)
{
if (!isset(static::$OPERATORS[$str])) {
return null;
}
+
return static::$OPERATORS[$str];
}
@@ -289,7 +288,7 @@ abstract class Context
/**
* Checks if the given character is a whitespace.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
* @return bool
*/
@@ -304,9 +303,9 @@ abstract class Context
/**
* Checks if the given string is the beginning of a whitespace.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
- * @return int The appropriate flag for the comment type.
+ * @return int the appropriate flag for the comment type
*/
public static function isComment($str)
{
@@ -323,6 +322,7 @@ abstract class Context
) {
return Token::FLAG_COMMENT_SQL;
}
+
return null;
}
@@ -334,13 +334,14 @@ abstract class Context
* This actually check only for `TRUE` and `FALSE` because `1` or `0` are
* actually numbers and are parsed by specific methods.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
* @return bool
*/
public static function isBool($str)
{
$str = strtoupper($str);
+
return ($str === 'TRUE') || ($str === 'FALSE');
}
@@ -350,7 +351,7 @@ abstract class Context
/**
* Checks if the given character can be a part of a number.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
* @return bool
*/
@@ -367,9 +368,9 @@ abstract class Context
* Checks if the given character is the beginning of a symbol. A symbol
* can be either a variable or a field name.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
- * @return int The appropriate flag for the symbol type.
+ * @return int the appropriate flag for the symbol type
*/
public static function isSymbol($str)
{
@@ -378,6 +379,7 @@ abstract class Context
} elseif ($str[0] === '`') {
return Token::FLAG_SYMBOL_BACKTICK;
}
+
return null;
}
@@ -387,9 +389,9 @@ abstract class Context
/**
* Checks if the given character is the beginning of a string.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
- * @return int The appropriate flag for the string type.
+ * @return int the appropriate flag for the string type
*/
public static function isString($str)
{
@@ -398,6 +400,7 @@ abstract class Context
} elseif ($str[0] === '"') {
return Token::FLAG_STRING_DOUBLE_QUOTES;
}
+
return null;
}
@@ -407,7 +410,7 @@ abstract class Context
/**
* Checks if the given character can be a separator for two lexeme.
*
- * @param string $str String to be checked.
+ * @param string $str string to be checked
*
* @return bool
*/
@@ -426,12 +429,10 @@ abstract class Context
*
* Contexts may be used by accessing the context directly.
*
- * @param string $context Name of the context or full class name that
- * defines the context.
+ * @param string $context name of the context or full class name that
+ * defines the context
*
- * @throws \Exception If the specified context doesn't exist.
- *
- * @return void
+ * @throws \Exception if the specified context doesn't exist
*/
public static function load($context = '')
{
@@ -459,8 +460,8 @@ abstract class Context
*
* @see Context::load()
*
- * @param string $context Name of the context or full class name that
- * defines the context.
+ * @param string $context name of the context or full class name that
+ * defines the context
*
* @return string The loaded context. `null` if no context was loaded.
*/
@@ -470,7 +471,7 @@ abstract class Context
* The number of replaces done by `preg_replace`.
* This actually represents whether a new context was generated or not.
*
- * @var int $count
+ * @var int
*/
$count = 0;
@@ -504,8 +505,6 @@ abstract class Context
* Sets the SQL mode.
*
* @param string $mode The list of modes. If empty, the mode is reset.
- *
- * @return void
*/
public static function setMode($mode = '')
{
@@ -522,8 +521,8 @@ abstract class Context
/**
* Escapes the symbol by adding surrounding backticks.
*
- * @param array|string $str The string to be escaped.
- * @param string $quote Quote to be used when escaping.
+ * @param array|string $str the string to be escaped
+ * @param string $quote quote to be used when escaping
*
* @return string
*/
@@ -533,16 +532,17 @@ abstract class Context
foreach ($str as $key => $value) {
$str[$key] = static::escape($value);
}
+
return $str;
}
- if ((static::$MODE & Context::NO_ENCLOSING_QUOTES)
+ if ((static::$MODE & self::NO_ENCLOSING_QUOTES)
&& (!static::isKeyword($str, true))
) {
return $str;
}
- if (static::$MODE & Context::ANSI_QUOTES) {
+ if (static::$MODE & self::ANSI_QUOTES) {
$quote = '"';
}
diff --git a/src/Exceptions/LexerException.php b/src/Exceptions/LexerException.php
index 2dd3041..e60c332 100644
--- a/src/Exceptions/LexerException.php
+++ b/src/Exceptions/LexerException.php
@@ -2,23 +2,19 @@
/**
* Exception thrown by the lexer.
- *
- * @package SqlParser
- * @subpackage Exceptions
*/
+
namespace SqlParser\Exceptions;
/**
* Exception thrown by the lexer.
*
* @category Exceptions
- * @package SqlParser
- * @subpackage Exceptions
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class LexerException extends \Exception
{
-
/**
* The character that produced this error.
*
@@ -36,10 +32,10 @@ class LexerException extends \Exception
/**
* Constructor.
*
- * @param string $msg The message of this exception.
- * @param string $ch The character that produced this exception.
- * @param int $pos The position of the character.
- * @param int $code The code of this error.
+ * @param string $msg the message of this exception
+ * @param string $ch the character that produced this exception
+ * @param int $pos the position of the character
+ * @param int $code the code of this error
*/
public function __construct($msg = '', $ch = '', $pos = 0, $code = 0)
{
diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php
index 81f6259..07f30c7 100644
--- a/src/Exceptions/ParserException.php
+++ b/src/Exceptions/ParserException.php
@@ -2,10 +2,8 @@
/**
* Exception thrown by the parser.
- *
- * @package SqlParser
- * @subpackage Exceptions
*/
+
namespace SqlParser\Exceptions;
use SqlParser\Token;
@@ -14,13 +12,11 @@ use SqlParser\Token;
* Exception thrown by the parser.
*
* @category Exceptions
- * @package SqlParser
- * @subpackage Exceptions
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ParserException extends \Exception
{
-
/**
* The token that produced this error.
*
@@ -31,9 +27,9 @@ class ParserException extends \Exception
/**
* Constructor.
*
- * @param string $msg The message of this exception.
- * @param Token $token The token that produced this exception.
- * @param int $code The code of this error.
+ * @param string $msg the message of this exception
+ * @param Token $token the token that produced this exception
+ * @param int $code the code of this error
*/
public function __construct($msg = '', Token $token = null, $code = 0)
{
diff --git a/src/Lexer.php b/src/Lexer.php
index 9de2a7a..73c4100 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -6,9 +6,8 @@
* This is one of the most important components, along with the parser.
*
* Depends on context to extract lexemes.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
require_once 'common.php';
@@ -21,7 +20,7 @@ if (!defined('USE_UTF_STRINGS')) {
// All `mb_` functions must specify the correct encoding, which is
// 'UTF-8' in order to work properly.
- /**
+ /*
* Forces usage of `UtfString` if the string is multibyte.
* `UtfString` may be slower, but it gives better results.
*
@@ -37,20 +36,19 @@ if (!defined('USE_UTF_STRINGS')) {
* The output of the lexer is affected by the context of the SQL statement.
*
* @category Lexer
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
+ *
* @see Context
*/
class Lexer
{
-
/**
* A list of methods that are used in lexing the SQL query.
*
* @var array
*/
public static $PARSER_METHODS = array(
-
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
@@ -76,7 +74,7 @@ class Lexer
'parseDelimiter', 'parseWhitespace', 'parseNumber',
'parseComment', 'parseOperator', 'parseBool', 'parseString',
- 'parseSymbol', 'parseKeyword', 'parseLabel', 'parseUnknown'
+ 'parseSymbol', 'parseKeyword', 'parseLabel', 'parseUnknown',
);
/**
@@ -161,26 +159,27 @@ class Lexer
/**
* Gets the tokens list parsed by a new instance of a lexer.
*
- * @param string|UtfString $str The query to be lexed.
- * @param bool $strict Whether strict mode should be
- * enabled or not.
- * @param string $delimiter The delimiter to be used.
+ * @param string|UtfString $str the query to be lexed
+ * @param bool $strict whether strict mode should be
+ * enabled or not
+ * @param string $delimiter the delimiter to be used
*
* @return TokensList
*/
public static function getTokens($str, $strict = false, $delimiter = null)
{
- $lexer = new Lexer($str, $strict, $delimiter);
+ $lexer = new self($str, $strict, $delimiter);
+
return $lexer->list;
}
/**
* Constructor.
*
- * @param string|UtfString $str The query to be lexed.
- * @param bool $strict Whether strict mode should be
- * enabled or not.
- * @param string $delimiter The delimiter to be used.
+ * @param string|UtfString $str the query to be lexed
+ * @param bool $strict whether strict mode should be
+ * enabled or not
+ * @param string $delimiter the delimiter to be used
*/
public function __construct($str, $strict = false, $delimiter = null)
{
@@ -212,7 +211,7 @@ class Lexer
/**
* Sets the delimiter.
*
- * @param string $delimiter The new delimiter.
+ * @param string $delimiter the new delimiter
*/
public function setDelimiter($delimiter)
{
@@ -222,8 +221,6 @@ class Lexer
/**
* Parses the string and extracts lexemes.
- *
- * @return void
*/
public function lex()
{
@@ -241,7 +238,7 @@ class Lexer
/**
* Last processed token.
*
- * @var Token $lastToken
+ * @var Token
*/
$lastToken = null;
@@ -249,7 +246,7 @@ class Lexer
/**
* The new token.
*
- * @var Token $token
+ * @var Token
*/
$token = null;
@@ -363,14 +360,12 @@ class Lexer
/**
* Creates a new error log.
*
- * @param string $msg The error message.
- * @param string $str The character that produced the error.
- * @param int $pos The position of the character.
- * @param int $code The code of the error.
+ * @param string $msg the error message
+ * @param string $str the character that produced the error
+ * @param int $pos the position of the character
+ * @param int $code the code of the error
*
- * @throws LexerException Throws the exception, if strict mode is enabled.
- *
- * @return void
+ * @throws LexerException throws the exception, if strict mode is enabled
*/
public function error($msg = '', $str = '', $pos = 0, $code = 0)
{
@@ -393,21 +388,21 @@ class Lexer
/**
* Value to be returned.
*
- * @var Token $ret
+ * @var Token
*/
$ret = null;
/**
* The value of `$this->last` where `$token` ends in `$this->str`.
*
- * @var int $iEnd
+ * @var int
*/
$iEnd = $this->last;
/**
* Whether last parsed character is a whitespace.
*
- * @var bool $lastSpace
+ * @var bool
*/
$lastSpace = false;
@@ -438,6 +433,7 @@ class Lexer
}
$this->last = $iEnd;
+
return $ret;
}
@@ -453,21 +449,21 @@ class Lexer
/**
* Value to be returned.
*
- * @var Token $ret
+ * @var Token
*/
$ret = null;
/**
* The value of `$this->last` where `$token` ends in `$this->str`.
*
- * @var int $iEnd
+ * @var int
*/
$iEnd = $this->last;
/**
* Whether last parsed character is a whitespace.
*
- * @var bool $lastSpace
+ * @var bool
*/
$lastSpace = false;
@@ -493,6 +489,7 @@ class Lexer
}
$this->last = $iEnd;
+
return $ret;
}
@@ -508,14 +505,14 @@ class Lexer
/**
* Value to be returned.
*
- * @var Token $ret
+ * @var Token
*/
$ret = null;
/**
* The value of `$this->last` where `$token` ends in `$this->str`.
*
- * @var int $iEnd
+ * @var int
*/
$iEnd = $this->last;
@@ -528,6 +525,7 @@ class Lexer
}
$this->last = $iEnd;
+
return $ret;
}
@@ -549,6 +547,7 @@ class Lexer
}
--$this->last;
+
return new Token($token, Token::TYPE_WHITESPACE);
}
@@ -612,6 +611,7 @@ class Lexer
if ($this->last < $this->len) {
$token .= $this->str[$this->last];
}
+
return new Token($token, Token::TYPE_COMMENT, $flags);
}
}
@@ -627,11 +627,13 @@ class Lexer
}
$token .= "\n"; // Adding the line ending.
}
+
return new Token($token, Token::TYPE_COMMENT, Token::FLAG_COMMENT_SQL);
}
}
$this->last = $iBak;
+
return null;
}
@@ -662,6 +664,7 @@ class Lexer
}
$this->last = $iBak;
+
return null;
}
@@ -797,16 +800,18 @@ class Lexer
|| ($state === 6) || ($state === 9)
) {
--$this->last;
+
return new Token($token, Token::TYPE_NUMBER, $flags);
}
$this->last = $iBak;
+
return null;
}
/**
* Parses a string.
*
- * @param string $quote Additional starting symbol.
+ * @param string $quote additional starting symbol
*
* @return Token
*/
@@ -844,6 +849,7 @@ class Lexer
} else {
$token .= $this->str[$this->last];
}
+
return new Token($token, Token::TYPE_STRING, $flags);
}
@@ -905,6 +911,7 @@ class Lexer
$token .= $this->str[$this->last];
}
--$this->last;
+
return new Token($token);
}
@@ -925,6 +932,7 @@ class Lexer
}
$this->last += $this->delimiterLen - 1;
+
return new Token($this->delimiter, Token::TYPE_DELIMITER);
}
}
diff --git a/src/Parser.php b/src/Parser.php
index ddefc7e..1ad5bb8 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -4,9 +4,8 @@
* Defines the parser of the library.
*
* This is one of the most important components, along with the lexer.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
require_once 'common.php';
@@ -20,76 +19,74 @@ use SqlParser\Statements\TransactionStatement;
* parse tree.
*
* @category Parser
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Parser
{
-
/**
* Array of classes that are used in parsing the SQL statements.
*
* @var array
*/
public static $STATEMENT_PARSERS = array(
-
// MySQL Utility Statements
- 'DESCRIBE' => 'SqlParser\\Statements\\ExplainStatement',
- 'DESC' => 'SqlParser\\Statements\\ExplainStatement',
- 'EXPLAIN' => 'SqlParser\\Statements\\ExplainStatement',
- 'FLUSH' => '',
- 'GRANT' => '',
- 'HELP' => '',
- 'SET PASSWORD' => '',
- 'STATUS' => '',
- 'USE' => '',
+ 'DESCRIBE' => 'SqlParser\\Statements\\ExplainStatement',
+ 'DESC' => 'SqlParser\\Statements\\ExplainStatement',
+ 'EXPLAIN' => 'SqlParser\\Statements\\ExplainStatement',
+ 'FLUSH' => '',
+ 'GRANT' => '',
+ 'HELP' => '',
+ 'SET PASSWORD' => '',
+ 'STATUS' => '',
+ 'USE' => '',
// Table Maintenance Statements
// https://dev.mysql.com/doc/refman/5.7/en/table-maintenance-sql.html
- 'ANALYZE' => 'SqlParser\\Statements\\AnalyzeStatement',
- 'BACKUP' => 'SqlParser\\Statements\\BackupStatement',
- 'CHECK' => 'SqlParser\\Statements\\CheckStatement',
- 'CHECKSUM' => 'SqlParser\\Statements\\ChecksumStatement',
- 'OPTIMIZE' => 'SqlParser\\Statements\\OptimizeStatement',
- 'REPAIR' => 'SqlParser\\Statements\\RepairStatement',
- 'RESTORE' => 'SqlParser\\Statements\\RestoreStatement',
+ 'ANALYZE' => 'SqlParser\\Statements\\AnalyzeStatement',
+ 'BACKUP' => 'SqlParser\\Statements\\BackupStatement',
+ 'CHECK' => 'SqlParser\\Statements\\CheckStatement',
+ 'CHECKSUM' => 'SqlParser\\Statements\\ChecksumStatement',
+ 'OPTIMIZE' => 'SqlParser\\Statements\\OptimizeStatement',
+ 'REPAIR' => 'SqlParser\\Statements\\RepairStatement',
+ 'RESTORE' => 'SqlParser\\Statements\\RestoreStatement',
// Database Administration Statements
// https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-server-administration.html
- 'SET' => 'SqlParser\\Statements\\SetStatement',
- 'SHOW' => 'SqlParser\\Statements\\ShowStatement',
+ 'SET' => 'SqlParser\\Statements\\SetStatement',
+ 'SHOW' => 'SqlParser\\Statements\\ShowStatement',
// Data Definition Statements.
// https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-data-definition.html
- 'ALTER' => 'SqlParser\\Statements\\AlterStatement',
- 'CREATE' => 'SqlParser\\Statements\\CreateStatement',
- 'DROP' => 'SqlParser\\Statements\\DropStatement',
- 'RENAME' => 'SqlParser\\Statements\\RenameStatement',
- 'TRUNCATE' => 'SqlParser\\Statements\\TruncateStatement',
+ 'ALTER' => 'SqlParser\\Statements\\AlterStatement',
+ 'CREATE' => 'SqlParser\\Statements\\CreateStatement',
+ 'DROP' => 'SqlParser\\Statements\\DropStatement',
+ 'RENAME' => 'SqlParser\\Statements\\RenameStatement',
+ 'TRUNCATE' => 'SqlParser\\Statements\\TruncateStatement',
// Data Manipulation Statements.
// https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-data-manipulation.html
- 'CALL' => 'SqlParser\\Statements\\CallStatement',
- 'DELETE' => 'SqlParser\\Statements\\DeleteStatement',
- 'DO' => '',
- 'HANDLER' => '',
- 'INSERT' => 'SqlParser\\Statements\\InsertStatement',
- 'LOAD' => '',
- 'REPLACE' => 'SqlParser\\Statements\\ReplaceStatement',
- 'SELECT' => 'SqlParser\\Statements\\SelectStatement',
- 'UPDATE' => 'SqlParser\\Statements\\UpdateStatement',
+ 'CALL' => 'SqlParser\\Statements\\CallStatement',
+ 'DELETE' => 'SqlParser\\Statements\\DeleteStatement',
+ 'DO' => '',
+ 'HANDLER' => '',
+ 'INSERT' => 'SqlParser\\Statements\\InsertStatement',
+ 'LOAD' => '',
+ 'REPLACE' => 'SqlParser\\Statements\\ReplaceStatement',
+ 'SELECT' => 'SqlParser\\Statements\\SelectStatement',
+ 'UPDATE' => 'SqlParser\\Statements\\UpdateStatement',
// Prepared Statements.
// https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html
- 'DEALLOCATE' => '',
- 'EXECUTE' => '',
- 'PREPARE' => '',
+ 'DEALLOCATE' => '',
+ 'EXECUTE' => '',
+ 'PREPARE' => '',
// Transactional and Locking Statements
// https://dev.mysql.com/doc/refman/5.7/en/commit.html
- 'BEGIN' => 'SqlParser\\Statements\\TransactionStatement',
- 'COMMIT' => 'SqlParser\\Statements\\TransactionStatement',
- 'ROLLBACK' => 'SqlParser\\Statements\\TransactionStatement',
+ 'BEGIN' => 'SqlParser\\Statements\\TransactionStatement',
+ 'COMMIT' => 'SqlParser\\Statements\\TransactionStatement',
+ 'ROLLBACK' => 'SqlParser\\Statements\\TransactionStatement',
'START TRANSACTION' => 'SqlParser\\Statements\\TransactionStatement',
);
@@ -99,216 +96,213 @@ class Parser
* @var array
*/
public static $KEYWORD_PARSERS = array(
-
// This is not a proper keyword and was added here to help the
// formatter.
- 'PARTITION BY' => array(),
- 'SUBPARTITION BY' => array(),
+ 'PARTITION BY' => array(),
+ 'SUBPARTITION BY' => array(),
// This is not a proper keyword and was added here to help the
// builder.
- '_OPTIONS' => array(
- 'class' => 'SqlParser\\Components\\OptionsArray',
- 'field' => 'options',
+ '_OPTIONS' => array(
+ 'class' => 'SqlParser\\Components\\OptionsArray',
+ 'field' => 'options',
),
- '_END_OPTIONS' => array(
- 'class' => 'SqlParser\\Components\\OptionsArray',
- 'field' => 'end_options',
+ '_END_OPTIONS' => array(
+ 'class' => 'SqlParser\\Components\\OptionsArray',
+ 'field' => 'end_options',
),
-
- 'UNION' => array(
- 'class' => 'SqlParser\\Components\\UnionKeyword',
- 'field' => 'union',
+ 'UNION' => array(
+ 'class' => 'SqlParser\\Components\\UnionKeyword',
+ 'field' => 'union',
),
- 'UNION ALL' => array(
- 'class' => 'SqlParser\\Components\\UnionKeyword',
- 'field' => 'union',
+ 'UNION ALL' => array(
+ 'class' => 'SqlParser\\Components\\UnionKeyword',
+ 'field' => 'union',
),
- 'UNION DISTINCT' => array(
- 'class' => 'SqlParser\\Components\\UnionKeyword',
- 'field' => 'union',
+ 'UNION DISTINCT' => array(
+ 'class' => 'SqlParser\\Components\\UnionKeyword',
+ 'field' => 'union',
),
// Actual clause parsers.
- 'ALTER' => array(
- 'class' => 'SqlParser\\Components\\Expression',
- 'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'ANALYZE' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'BACKUP' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CALL' => array(
- 'class' => 'SqlParser\\Components\\FunctionCall',
- 'field' => 'call',
- ),
- 'CHECK' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CHECKSUM' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'CROSS JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'DROP' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'fields',
- 'options' => array('parseField' => 'table'),
- ),
- 'FROM' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'from',
- 'options' => array('field' => 'table'),
- ),
- 'GROUP BY' => array(
- 'class' => 'SqlParser\\Components\\OrderKeyword',
- 'field' => 'group',
- ),
- 'HAVING' => array(
- 'class' => 'SqlParser\\Components\\Condition',
- 'field' => 'having',
- ),
- 'INTO' => array(
- 'class' => 'SqlParser\\Components\\IntoKeyword',
- 'field' => 'into',
- ),
- 'JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'LEFT JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'LEFT OUTER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'ON' => array(
- 'class' => 'SqlParser\\Components\\Expression',
- 'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'RIGHT JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'RIGHT OUTER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'INNER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'FULL JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'FULL OUTER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'NATURAL JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'NATURAL LEFT JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'NATURAL RIGHT JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'NATURAL LEFT OUTER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'NATURAL RIGHT OUTER JOIN' => array(
- 'class' => 'SqlParser\\Components\\JoinKeyword',
- 'field' => 'join',
- ),
- 'LIMIT' => array(
- 'class' => 'SqlParser\\Components\\Limit',
- 'field' => 'limit',
- ),
- 'OPTIMIZE' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'ORDER BY' => array(
- 'class' => 'SqlParser\\Components\\OrderKeyword',
- 'field' => 'order',
- ),
- 'PARTITION' => array(
- 'class' => 'SqlParser\\Components\\ArrayObj',
- 'field' => 'partition',
- ),
- 'PROCEDURE' => array(
- 'class' => 'SqlParser\\Components\\FunctionCall',
- 'field' => 'procedure',
- ),
- 'RENAME' => array(
- 'class' => 'SqlParser\\Components\\RenameOperation',
- 'field' => 'renames',
- ),
- 'REPAIR' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
+ 'ALTER' => array(
+ 'class' => 'SqlParser\\Components\\Expression',
+ 'field' => 'table',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'ANALYZE' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'BACKUP' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'CALL' => array(
+ 'class' => 'SqlParser\\Components\\FunctionCall',
+ 'field' => 'call',
+ ),
+ 'CHECK' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'CHECKSUM' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'CROSS JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'DROP' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'fields',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'FROM' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'from',
+ 'options' => array('field' => 'table'),
+ ),
+ 'GROUP BY' => array(
+ 'class' => 'SqlParser\\Components\\OrderKeyword',
+ 'field' => 'group',
+ ),
+ 'HAVING' => array(
+ 'class' => 'SqlParser\\Components\\Condition',
+ 'field' => 'having',
+ ),
+ 'INTO' => array(
+ 'class' => 'SqlParser\\Components\\IntoKeyword',
+ 'field' => 'into',
+ ),
+ 'JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'LEFT JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'LEFT OUTER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'ON' => array(
+ 'class' => 'SqlParser\\Components\\Expression',
+ 'field' => 'table',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'RIGHT JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'RIGHT OUTER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'INNER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'FULL JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'FULL OUTER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'NATURAL JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'NATURAL LEFT JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'NATURAL RIGHT JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'NATURAL LEFT OUTER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'NATURAL RIGHT OUTER JOIN' => array(
+ 'class' => 'SqlParser\\Components\\JoinKeyword',
+ 'field' => 'join',
+ ),
+ 'LIMIT' => array(
+ 'class' => 'SqlParser\\Components\\Limit',
+ 'field' => 'limit',
+ ),
+ 'OPTIMIZE' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'ORDER BY' => array(
+ 'class' => 'SqlParser\\Components\\OrderKeyword',
+ 'field' => 'order',
+ ),
+ 'PARTITION' => array(
+ 'class' => 'SqlParser\\Components\\ArrayObj',
+ 'field' => 'partition',
+ ),
+ 'PROCEDURE' => array(
+ 'class' => 'SqlParser\\Components\\FunctionCall',
+ 'field' => 'procedure',
+ ),
+ 'RENAME' => array(
+ 'class' => 'SqlParser\\Components\\RenameOperation',
+ 'field' => 'renames',
+ ),
+ 'REPAIR' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'RESTORE' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
),
- 'RESTORE' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
+ 'SET' => array(
+ 'class' => 'SqlParser\\Components\\SetOperation',
+ 'field' => 'set',
),
- 'SET' => array(
- 'class' => 'SqlParser\\Components\\SetOperation',
- 'field' => 'set',
+ 'SELECT' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'expr',
),
- 'SELECT' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'expr',
+ 'TRUNCATE' => array(
+ 'class' => 'SqlParser\\Components\\Expression',
+ 'field' => 'table',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'UPDATE' => array(
+ 'class' => 'SqlParser\\Components\\ExpressionArray',
+ 'field' => 'tables',
+ 'options' => array('parseField' => 'table'),
+ ),
+ 'VALUE' => array(
+ 'class' => 'SqlParser\\Components\\Array2d',
+ 'field' => 'values',
+ ),
+ 'VALUES' => array(
+ 'class' => 'SqlParser\\Components\\Array2d',
+ 'field' => 'values',
+ ),
+ 'WHERE' => array(
+ 'class' => 'SqlParser\\Components\\Condition',
+ 'field' => 'where',
),
- 'TRUNCATE' => array(
- 'class' => 'SqlParser\\Components\\Expression',
- 'field' => 'table',
- 'options' => array('parseField' => 'table'),
- ),
- 'UPDATE' => array(
- 'class' => 'SqlParser\\Components\\ExpressionArray',
- 'field' => 'tables',
- 'options' => array('parseField' => 'table'),
- ),
- 'VALUE' => array(
- 'class' => 'SqlParser\\Components\\Array2d',
- 'field' => 'values',
- ),
- 'VALUES' => array(
- 'class' => 'SqlParser\\Components\\Array2d',
- 'field' => 'values',
- ),
- 'WHERE' => array(
- 'class' => 'SqlParser\\Components\\Condition',
- 'field' => 'where',
- ),
-
);
/**
@@ -357,8 +351,8 @@ class Parser
/**
* Constructor.
*
- * @param string|UtfString|TokensList $list The list of tokens to be parsed.
- * @param bool $strict Whether strict mode should be enabled or not.
+ * @param string|UtfString|TokensList $list the list of tokens to be parsed
+ * @param bool $strict whether strict mode should be enabled or not
*/
public function __construct($list = null, $strict = false)
{
@@ -378,44 +372,41 @@ class Parser
/**
* Builds the parse trees.
- *
- * @return void
*/
public function parse()
{
-
/**
* Last transaction.
*
- * @var TransactionStatement $lastTransaction
+ * @var TransactionStatement
*/
$lastTransaction = null;
/**
* Last parsed statement.
*
- * @var Statement $lastStatement
+ * @var Statement
*/
$lastStatement = null;
/**
* Union's type or false for no union.
*
- * @var bool|string $unionType
+ * @var bool|string
*/
$unionType = false;
/**
* The index of the last token from the last statement.
*
- * @var int $prevLastIdx
+ * @var int
*/
$prevLastIdx = -1;
/**
* The list of tokens.
*
- * @var TokensList $list
+ * @var TokensList
*/
$list = &$this->list;
@@ -423,7 +414,7 @@ class Parser
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -485,14 +476,14 @@ class Parser
/**
* The name of the class that is used for parsing.
*
- * @var string $class
+ * @var string
*/
$class = static::$STATEMENT_PARSERS[$token->value];
/**
* Processed statement.
*
- * @var Statement $statement
+ * @var Statement
*/
$statement = new $class($this, $this->list);
@@ -512,13 +503,13 @@ class Parser
&& ($lastStatement instanceof SelectStatement)
&& ($statement instanceof SelectStatement)
) {
- /**
+ /*
* This SELECT statement.
*
* @var SelectStatement $statement
*/
- /**
+ /*
* Last SELECT statement.
*
* @var SelectStatement $lastStatement
@@ -545,8 +536,8 @@ class Parser
// Handles transactions.
if ($statement instanceof TransactionStatement) {
- /**
- * @var TransactionStatement $statement
+ /*
+ * @var TransactionStatement
*/
if ($statement->type === TransactionStatement::TYPE_BEGIN) {
$lastTransaction = $statement;
@@ -581,20 +572,17 @@ class Parser
$this->statements[] = $statement;
}
$lastStatement = $statement;
-
}
}
/**
* Creates a new error log.
*
- * @param string $msg The error message.
- * @param Token $token The token that produced the error.
- * @param int $code The code of the error.
- *
- * @throws ParserException Throws the exception, if strict mode is enabled.
+ * @param string $msg the error message
+ * @param Token $token the token that produced the error
+ * @param int $code the code of the error
*
- * @return void
+ * @throws ParserException throws the exception, if strict mode is enabled
*/
public function error($msg = '', Token $token = null, $code = 0)
{
diff --git a/src/Statement.php b/src/Statement.php
index b7c4da0..a907b99 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -5,9 +5,8 @@
* class defined here.
*
* A statement represents the result of parsing the lexemes.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
use SqlParser\Components\OptionsArray;
@@ -16,12 +15,11 @@ use SqlParser\Components\OptionsArray;
* Abstract statement definition.
*
* @category Statements
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class Statement
{
-
/**
* Options for this statement.
*
@@ -83,8 +81,8 @@ abstract class Statement
/**
* Constructor.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function __construct(Parser $parser = null, TokensList $list = null)
{
@@ -103,7 +101,7 @@ abstract class Statement
/**
* Query to be returned.
*
- * @var string $query
+ * @var string
*/
$query = '';
@@ -132,7 +130,7 @@ abstract class Statement
/**
* The name of the clause.
*
- * @var string $name
+ * @var string
*/
$name = $clause[0];
@@ -140,14 +138,15 @@ abstract class Statement
* The type of the clause.
*
* @see self::$CLAUSES
- * @var int $type
+ *
+ * @var int
*/
$type = $clause[1];
/**
* The builder (parser) of this clause.
*
- * @var Component $class
+ * @var Component
*/
$class = Parser::$KEYWORD_PARSERS[$name]['class'];
@@ -155,7 +154,7 @@ abstract class Statement
* The name of the field that is used as source for the builder.
* Same field is used to store the result of parsing.
*
- * @var string $field
+ * @var string
*/
$field = Parser::$KEYWORD_PARSERS[$name]['field'];
@@ -189,10 +188,8 @@ abstract class Statement
/**
* Parses the statements defined by the tokens list.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -200,7 +197,7 @@ abstract class Statement
* Array containing all list of clauses parsed.
* This is used to check for duplicates.
*
- * @var array $parsedClauses
+ * @var array
*/
$parsedClauses = array();
@@ -212,7 +209,7 @@ abstract class Statement
* For statements that do not have any options this is set to `true` by
* default.
*
- * @var bool $parsedOptions
+ * @var bool
*/
$parsedOptions = empty(static::$OPTIONS);
@@ -220,7 +217,7 @@ abstract class Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -282,21 +279,21 @@ abstract class Statement
/**
* The name of the class that is used for parsing.
*
- * @var Component $class
+ * @var Component
*/
$class = null;
/**
* The name of the field where the result of the parsing is stored.
*
- * @var string $field
+ * @var string
*/
$field = null;
/**
* Parser's options.
*
- * @var array $options
+ * @var array
*/
$options = array();
@@ -389,29 +386,23 @@ abstract class Statement
/**
* Function called before the token is processed.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- * @param Token $token The token that is being parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
+ * @param Token $token the token that is being parsed
*/
public function before(Parser $parser, TokensList $list, Token $token)
{
-
}
/**
* Function called after the token was processed.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- * @param Token $token The token that is being parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
+ * @param Token $token the token that is being parsed
*/
public function after(Parser $parser, TokensList $list, Token $token)
{
-
}
/**
@@ -439,12 +430,12 @@ abstract class Statement
/**
* Validates the order of the clauses in parsed statement
* Ideally this should be called after successfully
- * completing the parsing of each statement
+ * completing the parsing of each statement.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*
- * @return boolean
+ * @return bool
*/
public function validateClauseOrder($parser, $list)
{
@@ -463,9 +454,9 @@ abstract class Statement
* 0 - JOIN not found till now
* 1 - JOIN has been found
* 2 - A Non-JOIN clause has been found
- * after a previously found JOIN clause
+ * after a previously found JOIN clause.
*
- * @var int $joinStart
+ * @var int
*/
$joinStart = 0;
@@ -495,6 +486,7 @@ abstract class Statement
__('Unexpected ordering of clauses.'),
$token
);
+
return false;
} else {
$minIdx = $clauseStartIdx;
diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php
index abad5da..487ad43 100644
--- a/src/Statements/AlterStatement.php
+++ b/src/Statements/AlterStatement.php
@@ -2,10 +2,8 @@
/**
* `ALTER` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -20,13 +18,11 @@ use SqlParser\Components\OptionsArray;
* `ALTER` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class AlterStatement extends Statement
{
-
/**
* Table affected.
*
@@ -47,25 +43,23 @@ class AlterStatement extends Statement
* @var array
*/
public static $OPTIONS = array(
- 'ONLINE' => 1,
- 'OFFLINE' => 1,
- 'IGNORE' => 2,
-
- 'DATABASE' => 3,
- 'EVENT' => 3,
- 'FUNCTION' => 3,
- 'PROCEDURE' => 3,
- 'SERVER' => 3,
- 'TABLE' => 3,
- 'TABLESPACE' => 3,
- 'VIEW' => 3,
+ 'ONLINE' => 1,
+ 'OFFLINE' => 1,
+ 'IGNORE' => 2,
+
+ 'DATABASE' => 3,
+ 'EVENT' => 3,
+ 'FUNCTION' => 3,
+ 'PROCEDURE' => 3,
+ 'SERVER' => 3,
+ 'TABLE' => 3,
+ 'TABLESPACE' => 3,
+ 'VIEW' => 3,
);
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -97,7 +91,7 @@ class AlterStatement extends Statement
*
* 1 -------------------------[ , ]-----------------------> 0
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -105,7 +99,7 @@ class AlterStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
diff --git a/src/Statements/AnalyzeStatement.php b/src/Statements/AnalyzeStatement.php
index f7e8f81..aaa5850 100644
--- a/src/Statements/AnalyzeStatement.php
+++ b/src/Statements/AnalyzeStatement.php
@@ -2,10 +2,8 @@
/**
* `ANALYZE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -18,24 +16,21 @@ use SqlParser\Components\Expression;
* tbl_name [, tbl_name] ...
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class AnalyzeStatement extends Statement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'NO_WRITE_TO_BINLOG' => 2,
- 'LOCAL' => 3,
+ 'NO_WRITE_TO_BINLOG' => 2,
+ 'LOCAL' => 3,
);
/**
diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php
index df75939..b207a42 100644
--- a/src/Statements/BackupStatement.php
+++ b/src/Statements/BackupStatement.php
@@ -2,10 +2,8 @@
/**
* `BACKUP` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
@@ -14,25 +12,22 @@ namespace SqlParser\Statements;
* BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory'
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class BackupStatement extends MaintenanceStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'NO_WRITE_TO_BINLOG' => 2,
- 'LOCAL' => 3,
+ 'NO_WRITE_TO_BINLOG' => 2,
+ 'LOCAL' => 3,
- 'TO' => array(4, 'var'),
+ 'TO' => array(4, 'var'),
);
}
diff --git a/src/Statements/CallStatement.php b/src/Statements/CallStatement.php
index 42a21d7..80e49d3 100644
--- a/src/Statements/CallStatement.php
+++ b/src/Statements/CallStatement.php
@@ -2,10 +2,8 @@
/**
* `CALL` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -21,13 +19,11 @@ use SqlParser\Components\FunctionCall;
* CALL sp_name[()]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CallStatement extends Statement
{
-
/**
* The name of the function and its parameters.
*
diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php
index ef99ed3..6d852cc 100644
--- a/src/Statements/CheckStatement.php
+++ b/src/Statements/CheckStatement.php
@@ -2,10 +2,8 @@
/**
* `CHECK` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
@@ -14,27 +12,24 @@ namespace SqlParser\Statements;
* CHECK TABLE tbl_name [, tbl_name] ... [option] ...
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CheckStatement extends MaintenanceStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'FOR UPGRADE' => 2,
- 'QUICK' => 3,
- 'FAST' => 4,
- 'MEDIUM' => 5,
- 'EXTENDED' => 6,
- 'CHANGED' => 7,
+ 'FOR UPGRADE' => 2,
+ 'QUICK' => 3,
+ 'FAST' => 4,
+ 'MEDIUM' => 5,
+ 'EXTENDED' => 6,
+ 'CHANGED' => 7,
);
}
diff --git a/src/Statements/ChecksumStatement.php b/src/Statements/ChecksumStatement.php
index 8b62335..d8001e6 100644
--- a/src/Statements/ChecksumStatement.php
+++ b/src/Statements/ChecksumStatement.php
@@ -2,10 +2,8 @@
/**
* `CHECKSUM` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
@@ -14,23 +12,20 @@ namespace SqlParser\Statements;
* CHECKSUM TABLE tbl_name [, tbl_name] ... [ QUICK | EXTENDED ]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ChecksumStatement extends MaintenanceStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'QUICK' => 2,
- 'EXTENDED' => 3,
+ 'QUICK' => 2,
+ 'EXTENDED' => 3,
);
}
diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php
index ed13952..891fb50 100644
--- a/src/Statements/CreateStatement.php
+++ b/src/Statements/CreateStatement.php
@@ -2,10 +2,8 @@
/**
* `CREATE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -19,53 +17,49 @@ use SqlParser\Components\PartitionDefinition;
use SqlParser\Components\Expression;
use SqlParser\Components\OptionsArray;
use SqlParser\Components\ParameterDefinition;
-use SqlParser\Statements\SelectStatement;
/**
* `CREATE` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CreateStatement extends Statement
{
-
/**
* Options for `CREATE` statements.
*
* @var array
*/
public static $OPTIONS = array(
-
// CREATE TABLE
- 'TEMPORARY' => 1,
+ 'TEMPORARY' => 1,
// CREATE VIEW
- 'OR REPLACE' => array(2, 'var='),
- 'ALGORITHM' => array(3, 'var='),
+ 'OR REPLACE' => array(2, 'var='),
+ 'ALGORITHM' => array(3, 'var='),
// `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE`
- 'DEFINER' => array(4, 'expr='),
- 'SQL SECURITY' => array(5, 'var'),
-
- 'DATABASE' => 6,
- 'EVENT' => 6,
- 'FUNCTION' => 6,
- 'INDEX' => 6,
- 'UNIQUE INDEX' => 6,
- 'FULLTEXT INDEX' => 6,
- 'SPATIAL INDEX' => 6,
- 'PROCEDURE' => 6,
- 'SERVER' => 6,
- 'TABLE' => 6,
- 'TABLESPACE' => 6,
- 'TRIGGER' => 6,
- 'USER' => 6,
- 'VIEW' => 6,
+ 'DEFINER' => array(4, 'expr='),
+ 'SQL SECURITY' => array(5, 'var'),
+
+ 'DATABASE' => 6,
+ 'EVENT' => 6,
+ 'FUNCTION' => 6,
+ 'INDEX' => 6,
+ 'UNIQUE INDEX' => 6,
+ 'FULLTEXT INDEX' => 6,
+ 'SPATIAL INDEX' => 6,
+ 'PROCEDURE' => 6,
+ 'SERVER' => 6,
+ 'TABLE' => 6,
+ 'TABLESPACE' => 6,
+ 'TRIGGER' => 6,
+ 'USER' => 6,
+ 'VIEW' => 6,
// CREATE TABLE
- 'IF NOT EXISTS' => 7,
+ 'IF NOT EXISTS' => 7,
);
/**
@@ -74,12 +68,12 @@ class CreateStatement extends Statement
* @var array
*/
public static $DB_OPTIONS = array(
- 'CHARACTER SET' => array(1, 'var='),
- 'CHARSET' => array(1, 'var='),
- 'DEFAULT CHARACTER SET' => array(1, 'var='),
- 'DEFAULT CHARSET' => array(1, 'var='),
- 'DEFAULT COLLATE' => array(2, 'var='),
- 'COLLATE' => array(2, 'var='),
+ 'CHARACTER SET' => array(1, 'var='),
+ 'CHARSET' => array(1, 'var='),
+ 'DEFAULT CHARACTER SET' => array(1, 'var='),
+ 'DEFAULT CHARSET' => array(1, 'var='),
+ 'DEFAULT COLLATE' => array(2, 'var='),
+ 'COLLATE' => array(2, 'var='),
);
/**
@@ -88,31 +82,31 @@ class CreateStatement extends Statement
* @var array
*/
public static $TABLE_OPTIONS = array(
- 'ENGINE' => array(1, 'var='),
- 'AUTO_INCREMENT' => array(2, 'var='),
- 'AVG_ROW_LENGTH' => array(3, 'var'),
- 'CHARACTER SET' => array(4, 'var='),
- 'CHARSET' => array(4, 'var='),
- 'DEFAULT CHARACTER SET' => array(4, 'var='),
- 'DEFAULT CHARSET' => array(4, 'var='),
- 'CHECKSUM' => array(5, 'var'),
- 'DEFAULT COLLATE' => array(6, 'var='),
- 'COLLATE' => array(6, 'var='),
- 'COMMENT' => array(7, 'var='),
- 'CONNECTION' => array(8, 'var'),
- 'DATA DIRECTORY' => array(9, 'var'),
- 'DELAY_KEY_WRITE' => array(10, 'var'),
- 'INDEX DIRECTORY' => array(11, 'var'),
- 'INSERT_METHOD' => array(12, 'var'),
- 'KEY_BLOCK_SIZE' => array(13, 'var'),
- 'MAX_ROWS' => array(14, 'var'),
- 'MIN_ROWS' => array(15, 'var'),
- 'PACK_KEYS' => array(16, 'var'),
- 'PASSWORD' => array(17, 'var'),
- 'ROW_FORMAT' => array(18, 'var'),
- 'TABLESPACE' => array(19, 'var'),
- 'STORAGE' => array(20, 'var'),
- 'UNION' => array(21, 'var'),
+ 'ENGINE' => array(1, 'var='),
+ 'AUTO_INCREMENT' => array(2, 'var='),
+ 'AVG_ROW_LENGTH' => array(3, 'var'),
+ 'CHARACTER SET' => array(4, 'var='),
+ 'CHARSET' => array(4, 'var='),
+ 'DEFAULT CHARACTER SET' => array(4, 'var='),
+ 'DEFAULT CHARSET' => array(4, 'var='),
+ 'CHECKSUM' => array(5, 'var'),
+ 'DEFAULT COLLATE' => array(6, 'var='),
+ 'COLLATE' => array(6, 'var='),
+ 'COMMENT' => array(7, 'var='),
+ 'CONNECTION' => array(8, 'var'),
+ 'DATA DIRECTORY' => array(9, 'var'),
+ 'DELAY_KEY_WRITE' => array(10, 'var'),
+ 'INDEX DIRECTORY' => array(11, 'var'),
+ 'INSERT_METHOD' => array(12, 'var'),
+ 'KEY_BLOCK_SIZE' => array(13, 'var'),
+ 'MAX_ROWS' => array(14, 'var'),
+ 'MIN_ROWS' => array(15, 'var'),
+ 'PACK_KEYS' => array(16, 'var'),
+ 'PASSWORD' => array(17, 'var'),
+ 'ROW_FORMAT' => array(18, 'var'),
+ 'TABLESPACE' => array(19, 'var'),
+ 'STORAGE' => array(20, 'var'),
+ 'UNION' => array(21, 'var'),
);
/**
@@ -121,15 +115,15 @@ class CreateStatement extends Statement
* @var array
*/
public static $FUNC_OPTIONS = array(
- 'COMMENT' => array(1, 'var='),
- 'LANGUAGE SQL' => 2,
- 'DETERMINISTIC' => 3,
- 'NOT DETERMINISTIC' => 3,
- 'CONTAINS SQL' => 4,
- 'NO SQL' => 4,
- 'READS SQL DATA' => 4,
- 'MODIFIES SQL DATA' => 4,
- 'SQL SECURITY DEFINER' => array(5, 'var'),
+ 'COMMENT' => array(1, 'var='),
+ 'LANGUAGE SQL' => 2,
+ 'DETERMINISTIC' => 3,
+ 'NOT DETERMINISTIC' => 3,
+ 'CONTAINS SQL' => 4,
+ 'NO SQL' => 4,
+ 'READS SQL DATA' => 4,
+ 'MODIFIES SQL DATA' => 4,
+ 'SQL SECURITY DEFINER' => array(5, 'var'),
);
/**
@@ -138,11 +132,11 @@ class CreateStatement extends Statement
* @var array
*/
public static $TRIGGER_OPTIONS = array(
- 'BEFORE' => 1,
- 'AFTER' => 1,
- 'INSERT' => 2,
- 'UPDATE' => 2,
- 'DELETE' => 2,
+ 'BEFORE' => 1,
+ 'AFTER' => 1,
+ 'INSERT' => 2,
+ 'UPDATE' => 2,
+ 'DELETE' => 2,
);
/**
@@ -178,7 +172,7 @@ class CreateStatement extends Statement
public $fields;
/**
- * If `CREATE TABLE ... SELECT`
+ * If `CREATE TABLE ... SELECT`.
*
* Used by `CREATE TABLE`
*
@@ -187,7 +181,7 @@ class CreateStatement extends Statement
public $select;
/**
- * If `CREATE TABLE ... LIKE`
+ * If `CREATE TABLE ... LIKE`.
*
* Used by `CREATE TABLE`
*
@@ -259,7 +253,7 @@ class CreateStatement extends Statement
/**
* The body of this function or procedure. For views, it is the select
- * statement that gets the
+ * statement that gets the.
*
* Used by `CREATE FUNCTION`, `CREATE PROCEDURE` and `CREATE VIEW`.
*
@@ -340,12 +334,14 @@ class CreateStatement extends Statement
if ($this->options->has('FUNCTION')) {
$tmp = 'RETURNS ' . DataType::build($this->return);
}
+
return 'CREATE '
. OptionsArray::build($this->options) . ' '
. Expression::build($this->name) . ' '
. ParameterDefinition::build($this->parameters) . ' '
. $tmp . ' ' . TokensList::build($this->body);
}
+
return 'CREATE '
. OptionsArray::build($this->options) . ' '
. Expression::build($this->name) . ' '
@@ -353,10 +349,8 @@ class CreateStatement extends Statement
}
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -388,12 +382,12 @@ class CreateStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
$nextidx = $list->idx + 1;
while ($nextidx < $list->count && $list->tokens[$nextidx]->type == Token::TYPE_WHITESPACE) {
- $nextidx++;
+ ++$nextidx;
}
if ($this->options->has('DATABASE')) {
@@ -457,7 +451,7 @@ class CreateStatement extends Statement
* The field that is being filled (`partitionBy` or
* `subpartitionBy`).
*
- * @var string $field
+ * @var string
*/
$field = null;
@@ -466,7 +460,7 @@ class CreateStatement extends Statement
* previously. At least one bracket is required to validate the
* expression.
*
- * @var int|bool $brackets
+ * @var int|bool
*/
$brackets = false;
@@ -477,7 +471,7 @@ class CreateStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -537,7 +531,7 @@ class CreateStatement extends Statement
$parser,
$list,
array(
- 'type' => 'SqlParser\\Components\\PartitionDefinition'
+ 'type' => 'SqlParser\\Components\\PartitionDefinition',
)
);
}
diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php
index d83d0e9..621d032 100644
--- a/src/Statements/DeleteStatement.php
+++ b/src/Statements/DeleteStatement.php
@@ -2,10 +2,8 @@
/**
* `DELETE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -45,22 +43,20 @@ use SqlParser\Components\OptionsArray;
*
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class DeleteStatement extends Statement
{
-
/**
* Options for `DELETE` statements.
*
* @var array
*/
public static $OPTIONS = array(
- 'LOW_PRIORITY' => 1,
- 'QUICK' => 2,
- 'IGNORE' => 3,
+ 'LOW_PRIORITY' => 1,
+ 'QUICK' => 2,
+ 'IGNORE' => 3,
);
/**
@@ -71,15 +67,15 @@ class DeleteStatement extends Statement
* @var array
*/
public static $CLAUSES = array(
- 'DELETE' => array('DELETE', 2),
+ 'DELETE' => array('DELETE', 2),
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
- 'FROM' => array('FROM', 3),
- 'PARTITION' => array('PARTITION', 3),
- 'USING' => array('USING', 3),
- 'WHERE' => array('WHERE', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
+ '_OPTIONS' => array('_OPTIONS', 1),
+ 'FROM' => array('FROM', 3),
+ 'PARTITION' => array('PARTITION', 3),
+ 'USING' => array('USING', 3),
+ 'WHERE' => array('WHERE', 3),
+ 'ORDER BY' => array('ORDER BY', 3),
+ 'LIMIT' => array('LIMIT', 3),
);
/**
@@ -90,14 +86,14 @@ class DeleteStatement extends Statement
public $from;
/**
- * Tables used as sources for this statement
+ * Tables used as sources for this statement.
*
* @var Expression[]
*/
public $using;
/**
- * Columns used in this statement
+ * Columns used in this statement.
*
* @var Expression[]
*/
@@ -131,7 +127,6 @@ class DeleteStatement extends Statement
*/
public $limit;
-
/**
* @return string
*/
@@ -139,35 +134,31 @@ class DeleteStatement extends Statement
{
$ret = 'DELETE ' . OptionsArray::build($this->options);
- if ($this->columns != NULL && count($this->columns) > 0) {
+ if ($this->columns != null && count($this->columns) > 0) {
$ret .= ' ' . ExpressionArray::build($this->columns);
}
- if ($this->from != NULL && count($this->from) > 0) {
+ if ($this->from != null && count($this->from) > 0) {
$ret .= ' FROM ' . ExpressionArray::build($this->from);
}
- if ($this->using != NULL && count($this->using) > 0) {
+ if ($this->using != null && count($this->using) > 0) {
$ret .= ' USING ' . ExpressionArray::build($this->using);
}
- if ($this->where != NULL && count($this->where) > 0) {
+ if ($this->where != null && count($this->where) > 0) {
$ret .= ' WHERE ' . Condition::build($this->where);
}
- if ($this->order != NULL && count($this->order) > 0) {
+ if ($this->order != null && count($this->order) > 0) {
$ret .= ' ORDER BY ' . ExpressionArray::build($this->order);
}
- if ($this->limit != NULL && strlen($this->limit) > 0) {
+ if ($this->limit != null && strlen($this->limit) > 0) {
$ret .= ' LIMIT ' . Limit::build($this->limit);
}
return $ret;
-
}
-
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -194,14 +185,14 @@ class DeleteStatement extends Statement
* 2 --------------------------------[ ORDER ]----------------------------------> 5
* 2 --------------------------------[ LIMIT ]----------------------------------> 6
*
- * @var int $state
+ * @var int
*/
$state = 0;
/**
- * If the query is multi-table or not
+ * If the query is multi-table or not.
*
- * @var bool $multiTable
+ * @var bool
*/
$multiTable = false;
@@ -209,7 +200,7 @@ class DeleteStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -312,7 +303,7 @@ class DeleteStatement extends Statement
++$list->idx; // Skip 'ORDER BY'
$this->order = OrderKeyword::parse($parser, $list);
$state = 5;
- } elseif ($token->type === Token::TYPE_KEYWORD
+ } elseif ($token->type === Token::TYPE_KEYWORD
&& $token->value === 'LIMIT'
) {
++$list->idx; // Skip 'LIMIT'
diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php
index b75ab0e..ebcae4a 100644
--- a/src/Statements/DropStatement.php
+++ b/src/Statements/DropStatement.php
@@ -2,10 +2,8 @@
/**
* `DROP` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -15,35 +13,32 @@ use SqlParser\Components\Expression;
* `DROP` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class DropStatement extends Statement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'DATABASE' => 1,
+ 'EVENT' => 1,
+ 'FUNCTION' => 1,
+ 'INDEX' => 1,
+ 'LOGFILE' => 1,
+ 'PROCEDURE' => 1,
+ 'SCHEMA' => 1,
+ 'SERVER' => 1,
+ 'TABLE' => 1,
+ 'VIEW' => 1,
+ 'TABLESPACE' => 1,
+ 'TRIGGER' => 1,
- 'DATABASE' => 1,
- 'EVENT' => 1,
- 'FUNCTION' => 1,
- 'INDEX' => 1,
- 'LOGFILE' => 1,
- 'PROCEDURE' => 1,
- 'SCHEMA' => 1,
- 'SERVER' => 1,
- 'TABLE' => 1,
- 'VIEW' => 1,
- 'TABLESPACE' => 1,
- 'TRIGGER' => 1,
-
- 'TEMPORARY' => 2,
- 'IF EXISTS' => 3,
+ 'TEMPORARY' => 2,
+ 'IF EXISTS' => 3,
);
/**
@@ -54,12 +49,12 @@ class DropStatement extends Statement
* @var array
*/
public static $CLAUSES = array(
- 'DROP' => array('DROP', 2),
+ 'DROP' => array('DROP', 2),
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => array('_OPTIONS', 1),
// Used for select expressions.
- 'DROP_' => array('DROP', 1),
- 'ON' => array('ON', 3),
+ 'DROP_' => array('DROP', 1),
+ 'ON' => array('ON', 3),
);
/**
diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php
index 78c7acd..482f53f 100644
--- a/src/Statements/ExplainStatement.php
+++ b/src/Statements/ExplainStatement.php
@@ -2,21 +2,17 @@
/**
* `EXPLAIN` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
* `EXPLAIN` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ExplainStatement extends NotImplementedStatement
{
-
}
diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php
index 9db1a44..6c76df6 100644
--- a/src/Statements/InsertStatement.php
+++ b/src/Statements/InsertStatement.php
@@ -2,17 +2,14 @@
/**
* `INSERT` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
use SqlParser\Token;
use SqlParser\TokensList;
use SqlParser\Statement;
-use SqlParser\Statements\SelectStatement;
use SqlParser\Components\IntoKeyword;
use SqlParser\Components\Array2d;
use SqlParser\Components\OptionsArray;
@@ -52,23 +49,21 @@ use SqlParser\Components\SetOperation;
* [, col_name=expr] ... ]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class InsertStatement extends Statement
{
-
/**
* Options for `INSERT` statements.
*
* @var array
*/
public static $OPTIONS = array(
- 'LOW_PRIORITY' => 1,
- 'DELAYED' => 2,
- 'HIGH_PRIORITY' => 3,
- 'IGNORE' => 4,
+ 'LOW_PRIORITY' => 1,
+ 'DELAYED' => 2,
+ 'HIGH_PRIORITY' => 3,
+ 'IGNORE' => 4,
);
/**
@@ -87,7 +82,7 @@ class InsertStatement extends Statement
/**
* If SET clause is present
- * holds the SetOperation
+ * holds the SetOperation.
*
* @var SetOperation[]
*/
@@ -95,7 +90,7 @@ class InsertStatement extends Statement
/**
* If SELECT clause is present
- * holds the SelectStatement
+ * holds the SelectStatement.
*
* @var SelectStatement
*/
@@ -103,7 +98,7 @@ class InsertStatement extends Statement
/**
* If ON DUPLICATE KEY UPDATE clause is present
- * holds the SetOperation
+ * holds the SetOperation.
*
* @var SetOperation[]
*/
@@ -117,28 +112,24 @@ class InsertStatement extends Statement
$ret = 'INSERT ' . $this->options
. ' INTO ' . $this->into;
- if ($this->values != NULL && count($this->values) > 0) {
+ if ($this->values != null && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif ($this->set != NULL && count($this->set) > 0) {
+ } elseif ($this->set != null && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif ($this->select != NULL && strlen($this->select) > 0) {
+ } elseif ($this->select != null && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
- if ($this->onDuplicateSet != NULL && count($this->onDuplicateSet) > 0) {
+ if ($this->onDuplicateSet != null && count($this->onDuplicateSet) > 0) {
$ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet);
}
return $ret;
-
}
-
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -163,14 +154,13 @@ class InsertStatement extends Statement
*
* 2 -------------------------[ ON DUPLICATE KEY UPDATE ]-----------------------> 3
*
- * @var int $state
+ * @var int
*/
$state = 0;
/**
* For keeping track of semi-states on encountering
* ON DUPLICATE KEY UPDATE ...
- *
*/
$miniState = 0;
@@ -178,7 +168,7 @@ class InsertStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
@@ -242,13 +232,13 @@ class InsertStatement extends Statement
$lastCount = $miniState;
if ($miniState === 1 && $token->value === 'ON') {
- $miniState++;
+ ++$miniState;
} elseif ($miniState === 2 && $token->value === 'DUPLICATE') {
- $miniState++;
+ ++$miniState;
} elseif ($miniState === 3 && $token->value === 'KEY') {
- $miniState++;
+ ++$miniState;
} elseif ($miniState === 4 && $token->value === 'UPDATE') {
- $miniState++;
+ ++$miniState;
}
if ($lastCount === $miniState) {
diff --git a/src/Statements/MaintenanceStatement.php b/src/Statements/MaintenanceStatement.php
index 9097527..5ce55d6 100644
--- a/src/Statements/MaintenanceStatement.php
+++ b/src/Statements/MaintenanceStatement.php
@@ -2,10 +2,8 @@
/**
* Maintenance statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -22,13 +20,11 @@ use SqlParser\Components\OptionsArray;
* STMT [some options] tbl_name [, tbl_name] ... [some more options]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class MaintenanceStatement extends Statement
{
-
/**
* Tables maintained.
*
@@ -41,11 +37,9 @@ class MaintenanceStatement extends Statement
*
* Parses the additional options from the end.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- * @param Token $token The token that is being parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
+ * @param Token $token the token that is being parsed
*/
public function after(Parser $parser, TokensList $list, Token $token)
{
diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php
index 8bdff2d..6796af7 100644
--- a/src/Statements/NotImplementedStatement.php
+++ b/src/Statements/NotImplementedStatement.php
@@ -2,10 +2,8 @@
/**
* Not implemented (yet) statements.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -19,13 +17,11 @@ use SqlParser\TokensList;
* The `after` function makes the parser jump straight to the first delimiter.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class NotImplementedStatement extends Statement
{
-
/**
* The part of the statement that can't be parsed.
*
@@ -50,10 +46,8 @@ class NotImplementedStatement extends Statement
}
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
diff --git a/src/Statements/OptimizeStatement.php b/src/Statements/OptimizeStatement.php
index f688333..7fd7045 100644
--- a/src/Statements/OptimizeStatement.php
+++ b/src/Statements/OptimizeStatement.php
@@ -2,10 +2,8 @@
/**
* `OPTIMIZE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -18,24 +16,21 @@ use SqlParser\Components\Expression;
* tbl_name [, tbl_name] ...
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class OptimizeStatement extends Statement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'NO_WRITE_TO_BINLOG' => 2,
- 'LOCAL' => 3,
+ 'NO_WRITE_TO_BINLOG' => 2,
+ 'LOCAL' => 3,
);
/**
diff --git a/src/Statements/RenameStatement.php b/src/Statements/RenameStatement.php
index 0205f84..e14223c 100644
--- a/src/Statements/RenameStatement.php
+++ b/src/Statements/RenameStatement.php
@@ -2,10 +2,8 @@
/**
* `RENAME` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -21,13 +19,11 @@ use SqlParser\Components\RenameOperation;
* [, tbl_name2 TO new_tbl_name2] ...
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class RenameStatement extends Statement
{
-
/**
* The old and new names of the tables.
*
@@ -40,11 +36,9 @@ class RenameStatement extends Statement
*
* Skips the `TABLE` keyword after `RENAME`.
*
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- * @param Token $token The token that is being parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
+ * @param Token $token the token that is being parsed
*/
public function before(Parser $parser, TokensList $list, Token $token)
{
diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php
index f98fcc6..f4ce53d 100644
--- a/src/Statements/RepairStatement.php
+++ b/src/Statements/RepairStatement.php
@@ -2,10 +2,8 @@
/**
* `REPAIR` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
@@ -16,27 +14,24 @@ namespace SqlParser\Statements;
* [QUICK] [EXTENDED] [USE_FRM]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class RepairStatement extends MaintenanceStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'NO_WRITE_TO_BINLOG' => 2,
- 'LOCAL' => 3,
+ 'NO_WRITE_TO_BINLOG' => 2,
+ 'LOCAL' => 3,
- 'QUICK' => 4,
- 'EXTENDED' => 5,
- 'USE_FRM' => 6,
+ 'QUICK' => 4,
+ 'EXTENDED' => 5,
+ 'USE_FRM' => 6,
);
}
diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php
index 0e85507..0b4af13 100644
--- a/src/Statements/ReplaceStatement.php
+++ b/src/Statements/ReplaceStatement.php
@@ -2,17 +2,14 @@
/**
* `REPLACE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
use SqlParser\Token;
use SqlParser\TokensList;
use SqlParser\Statement;
-use SqlParser\Statements\SelectStatement;
use SqlParser\Components\Array2d;
use SqlParser\Components\IntoKeyword;
use SqlParser\Components\OptionsArray;
@@ -40,21 +37,19 @@ use SqlParser\Components\SetOperation;
* SELECT ...
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ReplaceStatement extends Statement
{
-
/**
* Options for `REPLACE` statements and their slot ID.
*
* @var array
*/
public static $OPTIONS = array(
- 'LOW_PRIORITY' => 1,
- 'DELAYED' => 1,
+ 'LOW_PRIORITY' => 1,
+ 'DELAYED' => 1,
);
/**
@@ -73,7 +68,7 @@ class ReplaceStatement extends Statement
/**
* If SET clause is present
- * holds the SetOperation
+ * holds the SetOperation.
*
* @var SetOperation[]
*/
@@ -81,7 +76,7 @@ class ReplaceStatement extends Statement
/**
* If SELECT clause is present
- * holds the SelectStatement
+ * holds the SelectStatement.
*
* @var SelectStatement
*/
@@ -95,23 +90,20 @@ class ReplaceStatement extends Statement
$ret = 'REPLACE ' . $this->options
. ' INTO ' . $this->into;
- if ($this->values != NULL && count($this->values) > 0) {
+ if ($this->values != null && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif ($this->set != NULL && count($this->set) > 0) {
+ } elseif ($this->set != null && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif ($this->select != NULL && strlen($this->select) > 0) {
+ } elseif ($this->select != null && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
return $ret;
}
-
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -136,7 +128,7 @@ class ReplaceStatement extends Statement
*
* 1 -------------------------[ VALUES/VALUE/SET/SELECT ]-----------------------> 2
*
- * @var int $state
+ * @var int
*/
$state = 0;
@@ -144,7 +136,7 @@ class ReplaceStatement extends Statement
/**
* Token parsed at this moment.
*
- * @var Token $token
+ * @var Token
*/
$token = $list->tokens[$list->idx];
diff --git a/src/Statements/RestoreStatement.php b/src/Statements/RestoreStatement.php
index 8500479..720f907 100644
--- a/src/Statements/RestoreStatement.php
+++ b/src/Statements/RestoreStatement.php
@@ -2,10 +2,8 @@
/**
* `RESTORE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
@@ -14,22 +12,19 @@ namespace SqlParser\Statements;
* RESTORE TABLE tbl_name [, tbl_name] ... FROM '/path/to/backup/directory'
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class RestoreStatement extends MaintenanceStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
+ 'TABLE' => 1,
- 'TABLE' => 1,
-
- 'FROM' => array(2, 'var'),
+ 'FROM' => array(2, 'var'),
);
}
diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php
index 49ed393..511334c 100644
--- a/src/Statements/SelectStatement.php
+++ b/src/Statements/SelectStatement.php
@@ -2,10 +2,8 @@
/**
* `SELECT` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -47,36 +45,34 @@ use SqlParser\Components\Condition;
* [FOR UPDATE | LOCK IN SHARE MODE]]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class SelectStatement extends Statement
{
-
/**
* Options for `SELECT` statements and their slot ID.
*
* @var array
*/
public static $OPTIONS = array(
- 'ALL' => 1,
- 'DISTINCT' => 1,
- 'DISTINCTROW' => 1,
- 'HIGH_PRIORITY' => 2,
- 'MAX_STATEMENT_TIME' => array(3, 'var='),
- 'STRAIGHT_JOIN' => 4,
- 'SQL_SMALL_RESULT' => 5,
- 'SQL_BIG_RESULT' => 6,
- 'SQL_BUFFER_RESULT' => 7,
- 'SQL_CACHE' => 8,
- 'SQL_NO_CACHE' => 8,
- 'SQL_CALC_FOUND_ROWS' => 9,
+ 'ALL' => 1,
+ 'DISTINCT' => 1,
+ 'DISTINCTROW' => 1,
+ 'HIGH_PRIORITY' => 2,
+ 'MAX_STATEMENT_TIME' => array(3, 'var='),
+ 'STRAIGHT_JOIN' => 4,
+ 'SQL_SMALL_RESULT' => 5,
+ 'SQL_BIG_RESULT' => 6,
+ 'SQL_BUFFER_RESULT' => 7,
+ 'SQL_CACHE' => 8,
+ 'SQL_NO_CACHE' => 8,
+ 'SQL_CALC_FOUND_ROWS' => 9,
);
public static $END_OPTIONS = array(
- 'FOR UPDATE' => 1,
- 'LOCK IN SHARE MODE' => 1
+ 'FOR UPDATE' => 1,
+ 'LOCK IN SHARE MODE' => 1,
);
/**
@@ -87,36 +83,36 @@ class SelectStatement extends Statement
* @var array
*/
public static $CLAUSES = array(
- 'SELECT' => array('SELECT', 2),
+ 'SELECT' => array('SELECT', 2),
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => array('_OPTIONS', 1),
// Used for selected expressions.
- '_SELECT' => array('SELECT', 1),
- 'INTO' => array('INTO', 3),
- 'FROM' => array('FROM', 3),
- 'PARTITION' => array('PARTITION', 3),
-
- 'JOIN' => array('JOIN', 1),
- 'FULL JOIN' => array('FULL JOIN', 1),
- 'INNER JOIN' => array('INNER JOIN', 1),
- 'LEFT JOIN' => array('LEFT JOIN', 1),
- 'LEFT OUTER JOIN' => array('LEFT OUTER JOIN', 1),
- 'RIGHT JOIN' => array('RIGHT JOIN', 1),
- 'RIGHT OUTER JOIN' => array('RIGHT OUTER JOIN', 1),
- 'NATURAL JOIN' => array('NATURAL JOIN', 1),
- 'NATURAL LEFT JOIN' => array('NATURAL LEFT JOIN', 1),
- 'NATURAL RIGHT JOIN' => array('NATURAL RIGHT JOIN', 1),
- 'NATURAL LEFT OUTER JOIN' => array('NATURAL LEFT OUTER JOIN', 1),
- 'NATURAL RIGHT OUTER JOIN' => array('NATURAL RIGHT JOIN', 1),
-
- 'WHERE' => array('WHERE', 3),
- 'GROUP BY' => array('GROUP BY', 3),
- 'HAVING' => array('HAVING', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
- 'PROCEDURE' => array('PROCEDURE', 3),
- 'UNION' => array('UNION', 1),
- '_END_OPTIONS' => array('_END_OPTIONS', 1)
+ '_SELECT' => array('SELECT', 1),
+ 'INTO' => array('INTO', 3),
+ 'FROM' => array('FROM', 3),
+ 'PARTITION' => array('PARTITION', 3),
+
+ 'JOIN' => array('JOIN', 1),
+ 'FULL JOIN' => array('FULL JOIN', 1),
+ 'INNER JOIN' => array('INNER JOIN', 1),
+ 'LEFT JOIN' => array('LEFT JOIN', 1),
+ 'LEFT OUTER JOIN' => array('LEFT OUTER JOIN', 1),
+ 'RIGHT JOIN' => array('RIGHT JOIN', 1),
+ 'RIGHT OUTER JOIN' => array('RIGHT OUTER JOIN', 1),
+ 'NATURAL JOIN' => array('NATURAL JOIN', 1),
+ 'NATURAL LEFT JOIN' => array('NATURAL LEFT JOIN', 1),
+ 'NATURAL RIGHT JOIN' => array('NATURAL RIGHT JOIN', 1),
+ 'NATURAL LEFT OUTER JOIN' => array('NATURAL LEFT OUTER JOIN', 1),
+ 'NATURAL RIGHT OUTER JOIN' => array('NATURAL RIGHT JOIN', 1),
+
+ 'WHERE' => array('WHERE', 3),
+ 'GROUP BY' => array('GROUP BY', 3),
+ 'HAVING' => array('HAVING', 3),
+ 'ORDER BY' => array('ORDER BY', 3),
+ 'LIMIT' => array('LIMIT', 3),
+ 'PROCEDURE' => array('PROCEDURE', 3),
+ 'UNION' => array('UNION', 1),
+ '_END_OPTIONS' => array('_END_OPTIONS', 1),
// These are available only when `UNION` is present.
// 'ORDER BY' => array('ORDER BY', 3),
// 'LIMIT' => array('LIMIT', 3),
@@ -231,8 +227,10 @@ class SelectStatement extends Statement
unset($clauses['LIMIT']);
$clauses['ORDER BY'] = array('ORDER BY', 3);
$clauses['LIMIT'] = array('LIMIT', 3);
+
return $clauses;
}
+
return static::$CLAUSES;
}
}
diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php
index a9ff498..5329b07 100644
--- a/src/Statements/SetStatement.php
+++ b/src/Statements/SetStatement.php
@@ -2,10 +2,8 @@
/**
* `SET` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -16,13 +14,11 @@ use SqlParser\Components\OptionsArray;
* `SET` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class SetStatement extends Statement
{
-
/**
* The clauses of this statement, in order.
*
@@ -31,23 +27,23 @@ class SetStatement extends Statement
* @var array
*/
public static $CLAUSES = array(
- 'SET' => array('SET', 3),
+ 'SET' => array('SET', 3),
);
/**
- * Possible exceptions in SET statment
+ * Possible exceptions in SET statment.
*
* @var array
*/
public static $OPTIONS = array(
- 'CHARSET' => array(3, 'var'),
- 'CHARACTER SET' => array(3, 'var'),
- 'NAMES' => array(3, 'var'),
- 'PASSWORD' => array(3, 'expr'),
+ 'CHARSET' => array(3, 'var'),
+ 'CHARACTER SET' => array(3, 'var'),
+ 'NAMES' => array(3, 'var'),
+ 'PASSWORD' => array(3, 'expr'),
);
/**
- * Options used in current statement
+ * Options used in current statement.
*
* @var OptionsArray[]
*/
diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php
index ecca348..be233a7 100644
--- a/src/Statements/ShowStatement.php
+++ b/src/Statements/ShowStatement.php
@@ -2,69 +2,65 @@
/**
* `SHOW` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
/**
* `SHOW` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ShowStatement extends NotImplementedStatement
{
-
/**
* Options of this statement.
*
* @var array
*/
public static $OPTIONS = array(
- 'CREATE' => 1,
- 'AUTHORS' => 2,
- 'BINARY' => 2,
- 'BINLOG' => 2,
- 'CHARACTER' => 2,
- 'CODE' => 2,
- 'COLLATION' => 2,
- 'COLUMNS' => 2,
- 'CONTRIBUTORS' => 2,
- 'DATABASE' => 2,
- 'DATABASES' => 2,
- 'ENGINE' => 2,
- 'ENGINES' => 2,
- 'ERRORS' => 2,
- 'EVENT' => 2,
- 'EVENTS' => 2,
- 'FUNCTION' => 2,
- 'GRANTS' => 2,
- 'HOSTS' => 2,
- 'INDEX' => 2,
- 'INNODB' => 2,
- 'LOGS' => 2,
- 'MASTER' => 2,
- 'OPEN' => 2,
- 'PLUGINS' => 2,
- 'PRIVILEGES' => 2,
- 'PROCEDURE' => 2,
- 'PROCESSLIST' => 2,
- 'PROFILE' => 2,
- 'PROFILES' => 2,
- 'SCHEDULER' => 2,
- 'SET' => 2,
- 'SLAVE' => 2,
- 'STATUS' => 2,
- 'TABLE' => 2,
- 'TABLES' => 2,
- 'TRIGGER' => 2,
- 'TRIGGERS' => 2,
- 'VARIABLES' => 2,
- 'VIEW' => 2,
- 'WARNINGS' => 2,
+ 'CREATE' => 1,
+ 'AUTHORS' => 2,
+ 'BINARY' => 2,
+ 'BINLOG' => 2,
+ 'CHARACTER' => 2,
+ 'CODE' => 2,
+ 'COLLATION' => 2,
+ 'COLUMNS' => 2,
+ 'CONTRIBUTORS' => 2,
+ 'DATABASE' => 2,
+ 'DATABASES' => 2,
+ 'ENGINE' => 2,
+ 'ENGINES' => 2,
+ 'ERRORS' => 2,
+ 'EVENT' => 2,
+ 'EVENTS' => 2,
+ 'FUNCTION' => 2,
+ 'GRANTS' => 2,
+ 'HOSTS' => 2,
+ 'INDEX' => 2,
+ 'INNODB' => 2,
+ 'LOGS' => 2,
+ 'MASTER' => 2,
+ 'OPEN' => 2,
+ 'PLUGINS' => 2,
+ 'PRIVILEGES' => 2,
+ 'PROCEDURE' => 2,
+ 'PROCESSLIST' => 2,
+ 'PROFILE' => 2,
+ 'PROFILES' => 2,
+ 'SCHEDULER' => 2,
+ 'SET' => 2,
+ 'SLAVE' => 2,
+ 'STATUS' => 2,
+ 'TABLE' => 2,
+ 'TABLES' => 2,
+ 'TRIGGER' => 2,
+ 'TRIGGERS' => 2,
+ 'VARIABLES' => 2,
+ 'VIEW' => 2,
+ 'WARNINGS' => 2,
);
}
diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php
index 2d355ea..9e11daa 100644
--- a/src/Statements/TransactionStatement.php
+++ b/src/Statements/TransactionStatement.php
@@ -2,10 +2,8 @@
/**
* Transaction statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Parser;
@@ -17,26 +15,24 @@ use SqlParser\Components\OptionsArray;
* Transaction statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class TransactionStatement extends Statement
{
-
/**
- * START TRANSACTION and BEGIN
+ * START TRANSACTION and BEGIN.
*
* @var int
*/
- const TYPE_BEGIN = 1;
+ const TYPE_BEGIN = 1;
/**
- * COMMIT and ROLLBACK
+ * COMMIT and ROLLBACK.
*
* @var int
*/
- const TYPE_END = 2;
+ const TYPE_END = 2;
/**
* The type of this query.
@@ -65,23 +61,21 @@ class TransactionStatement extends Statement
* @var array
*/
public static $OPTIONS = array(
- 'START TRANSACTION' => 1,
- 'BEGIN' => 1,
- 'COMMIT' => 1,
- 'ROLLBACK' => 1,
- 'WITH CONSISTENT SNAPSHOT' => 2,
- 'WORK' => 2,
- 'AND NO CHAIN' => 3,
- 'AND CHAIN' => 3,
- 'RELEASE' => 4,
- 'NO RELEASE' => 4,
+ 'START TRANSACTION' => 1,
+ 'BEGIN' => 1,
+ 'COMMIT' => 1,
+ 'ROLLBACK' => 1,
+ 'WITH CONSISTENT SNAPSHOT' => 2,
+ 'WORK' => 2,
+ 'AND NO CHAIN' => 3,
+ 'AND CHAIN' => 3,
+ 'RELEASE' => 4,
+ 'NO RELEASE' => 4,
);
/**
- * @param Parser $parser The instance that requests parsing.
- * @param TokensList $list The list of tokens to be parsed.
- *
- * @return void
+ * @param Parser $parser the instance that requests parsing
+ * @param TokensList $list the list of tokens to be parsed
*/
public function parse(Parser $parser, TokensList $list)
{
@@ -91,11 +85,11 @@ class TransactionStatement extends Statement
if (($this->options->has('START TRANSACTION'))
|| ($this->options->has('BEGIN'))
) {
- $this->type = TransactionStatement::TYPE_BEGIN;
+ $this->type = self::TYPE_BEGIN;
} elseif (($this->options->has('COMMIT'))
|| ($this->options->has('ROLLBACK'))
) {
- $this->type = TransactionStatement::TYPE_END;
+ $this->type = self::TYPE_END;
}
}
@@ -105,15 +99,16 @@ class TransactionStatement extends Statement
public function build()
{
$ret = OptionsArray::build($this->options);
- if ($this->type === TransactionStatement::TYPE_BEGIN) {
+ if ($this->type === self::TYPE_BEGIN) {
foreach ($this->statements as $statement) {
- /**
+ /*
* @var SelectStatement $statement
*/
$ret .= ';' . $statement->build();
}
$ret .= ';' . $this->end->build();
}
+
return $ret;
}
}
diff --git a/src/Statements/TruncateStatement.php b/src/Statements/TruncateStatement.php
index 6f9d303..20ad4b8 100644
--- a/src/Statements/TruncateStatement.php
+++ b/src/Statements/TruncateStatement.php
@@ -2,10 +2,8 @@
/**
* `TRUNCATE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -15,20 +13,18 @@ use SqlParser\Components\Expression;
* `TRUNCATE` statement.
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class TruncateStatement extends Statement
{
-
/**
* Options for `TRUNCATE` statements.
*
* @var array
*/
public static $OPTIONS = array(
- 'TABLE' => 1,
+ 'TABLE' => 1,
);
/**
diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php
index 011b955..796a722 100644
--- a/src/Statements/UpdateStatement.php
+++ b/src/Statements/UpdateStatement.php
@@ -2,10 +2,8 @@
/**
* `UPDATE` statement.
- *
- * @package SqlParser
- * @subpackage Statements
*/
+
namespace SqlParser\Statements;
use SqlParser\Statement;
@@ -31,21 +29,19 @@ use SqlParser\Components\Condition;
* [WHERE where_condition]
*
* @category Statements
- * @package SqlParser
- * @subpackage Statements
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class UpdateStatement extends Statement
{
-
/**
* Options for `UPDATE` statements and their slot ID.
*
* @var array
*/
public static $OPTIONS = array(
- 'LOW_PRIORITY' => 1,
- 'IGNORE' => 2,
+ 'LOW_PRIORITY' => 1,
+ 'IGNORE' => 2,
);
/**
@@ -56,15 +52,15 @@ class UpdateStatement extends Statement
* @var array
*/
public static $CLAUSES = array(
- 'UPDATE' => array('UPDATE', 2),
+ 'UPDATE' => array('UPDATE', 2),
// Used for options.
- '_OPTIONS' => array('_OPTIONS', 1),
+ '_OPTIONS' => array('_OPTIONS', 1),
// Used for updated tables.
- '_UPDATE' => array('UPDATE', 1),
- 'SET' => array('SET', 3),
- 'WHERE' => array('WHERE', 3),
- 'ORDER BY' => array('ORDER BY', 3),
- 'LIMIT' => array('LIMIT', 3),
+ '_UPDATE' => array('UPDATE', 1),
+ 'SET' => array('SET', 3),
+ 'WHERE' => array('WHERE', 3),
+ 'ORDER BY' => array('ORDER BY', 3),
+ 'LIMIT' => array('LIMIT', 3),
);
/**
diff --git a/src/Token.php b/src/Token.php
index e5001ef..d847224 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -4,9 +4,8 @@
* Defines a token along with a set of types and flags and utility functions.
*
* An array of tokens will result after parsing the query.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
/**
@@ -14,12 +13,11 @@ namespace SqlParser;
* categorization for the purpose of parsing.
*
* @category Tokens
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Token
{
-
// Types of tokens (a vague description of a token's purpose).
/**
@@ -29,14 +27,14 @@ class Token
*
* @var int
*/
- const TYPE_NONE = 0;
+ const TYPE_NONE = 0;
/**
* SQL specific keywords: SELECT, UPDATE, INSERT, etc.
*
* @var int
*/
- const TYPE_KEYWORD = 1;
+ const TYPE_KEYWORD = 1;
/**
* Any type of legal operator.
@@ -50,14 +48,14 @@ class Token
*
* @var int
*/
- const TYPE_OPERATOR = 2;
+ const TYPE_OPERATOR = 2;
/**
* Spaces, tabs, new lines, etc.
*
* @var int
*/
- const TYPE_WHITESPACE = 3;
+ const TYPE_WHITESPACE = 3;
/**
* Any type of legal comment.
@@ -79,21 +77,21 @@ class Token
*
* @var int
*/
- const TYPE_COMMENT = 4;
+ const TYPE_COMMENT = 4;
/**
* Boolean values: true or false.
*
* @var int
*/
- const TYPE_BOOL = 5;
+ const TYPE_BOOL = 5;
/**
* Numbers: 4, 0x8, 15.16, 23e42, etc.
*
* @var int
*/
- const TYPE_NUMBER = 6;
+ const TYPE_NUMBER = 6;
/**
* Literal strings: 'string', "test".
@@ -101,15 +99,15 @@ class Token
*
* @var int
*/
- const TYPE_STRING = 7;
+ const TYPE_STRING = 7;
/**
* Database, table names, variables, etc.
- * For example: ```SELECT `foo`, `bar` FROM `database`.`table`;```
+ * For example: ```SELECT `foo`, `bar` FROM `database`.`table`;```.
*
* @var int
*/
- const TYPE_SYMBOL = 8;
+ const TYPE_SYMBOL = 8;
/**
* Delimits an unknown string.
@@ -117,7 +115,7 @@ class Token
*
* @var int
*/
- const TYPE_DELIMITER = 9;
+ const TYPE_DELIMITER = 9;
/**
* Labels in LOOP statement, ITERATE statement etc.
@@ -125,50 +123,50 @@ class Token
* begin_label: BEGIN [statement_list] END [end_label]
* begin_label: LOOP [statement_list] END LOOP [end_label]
* begin_label: REPEAT [statement_list] ... END REPEAT [end_label]
- * begin_label: WHILE ... DO [statement_list] END WHILE [end_label]
+ * begin_label: WHILE ... DO [statement_list] END WHILE [end_label].
*
* @var int
*/
- const TYPE_LABEL = 10;
+ const TYPE_LABEL = 10;
// Flags that describe the tokens in more detail.
// All keywords must have flag 1 so `Context::isKeyword` method doesn't
// require strict comparison.
- const FLAG_KEYWORD_RESERVED = 2;
- const FLAG_KEYWORD_COMPOSED = 4;
- const FLAG_KEYWORD_DATA_TYPE = 8;
- const FLAG_KEYWORD_KEY = 16;
- const FLAG_KEYWORD_FUNCTION = 32;
+ const FLAG_KEYWORD_RESERVED = 2;
+ const FLAG_KEYWORD_COMPOSED = 4;
+ const FLAG_KEYWORD_DATA_TYPE = 8;
+ const FLAG_KEYWORD_KEY = 16;
+ const FLAG_KEYWORD_FUNCTION = 32;
// Numbers related flags.
- const FLAG_NUMBER_HEX = 1;
- const FLAG_NUMBER_FLOAT = 2;
- const FLAG_NUMBER_APPROXIMATE = 4;
- const FLAG_NUMBER_NEGATIVE = 8;
- const FLAG_NUMBER_BINARY = 16;
+ const FLAG_NUMBER_HEX = 1;
+ const FLAG_NUMBER_FLOAT = 2;
+ const FLAG_NUMBER_APPROXIMATE = 4;
+ const FLAG_NUMBER_NEGATIVE = 8;
+ const FLAG_NUMBER_BINARY = 16;
// Strings related flags.
- const FLAG_STRING_SINGLE_QUOTES = 1;
- const FLAG_STRING_DOUBLE_QUOTES = 2;
+ const FLAG_STRING_SINGLE_QUOTES = 1;
+ const FLAG_STRING_DOUBLE_QUOTES = 2;
// Comments related flags.
- const FLAG_COMMENT_BASH = 1;
- const FLAG_COMMENT_C = 2;
- const FLAG_COMMENT_SQL = 4;
- const FLAG_COMMENT_MYSQL_CMD = 8;
+ const FLAG_COMMENT_BASH = 1;
+ const FLAG_COMMENT_C = 2;
+ const FLAG_COMMENT_SQL = 4;
+ const FLAG_COMMENT_MYSQL_CMD = 8;
// Operators related flags.
- const FLAG_OPERATOR_ARITHMETIC = 1;
- const FLAG_OPERATOR_LOGICAL = 2;
- const FLAG_OPERATOR_BITWISE = 4;
- const FLAG_OPERATOR_ASSIGNMENT = 8;
- const FLAG_OPERATOR_SQL = 16;
+ const FLAG_OPERATOR_ARITHMETIC = 1;
+ const FLAG_OPERATOR_LOGICAL = 2;
+ const FLAG_OPERATOR_BITWISE = 4;
+ const FLAG_OPERATOR_ASSIGNMENT = 8;
+ const FLAG_OPERATOR_SQL = 16;
// Symbols related flags.
- const FLAG_SYMBOL_VARIABLE = 1;
- const FLAG_SYMBOL_BACKTICK = 2;
- const FLAG_SYMBOL_USER = 4;
- const FLAG_SYMBOL_SYSTEM = 8;
+ const FLAG_SYMBOL_VARIABLE = 1;
+ const FLAG_SYMBOL_BACKTICK = 2;
+ const FLAG_SYMBOL_USER = 4;
+ const FLAG_SYMBOL_SYSTEM = 8;
/**
* The token it its raw string representation.
@@ -178,7 +176,7 @@ class Token
public $token;
/**
- * The value this token contains (i.e. token after some evaluation)
+ * The value this token contains (i.e. token after some evaluation).
*
* @var mixed
*/
@@ -208,9 +206,9 @@ class Token
/**
* Constructor.
*
- * @param string $token The value of the token.
- * @param int $type The type of the token.
- * @param int $flags The flags of the token.
+ * @param string $token the value of the token
+ * @param int $type the type of the token
+ * @param int $flags the flags of the token
*/
public function __construct($token, $type = 0, $flags = 0)
{
@@ -230,40 +228,43 @@ class Token
public function extract()
{
switch ($this->type) {
- case Token::TYPE_KEYWORD:
- if (!($this->flags & Token::FLAG_KEYWORD_RESERVED)) {
+ case self::TYPE_KEYWORD:
+ if (!($this->flags & self::FLAG_KEYWORD_RESERVED)) {
// Unreserved keywords should stay the way they are because they
// might represent field names.
return $this->token;
}
+
return strtoupper($this->token);
- case Token::TYPE_WHITESPACE:
+ case self::TYPE_WHITESPACE:
return ' ';
- case Token::TYPE_BOOL:
+ case self::TYPE_BOOL:
return strtoupper($this->token) === 'TRUE';
- case Token::TYPE_NUMBER:
+ case self::TYPE_NUMBER:
$ret = str_replace('--', '', $this->token); // e.g. ---42 === -42
- if ($this->flags & Token::FLAG_NUMBER_HEX) {
- if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) {
+ if ($this->flags & self::FLAG_NUMBER_HEX) {
+ if ($this->flags & self::FLAG_NUMBER_NEGATIVE) {
$ret = str_replace('-', '', $this->token);
sscanf($ret, '%x', $ret);
$ret = -$ret;
} else {
sscanf($ret, '%x', $ret);
}
- } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE)
- || ($this->flags & Token::FLAG_NUMBER_FLOAT)
+ } elseif (($this->flags & self::FLAG_NUMBER_APPROXIMATE)
+ || ($this->flags & self::FLAG_NUMBER_FLOAT)
) {
sscanf($ret, '%f', $ret);
} else {
sscanf($ret, '%d', $ret);
}
+
return $ret;
- case Token::TYPE_STRING:
+ case self::TYPE_STRING:
$quote = $this->token[0];
$str = str_replace($quote . $quote, $quote, $this->token);
+
return mb_substr($str, 1, -1, 'UTF-8'); // trims quotes
- case Token::TYPE_SYMBOL:
+ case self::TYPE_SYMBOL:
$str = $this->token;
if ((isset($str[0])) && ($str[0] === '@')) {
// `mb_strlen($str)` must be used instead of `null` because
@@ -282,8 +283,10 @@ class Token
$str = str_replace($quote . $quote, $quote, $str);
$str = mb_substr($str, 1, -1, 'UTF-8');
}
+
return $str;
}
+
return $this->token;
}
diff --git a/src/TokensList.php b/src/TokensList.php
index c0c2c89..512fcb5 100644
--- a/src/TokensList.php
+++ b/src/TokensList.php
@@ -2,21 +2,19 @@
/**
* Defines an array of tokens and utility functions to iterate through it.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
/**
* A structure representing a list of tokens.
*
* @category Tokens
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class TokensList implements \ArrayAccess
{
-
/**
* The array of tokens.
*
@@ -41,8 +39,8 @@ class TokensList implements \ArrayAccess
/**
* Constructor.
*
- * @param array $tokens The initial array of tokens.
- * @param int $count The count of tokens in the initial array.
+ * @param array $tokens the initial array of tokens
+ * @param int $count the count of tokens in the initial array
*/
public function __construct(array $tokens = array(), $count = -1)
{
@@ -57,7 +55,7 @@ class TokensList implements \ArrayAccess
/**
* Builds an array of tokens by merging their raw value.
*
- * @param string|Token[]|TokensList $list The tokens to be built.
+ * @param string|Token[]|TokensList $list the tokens to be built
*
* @return string
*/
@@ -67,7 +65,7 @@ class TokensList implements \ArrayAccess
return $list;
}
- if ($list instanceof TokensList) {
+ if ($list instanceof self) {
$list = $list->tokens;
}
@@ -77,15 +75,14 @@ class TokensList implements \ArrayAccess
$ret .= $tok->token;
}
}
+
return $ret;
}
/**
* Adds a new token.
*
- * @param Token $token Token to be added in list.
- *
- * @return void
+ * @param Token $token token to be added in list
*/
public function add(Token $token)
{
@@ -107,13 +104,14 @@ class TokensList implements \ArrayAccess
return $this->tokens[$this->idx++];
}
}
+
return null;
}
/**
* Gets the next token.
*
- * @param int $type The type.
+ * @param int $type the type
*
* @return Token
*/
@@ -124,14 +122,15 @@ class TokensList implements \ArrayAccess
return $this->tokens[$this->idx++];
}
}
+
return null;
}
/**
* Gets the next token.
*
- * @param int $type The type of the token.
- * @param string $value The value of the token.
+ * @param int $type the type of the token
+ * @param string $value the value of the token
*
* @return Token
*/
@@ -144,16 +143,15 @@ class TokensList implements \ArrayAccess
return $this->tokens[$this->idx++];
}
}
+
return null;
}
/**
* Sets an value inside the container.
*
- * @param int $offset The offset to be set.
- * @param Token $value The token to be saved.
- *
- * @return void
+ * @param int $offset the offset to be set
+ * @param Token $value the token to be saved
*/
public function offsetSet($offset, $value)
{
@@ -167,7 +165,7 @@ class TokensList implements \ArrayAccess
/**
* Gets a value from the container.
*
- * @param int $offset The offset to be returned.
+ * @param int $offset the offset to be returned
*
* @return Token
*/
@@ -179,7 +177,7 @@ class TokensList implements \ArrayAccess
/**
* Checks if an offset was previously set.
*
- * @param int $offset The offset to be checked.
+ * @param int $offset the offset to be checked
*
* @return bool
*/
@@ -191,9 +189,7 @@ class TokensList implements \ArrayAccess
/**
* Unsets the value of an offset.
*
- * @param int $offset The offset to be unset.
- *
- * @return void
+ * @param int $offset the offset to be unset
*/
public function offsetUnset($offset)
{
diff --git a/src/UtfString.php b/src/UtfString.php
index 66ec4e4..91aa19e 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -9,9 +9,8 @@
*
* Because the lexer relies on the subscript operator this class had to be
* implemented.
- *
- * @package SqlParser
*/
+
namespace SqlParser;
/**
@@ -20,12 +19,11 @@ namespace SqlParser;
* In this library, this class should be used to parse UTF-8 queries.
*
* @category Misc
- * @package SqlParser
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class UtfString implements \ArrayAccess
{
-
/**
* The raw, multi-byte string.
*
@@ -69,7 +67,7 @@ class UtfString implements \ArrayAccess
/**
* Constructor.
*
- * @param string $str The string.
+ * @param string $str the string
*/
public function __construct($str)
{
@@ -83,7 +81,7 @@ class UtfString implements \ArrayAccess
/**
* Checks if the given offset exists.
*
- * @param int $offset The offset to be checked.
+ * @param int $offset the offset to be checked
*
* @return bool
*/
@@ -95,7 +93,7 @@ class UtfString implements \ArrayAccess
/**
* Gets the character at given offset.
*
- * @param int $offset The offset to be returned.
+ * @param int $offset the offset to be returned
*
* @return string
*/
@@ -136,12 +134,10 @@ class UtfString implements \ArrayAccess
/**
* Sets the value of a character.
*
- * @param int $offset The offset to be set.
- * @param string $value The value to be set.
+ * @param int $offset the offset to be set
+ * @param string $value the value to be set
*
- * @throws \Exception Not implemented.
- *
- * @return void
+ * @throws \Exception not implemented
*/
public function offsetSet($offset, $value)
{
@@ -151,11 +147,9 @@ class UtfString implements \ArrayAccess
/**
* Unsets an index.
*
- * @param int $offset The value to be unset.
- *
- * @throws \Exception Not implemented.
+ * @param int $offset the value to be unset
*
- * @return void
+ * @throws \Exception not implemented
*/
public function offsetUnset($offset)
{
@@ -169,7 +163,7 @@ class UtfString implements \ArrayAccess
* However, this implementation supports UTF-8 characters containing up to 6
* bytes.
*
- * @param string $byte The byte to be analyzed.
+ * @param string $byte the byte to be analyzed
*
* @see https://tools.ietf.org/html/rfc3629
*
@@ -189,6 +183,7 @@ class UtfString implements \ArrayAccess
} elseif ($byte < 252) {
return 5; // unofficial
}
+
return 6; // unofficial
}
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.
diff --git a/src/common.php b/src/common.php
index 3575c24..cb63695 100644
--- a/src/common.php
+++ b/src/common.php
@@ -2,15 +2,12 @@
/**
* Defines common elements used by the library.
- *
- * @package SqlParser
*/
-
if (!function_exists('__')) {
/**
* Translates the given string.
*
- * @param string $str String to be translated.
+ * @param string $str string to be translated
*
* @return string
*/
diff --git a/tests/Builder/AlterStatementTest.php b/tests/Builder/AlterStatementTest.php
index d080b94..6cd6631 100644
--- a/tests/Builder/AlterStatementTest.php
+++ b/tests/Builder/AlterStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class AlterStatementTest extends TestCase
{
-
public function testBuilder()
{
$query = 'ALTER TABLE `actor` ' .
diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php
index ae906b3..2e7b611 100644
--- a/tests/Builder/CreateStatementTest.php
+++ b/tests/Builder/CreateStatementTest.php
@@ -9,12 +9,10 @@ use SqlParser\Components\CreateDefinition;
use SqlParser\Components\Key;
use SqlParser\Components\OptionsArray;
use SqlParser\Statements\CreateStatement;
-
use SqlParser\Tests\TestCase;
class CreateStatementTest extends TestCase
{
-
public function testBuilder()
{
$parser = new Parser(
@@ -45,16 +43,16 @@ class CreateStatementTest extends TestCase
public function testBuilderDefaultInt()
{
$parser = new Parser(
- "CREATE TABLE IF NOT EXISTS t1 (" .
+ 'CREATE TABLE IF NOT EXISTS t1 (' .
" c1 int(11) NOT NULL DEFAULT '0' COMMENT 'xxx'" .
- ") ENGINE=MyISAM"
+ ') ENGINE=MyISAM'
);
$stmt = $parser->statements[0];
$this->assertEquals(
"CREATE TABLE IF NOT EXISTS t1 (\n" .
" `c1` int(11) NOT NULL DEFAULT '0' COMMENT 'xxx'\n" .
- ") ENGINE=MyISAM",
+ ') ENGINE=MyISAM',
$stmt->build()
);
}
@@ -62,18 +60,18 @@ class CreateStatementTest extends TestCase
public function testBuilderDefaultComment()
{
$parser = new Parser(
- "CREATE TABLE `wp_audio` (" .
+ 'CREATE TABLE `wp_audio` (' .
" `somedata` int(11) DEFAULT NULL COMMENT 'ma data', " .
- " `someinfo` int(11) DEFAULT NULL COMMENT 'ma info' ".
- " )"
+ " `someinfo` int(11) DEFAULT NULL COMMENT 'ma info' " .
+ ' )'
);
$stmt = $parser->statements[0];
$this->assertEquals(
"CREATE TABLE `wp_audio` (\n" .
" `somedata` int(11) DEFAULT NULL COMMENT 'ma data',\n" .
- " `someinfo` int(11) DEFAULT NULL COMMENT 'ma info'\n".
- ") ",
+ " `someinfo` int(11) DEFAULT NULL COMMENT 'ma info'\n" .
+ ') ',
$stmt->build()
);
}
@@ -95,14 +93,14 @@ class CreateStatementTest extends TestCase
'',
null,
new Key('', array(array('name' => 'id')), 'PRIMARY KEY')
- )
+ ),
);
$this->assertEquals(
"CREATE TABLE `test` (\n" .
" `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n" .
" PRIMARY KEY (`id`)\n" .
- ") ",
+ ') ',
$stmt->build()
);
@@ -118,26 +116,24 @@ class CreateStatementTest extends TestCase
" PRIMARY KEY (`id`),\n" .
" UNIQUE KEY `jos_section_value_value_aro` (`section_value`(100),`value`(15)) USING BTREE,\n" .
" KEY `jos_gacl_hidden_aro` (`hidden`)\n" .
- ") ENGINE=InnoDB DEFAULT CHARSET=latin1";
+ ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
$parser = new Parser($query);
$this->assertEquals($query, $parser->statements[0]->build());
/* Assertion 3 */
- $query = "CREATE TABLE `table_copy` LIKE `old_table`";
+ $query = 'CREATE TABLE `table_copy` LIKE `old_table`';
$parser = new Parser($query);
$this->assertEquals($query, $parser->statements[0]->build());
-
/* Assertion 4 */
$query =
"CREATE TABLE `aa` (\n" .
" `id` int(11) NOT NULL,\n" .
" `rTime` timestamp(3) NOT NULL DEFAULT '0000-00-00 00:00:00.000' ON UPDATE CURRENT_TIMESTAMP(3),\n" .
" PRIMARY KEY (`id`)\n" .
- ") ENGINE=InnoDB DEFAULT CHARSET=latin1";
+ ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
$parser = new Parser($query);
$this->assertEquals($query, $parser->statements[0]->build());
-
}
public function testBuilderPartitions()
@@ -171,7 +167,7 @@ class CreateStatementTest extends TestCase
/* Assertion 2 */
$query = 'CREATE TABLE `pma_test` (' . "\n"
. ' `test_id` int(32) NOT NULL,' . "\n"
- . ' `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'. "\n"
+ . ' `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP' . "\n"
. ') ENGINE=InnoDB DEFAULT CHARSET=utf8' . "\n"
. 'PARTITION BY RANGE (test_id)' . "\n"
. '(' . "\n"
diff --git a/tests/Builder/DeleteStatementTest.php b/tests/Builder/DeleteStatementTest.php
index a7500f0..ba8ea3a 100644
--- a/tests/Builder/DeleteStatementTest.php
+++ b/tests/Builder/DeleteStatementTest.php
@@ -3,15 +3,13 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class DeleteStatementTest extends TestCase
{
-
public function testBuilderSingleTable()
{
- /* Assertion 1 */
+ /* Assertion 1 */
$query = 'DELETE IGNORE FROM t1';
$parser = new Parser($query);
@@ -53,7 +51,7 @@ class DeleteStatementTest extends TestCase
/* Assertion 6 */
$query = 'DELETE LOW_PRIORITY FROM `test`.users '
- . 'WHERE `id`<3 AND (username="Dan" OR username="Paul") ORDER BY id ASC';
+ . 'WHERE `id`<3 AND (username="Dan" OR username="Paul") ORDER BY id ASC';
$parser = new Parser($query);
$stmt = $parser->statements[0];
@@ -63,7 +61,7 @@ class DeleteStatementTest extends TestCase
public function testBuilderMultiTable()
{
- /* Assertion 1 */
+ /* Assertion 1 */
$query = 'DELETE QUICK table1, table2.* FROM table1 AS `t1`, table2 AS `t2`';
$parser = new Parser($query);
diff --git a/tests/Builder/ExplainStatement.php b/tests/Builder/ExplainStatement.php
index 1a44f44..2ff6284 100644
--- a/tests/Builder/ExplainStatement.php
+++ b/tests/Builder/ExplainStatement.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class ExplainStatementTest extends TestCase
{
-
public function testBuilderView()
{
$query = 'EXPLAIN SELECT * FROM test;';
diff --git a/tests/Builder/InsertStatementTest.php b/tests/Builder/InsertStatementTest.php
index d27726a..a212057 100644
--- a/tests/Builder/InsertStatementTest.php
+++ b/tests/Builder/InsertStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class InsertStatementTest extends TestCase
{
-
public function testBuilder()
{
/* Assertion 1 */
diff --git a/tests/Builder/ReplaceStatementTest.php b/tests/Builder/ReplaceStatementTest.php
index f25a58a..7a73992 100644
--- a/tests/Builder/ReplaceStatementTest.php
+++ b/tests/Builder/ReplaceStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class ReplaceStatementTest extends TestCase
{
-
public function testBuilder()
{
$parser = new Parser(
diff --git a/tests/Builder/SelectStatementTest.php b/tests/Builder/SelectStatementTest.php
index 173ff92..8151548 100644
--- a/tests/Builder/SelectStatementTest.php
+++ b/tests/Builder/SelectStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class SelectStatementTest extends TestCase
{
-
public function testBuilder()
{
$query = 'SELECT * FROM t1 LEFT JOIN (t2, t3, t4) '
@@ -77,7 +75,6 @@ class SelectStatementTest extends TestCase
);
}
-
public function testBuilderIntoOptions()
{
/* Assertion 1 */
diff --git a/tests/Builder/SetStatementTest.php b/tests/Builder/SetStatementTest.php
index 2f75c0f..5d2658c 100644
--- a/tests/Builder/SetStatementTest.php
+++ b/tests/Builder/SetStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class SetStatementTest extends TestCase
{
-
public function testBuilderView()
{
/* Assertion 1 */
diff --git a/tests/Builder/StatementTest.php b/tests/Builder/StatementTest.php
index 0dff320..1f63029 100644
--- a/tests/Builder/StatementTest.php
+++ b/tests/Builder/StatementTest.php
@@ -7,12 +7,10 @@ use SqlParser\Components\Expression;
use SqlParser\Components\Condition;
use SqlParser\Components\Limit;
use SqlParser\Statements\SelectStatement;
-
use SqlParser\Tests\TestCase;
class StatementTest extends TestCase
{
-
public function testBuilder()
{
$stmt = new SelectStatement();
diff --git a/tests/Builder/TransactionStatementTest.php b/tests/Builder/TransactionStatementTest.php
index 5b093b2..120ef13 100644
--- a/tests/Builder/TransactionStatementTest.php
+++ b/tests/Builder/TransactionStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
-
use SqlParser\Tests\TestCase;
class TransactionStatementTest extends TestCase
{
-
public function testBuilder()
{
$query = 'START TRANSACTION;' .
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php
index ee9d679..4f3483d 100644
--- a/tests/Components/Array2dTest.php
+++ b/tests/Components/Array2dTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Array2d;
-
use SqlParser\Tests\TestCase;
class Array2dTest extends TestCase
{
-
public function testParse()
{
$parser = new Parser();
@@ -79,7 +77,7 @@ class Array2dTest extends TestCase
count($parser->errors)
);
$this->assertEquals(
- "An opening bracket followed by a set of values was expected.",
+ 'An opening bracket followed by a set of values was expected.',
$parser->errors[0]->getMessage()
);
}
@@ -93,7 +91,7 @@ class Array2dTest extends TestCase
count($parser->errors)
);
$this->assertEquals(
- "2 values were expected, but found 1.",
+ '2 values were expected, but found 1.',
$parser->errors[0]->getMessage()
);
}
diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php
index d62c9d3..d40509f 100644
--- a/tests/Components/ArrayObjTest.php
+++ b/tests/Components/ArrayObjTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\ArrayObj;
-
use SqlParser\Tests\TestCase;
class ArrayObjTest extends TestCase
{
-
public function testBuildRaw()
{
$component = new ArrayObj(array('a', 'b'), array());
diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php
index 8746909..082c3aa 100644
--- a/tests/Components/CaseExpressionTest.php
+++ b/tests/Components/CaseExpressionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\CaseExpression;
-
use SqlParser\Tests\TestCase;
class CaseExpressionTest extends TestCase
{
-
public function testParseBuild()
{
$caseExprQuery = 'case 1 when 1 then "Some" else "Other" end';
diff --git a/tests/Components/ComponentTest.php b/tests/Components/ComponentTest.php
index b2388a3..4541602 100644
--- a/tests/Components/ComponentTest.php
+++ b/tests/Components/ComponentTest.php
@@ -5,12 +5,10 @@ namespace SqlParser\Tests\Parser;
use SqlParser\Component;
use SqlParser\Parser;
use SqlParser\TokensList;
-
use SqlParser\Tests\TestCase;
class ComponentTest extends TestCase
{
-
/**
* @expectedException \Exception
* @expectedExceptionMessage Not implemented yet.
diff --git a/tests/Components/ConditionTest.php b/tests/Components/ConditionTest.php
index b3279fe..f06e51d 100644
--- a/tests/Components/ConditionTest.php
+++ b/tests/Components/ConditionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Condition;
-
use SqlParser\Tests\TestCase;
class ConditionTest extends TestCase
{
-
public function testParse()
{
$component = Condition::parse(new Parser(), $this->getTokensList('/* id = */ id = 10'));
diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php
index a7b7f86..8f373d6 100644
--- a/tests/Components/CreateDefinitionTest.php
+++ b/tests/Components/CreateDefinitionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\CreateDefinition;
-
use SqlParser\Tests\TestCase;
class CreateDefinitionTest extends TestCase
{
-
public function testParse()
{
$component = CreateDefinition::parse(
diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php
index 3d8cd77..de80da3 100644
--- a/tests/Components/ExpressionArrayTest.php
+++ b/tests/Components/ExpressionArrayTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\ExpressionArray;
-
use SqlParser\Tests\TestCase;
class ExpressionArrayTest extends TestCase
{
-
public function testParse()
{
$component = ExpressionArray::parse(
diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php
index 9bacf9b..11d10e4 100644
--- a/tests/Components/ExpressionTest.php
+++ b/tests/Components/ExpressionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Expression;
-
use SqlParser\Tests\TestCase;
class ExpressionTest extends TestCase
{
-
public function testParse()
{
$component = Expression::parse(new Parser(), $this->getTokensList('IF(film_id > 0, film_id, film_id)'));
@@ -64,7 +62,7 @@ class ExpressionTest extends TestCase
{
$component = array(
new Expression('1 + 2', 'three'),
- new Expression('1 + 3', 'four')
+ new Expression('1 + 3', 'four'),
);
$this->assertEquals(
Expression::build($component),
diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php
index b7f71ca..fed3aa8 100644
--- a/tests/Components/FunctionCallTest.php
+++ b/tests/Components/FunctionCallTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Components\ArrayObj;
use SqlParser\Components\FunctionCall;
-
use SqlParser\Tests\TestCase;
class FunctionCallTest extends TestCase
{
-
public function testBuildArray()
{
$component = new FunctionCall('func', array('a', 'b'));
diff --git a/tests/Components/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php
index 388368c..c6d2b53 100644
--- a/tests/Components/IntoKeywordTest.php
+++ b/tests/Components/IntoKeywordTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\IntoKeyword;
-
use SqlParser\Tests\TestCase;
class IntoKeywordTest extends TestCase
{
-
public function testParse()
{
$component = IntoKeyword::parse(new Parser(), $this->getTokensList('OUTFILE "/tmp/outfile.txt"'));
diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php
index e14c62c..95d7354 100644
--- a/tests/Components/JoinKeywordTest.php
+++ b/tests/Components/JoinKeywordTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\JoinKeyword;
-
use SqlParser\Tests\TestCase;
class JoinKeywordTest extends TestCase
{
-
public function testParseIncomplete()
{
$component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN a'));
@@ -33,12 +31,12 @@ class JoinKeywordTest extends TestCase
$component = JoinKeyword::parse(
new Parser(),
$this->getTokensList(
- 'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) '.
+ 'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)'
)
);
$this->assertEquals(
- 'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) '.
+ 'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)',
JoinKeyword::build($component)
);
diff --git a/tests/Components/KeyTest.php b/tests/Components/KeyTest.php
index e8a462e..f6fa7b8 100644
--- a/tests/Components/KeyTest.php
+++ b/tests/Components/KeyTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Key;
-
use SqlParser\Tests\TestCase;
class KeyTest extends TestCase
{
-
public function testParse()
{
$component = Key::parse(
diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php
index 15c665a..aacfce7 100644
--- a/tests/Components/LimitTest.php
+++ b/tests/Components/LimitTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Limit;
-
use SqlParser\Tests\TestCase;
class LimitTest extends TestCase
{
-
public function testBuildWithoutOffset()
{
$component = new Limit(1);
diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php
index ea521b3..5008e80 100644
--- a/tests/Components/OptionsArrayTest.php
+++ b/tests/Components/OptionsArrayTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\OptionsArray;
-
use SqlParser\Tests\TestCase;
class OptionsArrayTest extends TestCase
{
-
public function testParse()
{
$component = OptionsArray::parse(
diff --git a/tests/Components/OrderKeywordTest.php b/tests/Components/OrderKeywordTest.php
index df8c95c..a89a365 100644
--- a/tests/Components/OrderKeywordTest.php
+++ b/tests/Components/OrderKeywordTest.php
@@ -2,22 +2,19 @@
namespace SqlParser\Tests\Components;
-use SqlParser\Parser;
use SqlParser\Components\Expression;
use SqlParser\Components\OrderKeyword;
-
use SqlParser\Tests\TestCase;
class OrderKeywordTest extends TestCase
{
-
public function testBuild()
{
$this->assertEquals(
OrderKeyword::build(
array(
new OrderKeyword(new Expression('a'), 'ASC'),
- new OrderKeyword(new Expression('b'), 'DESC')
+ new OrderKeyword(new Expression('b'), 'DESC'),
)
),
'a ASC, b DESC'
diff --git a/tests/Components/ParameterDefinitionTest.php b/tests/Components/ParameterDefinitionTest.php
index d4fe505..1de0de7 100644
--- a/tests/Components/ParameterDefinitionTest.php
+++ b/tests/Components/ParameterDefinitionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\ParameterDefinition;
-
use SqlParser\Tests\TestCase;
class ParameterDefinitionTest extends TestCase
{
-
public function testParse()
{
$component = ParameterDefinition::parse(
diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php
index 9a1819c..4e48183 100644
--- a/tests/Components/PartitionDefinitionTest.php
+++ b/tests/Components/PartitionDefinitionTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\PartitionDefinition;
-
use SqlParser\Tests\TestCase;
class PartitionDefinitionTest extends TestCase
{
-
public function testParse()
{
$component = PartitionDefinition::parse(
diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php
index d017572..2871385 100644
--- a/tests/Components/ReferenceTest.php
+++ b/tests/Components/ReferenceTest.php
@@ -5,12 +5,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\Expression;
use SqlParser\Components\Reference;
-
use SqlParser\Tests\TestCase;
class ReferenceTest extends TestCase
{
-
public function testParse()
{
$component = Reference::parse(new Parser(), $this->getTokensList('tbl (id)'));
diff --git a/tests/Components/RenameOperationTest.php b/tests/Components/RenameOperationTest.php
index b6a215c..37d2622 100644
--- a/tests/Components/RenameOperationTest.php
+++ b/tests/Components/RenameOperationTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Components;
use SqlParser\Parser;
use SqlParser\Components\RenameOperation;
-
use SqlParser\Tests\TestCase;
class RenameOperationTest extends TestCase
{
-
public function testBuild()
{
$component = RenameOperation::parse(new Parser(), $this->getTokensList('a TO b, c TO d'));
diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php
index 6f4e661..bfa1748 100644
--- a/tests/Lexer/ContextTest.php
+++ b/tests/Lexer/ContextTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Lexer;
use SqlParser\Context;
-
use SqlParser\Tests\TestCase;
class ContextTest extends TestCase
{
-
public function testLoad()
{
// Default context is 5.7.0.
@@ -34,7 +32,7 @@ class ContextTest extends TestCase
}
/**
- * @expectedException Exception
+ * @expectedException \Exception
* @expectedExceptionMessage Specified context ("\SqlParser\Contexts\ContextFoo") does not exist.
*/
public function testLoadError()
diff --git a/tests/Lexer/IsMethodsTest.php b/tests/Lexer/IsMethodsTest.php
index ac6d3ca..44b5a8a 100644
--- a/tests/Lexer/IsMethodsTest.php
+++ b/tests/Lexer/IsMethodsTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Lexer;
use SqlParser\Context;
use SqlParser\Token;
-
use SqlParser\Tests\TestCase;
class IsMethodsTest extends TestCase
{
-
public function testIsKeyword()
{
$this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('SELECT'));
@@ -47,12 +45,12 @@ class IsMethodsTest extends TestCase
public function testIsWhitespace()
{
- $this->assertTrue(Context::isWhitespace(" "));
+ $this->assertTrue(Context::isWhitespace(' '));
$this->assertTrue(Context::isWhitespace("\r"));
$this->assertTrue(Context::isWhitespace("\n"));
$this->assertTrue(Context::isWhitespace("\t"));
- $this->assertFalse(Context::isWhitespace("a"));
+ $this->assertFalse(Context::isWhitespace('a'));
$this->assertFalse(Context::isWhitespace("\b"));
$this->assertFalse(Context::isWhitespace("\u1000"));
}
diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php
index 0bcd3f7..8893d7b 100644
--- a/tests/Lexer/LexerTest.php
+++ b/tests/Lexer/LexerTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Lexer;
use SqlParser\Exceptions\LexerException;
use SqlParser\Lexer;
-
use SqlParser\Tests\TestCase;
class LexerTest extends TestCase
{
-
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -36,7 +34,7 @@ class LexerTest extends TestCase
}
/**
- * @expectedException SqlParser\Exceptions\LexerException
+ * @expectedException \SqlParser\Exceptions\LexerException
* @expectedExceptionMessage strict error
* @expectedExceptionCode 4
*/
diff --git a/tests/Lexer/TokenTest.php b/tests/Lexer/TokenTest.php
index 24e2a4d..bc4f4f0 100644
--- a/tests/Lexer/TokenTest.php
+++ b/tests/Lexer/TokenTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Lexer;
use SqlParser\Token;
-
use SqlParser\Tests\TestCase;
class TokenTest extends TestCase
{
-
public function testExtractKeyword()
{
$tok = new Token('SelecT', Token::TYPE_KEYWORD, Token::FLAG_KEYWORD_RESERVED);
diff --git a/tests/Lexer/TokensListTest.php b/tests/Lexer/TokensListTest.php
index e3cecff..863a65d 100644
--- a/tests/Lexer/TokensListTest.php
+++ b/tests/Lexer/TokensListTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Lexer;
use SqlParser\Token;
use SqlParser\TokensList;
-
use SqlParser\Tests\TestCase;
class TokensListTest extends TestCase
{
-
/**
* ArrayObj of tokens that are used for testing.
*
diff --git a/tests/Misc/BugsTest.php b/tests/Misc/BugsTest.php
index 2680890..b462dba 100644
--- a/tests/Misc/BugsTest.php
+++ b/tests/Misc/BugsTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class BugsTest extends TestCase
{
-
/**
* @dataProvider testBugProvider
*/
diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php
index 174b988..4c66654 100644
--- a/tests/Misc/UtfStringTest.php
+++ b/tests/Misc/UtfStringTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Misc;
use SqlParser\UtfString;
-
use SqlParser\Tests\TestCase;
class UtfStringTest extends TestCase
{
-
/**
* Sample phrase in French.
*
diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php
index 653eae0..f063b6a 100644
--- a/tests/Parser/AlterStatementTest.php
+++ b/tests/Parser/AlterStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class AlterStatementTest extends TestCase
{
-
/**
* @dataProvider testAlterProvider
*/
diff --git a/tests/Parser/CallStatementTest.php b/tests/Parser/CallStatementTest.php
index 9e6ab2e..706168d 100644
--- a/tests/Parser/CallStatementTest.php
+++ b/tests/Parser/CallStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class CallStatementTest extends TestCase
{
-
/**
* @dataProvider testCallProvider
*/
diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php
index 6d611af..479482f 100644
--- a/tests/Parser/CreateStatementTest.php
+++ b/tests/Parser/CreateStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class CreateStatementTest extends TestCase
{
-
/**
* @dataProvider testCreateProvider
*/
diff --git a/tests/Parser/DeleteStatementTest.php b/tests/Parser/DeleteStatementTest.php
index 3b72270..9090253 100644
--- a/tests/Parser/DeleteStatementTest.php
+++ b/tests/Parser/DeleteStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class DeleteStatementTest extends TestCase
{
-
/**
* @dataProvider testDeleteProvider
*/
diff --git a/tests/Parser/ExplainStatement.php b/tests/Parser/ExplainStatement.php
index 6a1a58e..a8581be 100644
--- a/tests/Parser/ExplainStatement.php
+++ b/tests/Parser/ExplainStatement.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class ExplainStatementTest extends TestCase
{
-
/**
* @dataProvider testExplainProvider
*/
diff --git a/tests/Parser/InsertStatementTest.php b/tests/Parser/InsertStatementTest.php
index 45923d2..371d3cf 100644
--- a/tests/Parser/InsertStatementTest.php
+++ b/tests/Parser/InsertStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class InsertStatementTest extends TestCase
{
-
/**
* @dataProvider testInsertProvider
*/
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index 190764e..0d0cd97 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -6,12 +6,10 @@ use SqlParser\Exceptions\ParserException;
use SqlParser\Parser;
use SqlParser\Token;
use SqlParser\TokensList;
-
use SqlParser\Tests\TestCase;
class ParserTest extends TestCase
{
-
/**
* @dataProvider testParseProvider
*/
@@ -68,7 +66,7 @@ class ParserTest extends TestCase
}
/**
- * @expectedException SqlParser\Exceptions\ParserException
+ * @expectedException \SqlParser\Exceptions\ParserException
* @expectedExceptionMessage strict error
* @expectedExceptionCode 3
*/
diff --git a/tests/Parser/RenameStatementTest.php b/tests/Parser/RenameStatementTest.php
index eae70ca..baea94c 100644
--- a/tests/Parser/RenameStatementTest.php
+++ b/tests/Parser/RenameStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class RenameStatementTest extends TestCase
{
-
/**
* @dataProvider testRenameProvider
*/
diff --git a/tests/Parser/ReplaceStatementTest.php b/tests/Parser/ReplaceStatementTest.php
index 2bc85ec..eb38628 100644
--- a/tests/Parser/ReplaceStatementTest.php
+++ b/tests/Parser/ReplaceStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class ReplaceStatementTest extends TestCase
{
-
/**
* @dataProvider testReplaceProvider
*/
diff --git a/tests/Parser/RestoreStatementTest.php b/tests/Parser/RestoreStatementTest.php
index 7c41074..cee72e3 100644
--- a/tests/Parser/RestoreStatementTest.php
+++ b/tests/Parser/RestoreStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class RestoreStatementTest extends TestCase
{
-
/**
* @dataProvider testRestoreProvider
*/
diff --git a/tests/Parser/SelectStatementTest.php b/tests/Parser/SelectStatementTest.php
index 2e3913e..bbfc926 100644
--- a/tests/Parser/SelectStatementTest.php
+++ b/tests/Parser/SelectStatementTest.php
@@ -3,12 +3,10 @@
namespace SqlParser\Tests\Parser;
use SqlParser\Tests\TestCase;
-
use SqlParser\Parser;
class SelectStatementTest extends TestCase
{
-
public function testSelectOptions()
{
$data = $this->getData('parser/parseSelect');
diff --git a/tests/Parser/SetStatementTest.php b/tests/Parser/SetStatementTest.php
index d9df799..20b783c 100644
--- a/tests/Parser/SetStatementTest.php
+++ b/tests/Parser/SetStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class SetStatementTest extends TestCase
{
-
/**
* @dataProvider testSetProvider
*/
diff --git a/tests/Parser/TransactionStatementTest.php b/tests/Parser/TransactionStatementTest.php
index d0b99cb..c5230f5 100644
--- a/tests/Parser/TransactionStatementTest.php
+++ b/tests/Parser/TransactionStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class TransactionStatementTest extends TestCase
{
-
/**
* @dataProvider testTransactionProvider
*/
diff --git a/tests/Parser/UpdateStatementTest.php b/tests/Parser/UpdateStatementTest.php
index 2b0c233..bcd39b1 100644
--- a/tests/Parser/UpdateStatementTest.php
+++ b/tests/Parser/UpdateStatementTest.php
@@ -6,7 +6,6 @@ use SqlParser\Tests\TestCase;
class UpdateStatementTest extends TestCase
{
-
/**
* @dataProvider testUpdateProvider
*/
diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php
index 41e14ff..a3e897b 100644
--- a/tests/Utils/BufferedQueryTest.php
+++ b/tests/Utils/BufferedQueryTest.php
@@ -3,19 +3,17 @@
namespace SqlParser\Tests\Utils;
use SqlParser\Utils\BufferedQuery;
-
use SqlParser\Tests\TestCase;
class BufferedQueryTest extends TestCase
{
-
/**
* @dataProvider testExtractProvider
*/
public function testExtract(
$query,
$chunkSize,
- array $options = array(),
+ array $options,
array $expected
) {
$chunks = str_split($query, $chunkSize);
@@ -24,14 +22,14 @@ class BufferedQueryTest extends TestCase
/**
* The array of extracted statements.
*
- * @var array $statements
+ * @var array
*/
$statements = array();
/**
* The `BufferedQuery` instance used for extraction.
*
- * @var BufferedQuery $bq
+ * @var BufferedQuery
*/
$bq = new BufferedQuery('', $options);
@@ -99,7 +97,6 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */';
return array(
-
array(
"SELECT '\'';\nSELECT '\'';",
8,
@@ -110,7 +107,7 @@ class BufferedQueryTest extends TestCase
array(
"SELECT '\'';",
"SELECT '\'';",
- )
+ ),
),
array(
@@ -128,11 +125,11 @@ class BufferedQueryTest extends TestCase
array(
"CREATE TABLE `test` (\n" .
" `txt` varchar(10)\n" .
- ");",
+ ');',
"INSERT INTO `test` (`txt`) VALUES('abc');",
"INSERT INTO `test` (`txt`) VALUES('\\\\');",
"INSERT INTO `test` (`txt`) VALUES('xyz');",
- )
+ ),
),
array(
@@ -145,8 +142,8 @@ class BufferedQueryTest extends TestCase
),
array(
'SELECT """""""";',
- 'SELECT """\\\\"""'
- )
+ 'SELECT """\\\\"""',
+ ),
),
array(
@@ -161,8 +158,8 @@ class BufferedQueryTest extends TestCase
array(
'DELIMITER A_VERY_LONG_DEL',
'SELECT 1 A_VERY_LONG_DEL',
- 'DELIMITER ;'
- )
+ 'DELIMITER ;',
+ ),
),
array(
@@ -207,8 +204,8 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
- '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */'
- )
+ '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
+ ),
),
array(
@@ -258,7 +255,7 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */',
'/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
- )
+ ),
),
array(
@@ -303,9 +300,9 @@ class BufferedQueryTest extends TestCase
'/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;',
- '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */'
- )
- )
+ '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */',
+ ),
+ ),
);
}
}
diff --git a/tests/Utils/CLITest.php b/tests/Utils/CLITest.php
index 21adde4..3f5796d 100644
--- a/tests/Utils/CLITest.php
+++ b/tests/Utils/CLITest.php
@@ -10,6 +10,7 @@ class CLITest extends TestCase
{
$cli = $this->getMockBuilder('SqlParser\Utils\CLI')->setMethods(array('getopt'))->getMock();
$cli->method('getopt')->willReturn($getopt);
+
return $cli;
}
diff --git a/tests/Utils/ErrorTest.php b/tests/Utils/ErrorTest.php
index 25e65f4..8408194 100644
--- a/tests/Utils/ErrorTest.php
+++ b/tests/Utils/ErrorTest.php
@@ -5,12 +5,10 @@ namespace SqlParser\Tests\Utils;
use SqlParser\Lexer;
use SqlParser\Parser;
use SqlParser\Utils\Error;
-
use SqlParser\Tests\TestCase;
class ErrorTest extends TestCase
{
-
public function testGet()
{
$lexer = new Lexer('SELECT * FROM db..tbl $');
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index f8a911f..1e03d17 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -3,7 +3,6 @@
namespace SqlParser\Tests\Utils;
use SqlParser\Utils\Formatter;
-
use SqlParser\Tests\TestCase;
class FormatTest extends TestCase
@@ -36,13 +35,13 @@ class FormatTest extends TestCase
'line_ending' => '<br>',
'clause_newline' => null,
'parts_newline' => 0,
- 'formats' => $expected
+ 'formats' => $expected,
);
$overridingOptions = array(
'type' => 'test-type',
'line_ending' => '<br>',
- 'formats' => $overriding
+ 'formats' => $overriding,
);
$reflectionMethod = new \ReflectionMethod($formatter, 'getMergedOptions');
@@ -98,7 +97,7 @@ class FormatTest extends TestCase
'type' => 0,
'html' => 'new html',
'cli' => 'new cli',
- )
+ ),
),
array( // expected
array(
@@ -246,20 +245,20 @@ class FormatTest extends TestCase
'SELECT 1',
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
' <span class="sql-number">1</span>',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'SELECT 1 # Comment',
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
' <span class="sql-number">1</span> <span class="sql-comment"># Comment' . "\n" .
'</span>',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'SELECT HEX("1")',
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
' <span class="sql-keyword">HEX</span>(<span class="sql-string">"1"</span>)',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'SELECT * FROM foo WHERE bar=1',
@@ -269,7 +268,7 @@ class FormatTest extends TestCase
' foo' . '<br/>' .
'<span class="sql-reserved">WHERE</span>' . '<br/>' .
' bar = <span class="sql-number">1</span>',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'CREATE PROCEDURE SPTEST() BEGIN FROM a SELECT *; END',
@@ -281,7 +280,7 @@ class FormatTest extends TestCase
'<span class="sql-reserved">SELECT</span>' . '<br/>' .
' *;' . '<br/>' .
'<span class="sql-keyword">END</span>',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'INSERT INTO foo VALUES (0, 0, 0), (1, 1, 1)',
@@ -291,17 +290,17 @@ class FormatTest extends TestCase
'<span class="sql-reserved">VALUES</span>' .
'(<span class="sql-number">0</span>, <span class="sql-number">0</span>, <span class="sql-number">0</span>),' .
'(<span class="sql-number">1</span>, <span class="sql-number">1</span>, <span class="sql-number">1</span>)',
- array('type' => 'html')
+ array('type' => 'html'),
),
array(
'SELECT 1',
"\x1b[35mSELECT\n \x1b[92m1\x1b[0m",
- array('type' => 'cli')
+ array('type' => 'cli'),
),
array(
'SELECT "Text" AS BAR',
"\x1b[35mSELECT\n \x1b[91m\"Text\" \x1b[35mAS \x1b[39mBAR\x1b[0m",
- array('type' => 'cli')
+ array('type' => 'cli'),
),
array(
'SELECT coditm AS Item, descripcion AS Descripcion, contenedores AS Contenedores, IF(suspendido = 1, Si, NO) AS Suspendido FROM `DW_articulos` WHERE superado = 0',
diff --git a/tests/Utils/MiscTest.php b/tests/Utils/MiscTest.php
index 854e361..c8b45f2 100644
--- a/tests/Utils/MiscTest.php
+++ b/tests/Utils/MiscTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Utils;
use SqlParser\Parser;
use SqlParser\Utils\Misc;
-
use SqlParser\Tests\TestCase;
class MiscTest extends TestCase
{
-
/**
* @dataProvider getAliasesProvider
*/
@@ -40,12 +38,12 @@ class MiscTest extends TestCase
'alias' => 'i',
'columns' => array(
'name' => 'n',
- 'abcdef' => 'gh'
- )
- )
- )
- )
- )
+ 'abcdef' => 'gh',
+ ),
+ ),
+ ),
+ ),
+ ),
),
array(
'select film_id id,title from film',
@@ -57,12 +55,12 @@ class MiscTest extends TestCase
'film' => array(
'alias' => null,
'columns' => array(
- 'film_id' => 'id'
- )
- )
- )
- )
- )
+ 'film_id' => 'id',
+ ),
+ ),
+ ),
+ ),
+ ),
),
array(
'select `sakila`.`A`.`actor_id` as aid,`F`.`film_id` `fid`,'
@@ -77,34 +75,34 @@ class MiscTest extends TestCase
'alias' => 'F',
'columns' => array(
'film_id' => 'fid',
- 'last_update' => 'updated'
- )
+ 'last_update' => 'updated',
+ ),
),
'actor' => array(
- 'alias'=> 'A',
+ 'alias' => 'A',
'columns' => array(
'actor_id' => 'aid',
- 'last_update' => 'updated'
- )
- )
- )
- )
- )
+ 'last_update' => 'updated',
+ ),
+ ),
+ ),
+ ),
+ ),
),
array(
'SELECT film_id FROM (SELECT * FROM film) as f;',
'sakila',
- array()
+ array(),
),
array(
'',
null,
- array()
+ array(),
),
array(
'SELECT 1',
null,
- array()
+ array(),
),
array(
'SELECT * FROM orders AS ord WHERE 1',
@@ -116,10 +114,10 @@ class MiscTest extends TestCase
'orders' => array(
'alias' => 'ord',
'columns' => array(),
- )
+ ),
),
),
- )
+ ),
),
);
}
diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php
index b5135c0..28b24ad 100644
--- a/tests/Utils/QueryTest.php
+++ b/tests/Utils/QueryTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Utils;
use SqlParser\Parser;
use SqlParser\Utils\Query;
-
use SqlParser\Tests\TestCase;
class QueryTest extends TestCase
{
-
/**
* @dataProvider testGetFlagsProvider
*/
@@ -29,29 +27,29 @@ class QueryTest extends TestCase
'ALTER TABLE DROP col',
array(
'reload' => true,
- 'querytype' => 'ALTER'
- )
+ 'querytype' => 'ALTER',
+ ),
),
array(
'CALL test()',
array(
'is_procedure' => true,
- 'querytype' => 'CALL'
- )
+ 'querytype' => 'CALL',
+ ),
),
array(
'CREATE TABLE tbl (id INT)',
array(
'reload' => true,
- 'querytype' => 'CREATE'
- )
+ 'querytype' => 'CREATE',
+ ),
),
array(
'CHECK TABLE tbl',
array(
'is_maint' => true,
- 'querytype' => 'CHECK'
- )
+ 'querytype' => 'CHECK',
+ ),
),
array(
'DELETE FROM tbl',
@@ -65,22 +63,22 @@ class QueryTest extends TestCase
'DROP VIEW v',
array(
'reload' => true,
- 'querytype' => 'DROP'
- )
+ 'querytype' => 'DROP',
+ ),
),
array(
'DROP DATABASE db',
array(
'drop_database' => true,
'reload' => true,
- 'querytype' => 'DROP'
- )
+ 'querytype' => 'DROP',
+ ),
),
array(
'EXPLAIN tbl',
array(
'is_explain' => true,
- 'querytype' => 'EXPLAIN'
+ 'querytype' => 'EXPLAIN',
),
),
array(
@@ -88,8 +86,8 @@ class QueryTest extends TestCase
array(
'is_affected' => true,
'is_insert' => true,
- 'querytype' => 'INSERT'
- )
+ 'querytype' => 'INSERT',
+ ),
),
array(
'REPLACE INTO tbl VALUES (2)',
@@ -97,23 +95,23 @@ class QueryTest extends TestCase
'is_affected' => true,
'is_replace' => true,
'is_insert' => true,
- 'querytype' => 'REPLACE'
- )
+ 'querytype' => 'REPLACE',
+ ),
),
array(
'SELECT 1',
array(
'is_select' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM tbl',
array(
'is_select' => true,
'select_from' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT DISTINCT * FROM tbl LIMIT 0, 10 ORDER BY id',
@@ -123,8 +121,8 @@ class QueryTest extends TestCase
'select_from' => true,
'limit' => true,
'order' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM actor GROUP BY actor_id',
@@ -133,8 +131,8 @@ class QueryTest extends TestCase
'is_select' => true,
'select_from' => true,
'group' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);',
@@ -142,8 +140,8 @@ class QueryTest extends TestCase
'is_analyse' => true,
'is_select' => true,
'select_from' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"',
@@ -151,8 +149,8 @@ class QueryTest extends TestCase
'is_export' => true,
'is_select' => true,
'select_from' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT COUNT(id), SUM(id) FROM tbl',
@@ -161,16 +159,16 @@ class QueryTest extends TestCase
'is_func' => true,
'is_select' => true,
'select_from' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT (SELECT "foo")',
array(
'is_select' => true,
'is_subquery' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM customer HAVING store_id = 2;',
@@ -179,8 +177,8 @@ class QueryTest extends TestCase
'select_from' => true,
'is_group' => true,
'having' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;',
@@ -188,50 +186,50 @@ class QueryTest extends TestCase
'is_select' => true,
'select_from' => true,
'join' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SHOW CREATE TABLE tbl',
array(
'is_show' => true,
- 'querytype' => 'SHOW'
- )
+ 'querytype' => 'SHOW',
+ ),
),
array(
'UPDATE tbl SET id = 1',
array(
'is_affected' => true,
- 'querytype' => 'UPDATE'
- )
+ 'querytype' => 'UPDATE',
+ ),
),
array(
'ANALYZE TABLE tbl',
array(
'is_maint' => true,
- 'querytype' => 'ANALYZE'
- )
+ 'querytype' => 'ANALYZE',
+ ),
),
array(
'CHECKSUM TABLE tbl',
array(
'is_maint' => true,
- 'querytype' => 'CHECKSUM'
- )
+ 'querytype' => 'CHECKSUM',
+ ),
),
array(
'OPTIMIZE TABLE tbl',
array(
'is_maint' => true,
- 'querytype' => 'OPTIMIZE'
- )
+ 'querytype' => 'OPTIMIZE',
+ ),
),
array(
'REPAIR TABLE tbl',
array(
'is_maint' => true,
- 'querytype' => 'REPAIR'
- )
+ 'querytype' => 'REPAIR',
+ ),
),
array(
'(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) ' .
@@ -243,8 +241,8 @@ class QueryTest extends TestCase
'limit' => true,
'order' => true,
'union' => true,
- 'querytype' => 'SELECT'
- )
+ 'querytype' => 'SELECT',
+ ),
),
array(
'SELECT * FROM orders AS ord WHERE 1',
@@ -252,7 +250,7 @@ class QueryTest extends TestCase
'querytype' => 'SELECT',
'is_select' => true,
'select_from' => true,
- )
+ ),
),
);
}
@@ -305,7 +303,7 @@ class QueryTest extends TestCase
'select_tables' => array(
array('actor', null),
array('film', 'sakila2'),
- )
+ ),
)
),
Query::getAll($query)
@@ -323,7 +321,7 @@ class QueryTest extends TestCase
'select_tables' => array(
array('actor', 'sakila'),
array('film', null),
- )
+ ),
)
),
Query::getAll($query)
@@ -340,7 +338,7 @@ class QueryTest extends TestCase
'select_expr' => array(),
'select_tables' => array(
array('actor', 'sakila'),
- )
+ ),
)
),
Query::getAll($query)
@@ -510,7 +508,7 @@ class QueryTest extends TestCase
$query = 'USE sakila; ' .
'/*test comment*/' .
- 'SELECT * FROM actor; '.
+ 'SELECT * FROM actor; ' .
'DELIMITER $$ ' .
'UPDATE actor SET last_name = "abc"$$' .
'/*!SELECT * FROM actor WHERE last_name = "abc"*/$$';
diff --git a/tests/Utils/RoutineTest.php b/tests/Utils/RoutineTest.php
index 51f558f..2c016e2 100644
--- a/tests/Utils/RoutineTest.php
+++ b/tests/Utils/RoutineTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Utils;
use SqlParser\Parser;
use SqlParser\Utils\Routine;
-
use SqlParser\Tests\TestCase;
class RoutineTest extends TestCase
{
-
/**
* @dataProvider getReturnTypeProvider
*/
@@ -26,26 +24,26 @@ class RoutineTest extends TestCase
array('INT(20)', array('', '', 'INT', '20', '')),
array(
'INT UNSIGNED',
- array('', '', 'INT', '', 'UNSIGNED')
+ array('', '', 'INT', '', 'UNSIGNED'),
),
array(
'VARCHAR(1) CHARSET utf8',
- array('', '', 'VARCHAR', '1', 'utf8')
+ array('', '', 'VARCHAR', '1', 'utf8'),
),
array(
'ENUM(\'a\', \'b\') CHARSET latin1',
- array('', '', 'ENUM', '\'a\',\'b\'', 'latin1')
+ array('', '', 'ENUM', '\'a\',\'b\'', 'latin1'),
),
array(
'DECIMAL(5,2) UNSIGNED ZEROFILL',
- array('', '', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')
+ array('', '', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL'),
),
array(
'SET(\'test\'\'esc"\', \'more\\\'esc\')',
array(
- '', '', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''
- )
- )
+ '', '', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '',
+ ),
+ ),
);
}
@@ -65,26 +63,26 @@ class RoutineTest extends TestCase
array('`foo` INT(20)', array('', 'foo', 'INT', '20', '')),
array(
'IN `fo``fo` INT UNSIGNED',
- array('IN', 'fo`fo', 'INT', '', 'UNSIGNED')
+ array('IN', 'fo`fo', 'INT', '', 'UNSIGNED'),
),
array(
'OUT bar VARCHAR(1) CHARSET utf8',
- array('OUT', 'bar', 'VARCHAR', '1', 'utf8')
+ array('OUT', 'bar', 'VARCHAR', '1', 'utf8'),
),
array(
'`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1',
- array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1')
+ array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1'),
),
array(
'INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL',
- array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')
+ array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL'),
),
array(
'`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')',
array(
- '', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''
- )
- )
+ '', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '',
+ ),
+ ),
);
}
@@ -109,87 +107,87 @@ class RoutineTest extends TestCase
'type' => array(),
'length' => array(),
'length_arr' => array(),
- 'opts' => array()
- )
+ 'opts' => array(),
+ ),
),
array(
'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
array(
'num' => 1,
'dir' => array(
- 0 => ''
+ 0 => '',
),
'name' => array(
- 0 => 'baz'
+ 0 => 'baz',
),
'type' => array(
- 0 => 'INT'
+ 0 => 'INT',
),
'length' => array(
- 0 => ''
+ 0 => '',
),
'length_arr' => array(
0 => array(),
),
'opts' => array(
- 0 => ''
- )
- )
+ 0 => '',
+ ),
+ ),
),
array(
'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
array(
'num' => 1,
'dir' => array(
- 0 => 'IN'
+ 0 => 'IN',
),
'name' => array(
- 0 => 'baz\\)'
+ 0 => 'baz\\)',
),
'type' => array(
- 0 => 'INT'
+ 0 => 'INT',
),
'length' => array(
- 0 => '25'
+ 0 => '25',
),
'length_arr' => array(
0 => array('25'),
),
'opts' => array(
- 0 => 'UNSIGNED ZEROFILL'
- )
- )
+ 0 => 'UNSIGNED ZEROFILL',
+ ),
+ ),
),
array(
- 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) '.
+ 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' .
'BEGIN SELECT NULL; END',
array(
'num' => 2,
'dir' => array(
0 => 'IN',
- 1 => 'OUT'
+ 1 => 'OUT',
),
'name' => array(
0 => 'baz\\',
- 1 => 'bazz'
+ 1 => 'bazz',
),
'type' => array(
0 => 'INT',
- 1 => 'VARCHAR'
+ 1 => 'VARCHAR',
),
'length' => array(
0 => '1',
- 1 => '15'
+ 1 => '15',
),
'length_arr' => array(
0 => array('1'),
- 1 => array('15')
+ 1 => array('15'),
),
'opts' => array(
0 => 'ZEROFILL',
- 1 => 'utf8'
- )
- )
+ 1 => 'utf8',
+ ),
+ ),
),
);
}
diff --git a/tests/Utils/TableTest.php b/tests/Utils/TableTest.php
index 3e577eb..f80b586 100644
--- a/tests/Utils/TableTest.php
+++ b/tests/Utils/TableTest.php
@@ -4,12 +4,10 @@ namespace SqlParser\Tests\Utils;
use SqlParser\Parser;
use SqlParser\Utils\Table;
-
use SqlParser\Tests\TestCase;
class TableTest extends TestCase
{
-
/**
* @dataProvider getForeignKeysProvider
*/
@@ -176,9 +174,9 @@ class TableTest extends TestCase
'timestamp_not_null' => true,
'default_value' => 'CURRENT_TIMESTAMP',
'default_current_timestamp' => true,
- 'on_update_current_timestamp' => true
- )
- )
+ 'on_update_current_timestamp' => true,
+ ),
+ ),
),
array(
'CREATE TABLE table1 (
diff --git a/tests/Utils/TokensTest.php b/tests/Utils/TokensTest.php
index 9ddbe5c..6222d5f 100644
--- a/tests/Utils/TokensTest.php
+++ b/tests/Utils/TokensTest.php
@@ -2,15 +2,12 @@
namespace SqlParser\Tests\Utils;
-use SqlParser\Parser;
use SqlParser\Token;
use SqlParser\Utils\Tokens;
-
use SqlParser\Tests\TestCase;
class TokensTest extends TestCase
{
-
/**
* @dataProvider replaceTokensProvider
*/
@@ -33,7 +30,7 @@ class TokensTest extends TestCase
new Token('.'),
),
'SELECT * FROM /*x*/c.b',
- )
+ ),
);
}
@@ -53,53 +50,53 @@ class TokensTest extends TestCase
array(
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('token' => '"abc"'),
- true
+ true,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('value' => 'abc'),
- true
+ true,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('value_str' => 'ABC'),
- true
+ true,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('type' => Token::TYPE_STRING),
- true
+ true,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('flags' => Token::FLAG_STRING_DOUBLE_QUOTES),
- true
+ true,
),
array(
new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('token' => '"abcd"'),
- false
+ false,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('value' => 'abcd'),
- false
+ false,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('value_str' => 'ABCd'),
- false
+ false,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('type' => Token::TYPE_NUMBER),
- false
+ false,
),
array(
new Token('"abc""', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES),
array('flags' => Token::FLAG_STRING_SINGLE_QUOTES),
- false
+ false,
),
);
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 89b5980..3c3c446 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -2,9 +2,6 @@
/**
* Bootstrap for tests.
- *
- * @package SqlParser
- * @subpackage Tests
*/
namespace SqlParser\Tests;
@@ -18,30 +15,29 @@ require_once 'vendor/autoload.php';
* Implements useful methods for testing.
*
* @category Tests
- * @package SqlParser
- * @subpackage Tests
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
-
/**
* Gets the token list generated by lexing this query.
*
- * @param string $query The query to be lexed.
+ * @param string $query the query to be lexed
*
* @return TokensList
*/
public function getTokensList($query)
{
$lexer = new Lexer($query);
+
return $lexer->list;
}
/**
* Gets the errors as an array.
*
- * @param Lexer|Parser $obj Object containing the errors.
+ * @param Lexer|Parser $obj object containing the errors
*
* @return array
*/
@@ -53,13 +49,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
? array($err->getMessage(), $err->ch, $err->pos, $err->getCode())
: array($err->getMessage(), $err->token, $err->getCode());
}
+
return $ret;
}
/**
* Gets test's input and expected output.
*
- * @param string $name The name of the test.
+ * @param string $name the name of the test
*
* @return array
*/
@@ -72,22 +69,21 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
*/
$data = unserialize(file_get_contents('tests/data/' . $name . '.out'));
$data['query'] = file_get_contents('tests/data/' . $name . '.in');
+
return $data;
}
/**
* Runs a test.
*
- * @param string $name The name of the test.
- *
- * @return void
+ * @param string $name the name of the test
*/
public function runParserTest($name)
{
/**
* Test's data.
*
- * @var array $data
+ * @var array
*/
$data = $this->getData($name);
diff --git a/tools/ContextGenerator.php b/tools/ContextGenerator.php
index 0ea5db9..e34d862 100644
--- a/tools/ContextGenerator.php
+++ b/tools/ContextGenerator.php
@@ -8,23 +8,21 @@ require_once '../vendor/autoload.php';
* Used for context generation.
*
* @category Contexts
- * @package SqlParser
- * @subpackage Tools
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ContextGenerator
{
-
/**
* Labels and flags that may be used when defining keywords.
*
* @var array
*/
public static $LABELS_FLAGS = array(
- '(R)' => 2, // reserved
- '(D)' => 8, // data type
- '(K)' => 16, // keyword
- '(F)' => 32, // function name
+ '(R)' => 2, // reserved
+ '(D)' => 8, // data type
+ '(K)' => 16, // keyword
+ '(F)' => 32, // function name
);
/**
@@ -52,46 +50,46 @@ class ContextGenerator
* @var string
*/
const TEMPLATE =
- '<?php' . "\n" .
- '' . "\n" .
- '/**' . "\n" .
- ' * Context for %1$s.' . "\n" .
- ' *' . "\n" .
- ' * This file was auto-generated.' . "\n" .
- ' *' . "\n" .
- ' * @package SqlParser' . "\n" .
- ' * @subpackage Contexts' . "\n" .
- ' * @link %3$s' . "\n" .
- ' */' . "\n" .
- 'namespace SqlParser\\Contexts;' . "\n" .
- '' . "\n" .
- 'use SqlParser\\Context;' . "\n" .
- '' . "\n" .
- '/**' . "\n" .
- ' * Context for %1$s.' . "\n" .
- ' *' . "\n" .
- ' * @category Contexts' . "\n" .
- ' * @package SqlParser' . "\n" .
- ' * @subpackage Contexts' . "\n" .
- ' * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+' . "\n" .
- ' */' . "\n" .
- 'class %2$s extends Context' . "\n" .
- '{' . "\n" .
- '' . "\n" .
- ' /**' . "\n" .
- ' * List of keywords.' . "\n" .
- ' *' . "\n" .
- ' * The value associated to each keyword represents its flags.' . "\n" .
- ' *' . "\n" .
- ' * @see Token::FLAG_KEYWORD_*' . "\n" .
- ' *' . "\n" .
- ' * @var array' . "\n" .
- ' */' . "\n" .
- ' public static $KEYWORDS = array(' . "\n" .
- '' . "\n" .
- '%4$s' .
- ' );' . "\n" .
- '}' . "\n";
+ '<?php' . "\n" .
+ '' . "\n" .
+ '/**' . "\n" .
+ ' * Context for %1$s.' . "\n" .
+ ' *' . "\n" .
+ ' * This file was auto-generated.' . "\n" .
+ ' *' . "\n" .
+ ' * @package SqlParser' . "\n" .
+ ' * @subpackage Contexts' . "\n" .
+ ' * @link %3$s' . "\n" .
+ ' */' . "\n" .
+ 'namespace SqlParser\\Contexts;' . "\n" .
+ '' . "\n" .
+ 'use SqlParser\\Context;' . "\n" .
+ '' . "\n" .
+ '/**' . "\n" .
+ ' * Context for %1$s.' . "\n" .
+ ' *' . "\n" .
+ ' * @category Contexts' . "\n" .
+ ' * @package SqlParser' . "\n" .
+ ' * @subpackage Contexts' . "\n" .
+ ' * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+' . "\n" .
+ ' */' . "\n" .
+ 'class %2$s extends Context' . "\n" .
+ '{' . "\n" .
+ '' . "\n" .
+ ' /**' . "\n" .
+ ' * List of keywords.' . "\n" .
+ ' *' . "\n" .
+ ' * The value associated to each keyword represents its flags.' . "\n" .
+ ' *' . "\n" .
+ ' * @see Token::FLAG_KEYWORD_*' . "\n" .
+ ' *' . "\n" .
+ ' * @var array' . "\n" .
+ ' */' . "\n" .
+ ' public static $KEYWORDS = array(' . "\n" .
+ '' . "\n" .
+ '%4$s' .
+ ' );' . "\n" .
+ '}' . "\n";
/**
* Sorts an array of words.
@@ -109,6 +107,7 @@ class ContextGenerator
sort($words, SORT_STRING);
}
}
+
return $arr;
}
@@ -177,9 +176,9 @@ class ContextGenerator
/**
* Prints an array of a words in PHP format.
*
- * @param array $words The list of words to be formatted.
- * @param int $spaces The number of spaces that starts every line.
- * @param int $line The length of a line.
+ * @param array $words the list of words to be formatted
+ * @param int $spaces the number of spaces that starts every line
+ * @param int $line the length of a line
*
* @return string
*/
@@ -218,7 +217,7 @@ class ContextGenerator
/**
* Generates a context's class.
*
- * @param array $options The options that are used in generating this context.
+ * @param array $options the options that are used in generating this context
*
* @return string
*/
@@ -242,14 +241,11 @@ class ContextGenerator
*
* Reads the input file, generates the data and writes it back.
*
- * @param string $input The input file.
- * @param string $output The output directory.
- *
- * @return void
+ * @param string $input the input file
+ * @param string $output the output directory
*/
public static function build($input, $output)
{
-
/**
* The directory that contains the input file.
*
@@ -295,14 +291,14 @@ class ContextGenerator
$output . '/' . $class . '.php',
static::generate(
array(
- 'name' => $formattedName,
- 'class' => $class,
- 'link' => static::$LINKS[$name],
- 'keywords' => static::readWords(
+ 'name' => $formattedName,
+ 'class' => $class,
+ 'link' => static::$LINKS[$name],
+ 'keywords' => static::readWords(
array(
$directory . '_common.txt',
$directory . '_functions' . $file,
- $directory . $file
+ $directory . $file,
)
),
)
@@ -313,10 +309,8 @@ class ContextGenerator
/**
* Generates recursively all tests preserving the directory structure.
*
- * @param string $input The input directory.
- * @param string $output The output directory.
- *
- * @return void
+ * @param string $input the input directory
+ * @param string $output the output directory
*/
public static function buildAll($input, $output)
{
diff --git a/tools/TestGenerator.php b/tools/TestGenerator.php
index 4d000f5..b4820ce 100644
--- a/tools/TestGenerator.php
+++ b/tools/TestGenerator.php
@@ -11,28 +11,25 @@ use SqlParser\Parser;
* Used for test generation.
*
* @category Tests
- * @package SqlParser
- * @subpackage Tools
+ *
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class TestGenerator
{
-
/**
* Generates a test's data.
*
- * @param string $query The query to be analyzed.
- * @param string $type Test's type (may be `lexer` or `parser`).
+ * @param string $query the query to be analyzed
+ * @param string $type test's type (may be `lexer` or `parser`)
*
* @return array
*/
public static function generate($query, $type = 'parser')
{
-
/**
* Lexer used for tokenizing the query.
*
- * @var Lexer $lexer
+ * @var Lexer
*/
$lexer = new Lexer($query);
@@ -40,21 +37,21 @@ class TestGenerator
* Parsed used for analyzing the query.
* A new instance of parser is generated only if the test requires.
*
- * @var Parser $parser
+ * @var Parser
*/
$parser = ($type === 'parser') ? new Parser($lexer->list) : null;
/**
* Lexer's errors.
*
- * @var array $lexerErrors
+ * @var array
*/
$lexerErrors = array();
/**
* Parser's errors.
*
- * @var array $parserErrors
+ * @var array
*/
$parserErrors = array();
@@ -85,7 +82,7 @@ class TestGenerator
'parser' => $parser,
'errors' => array(
'lexer' => $lexerErrors,
- 'parser' => $parserErrors
+ 'parser' => $parserErrors,
),
);
}
@@ -95,12 +92,10 @@ class TestGenerator
*
* Reads the input file, generates the data and writes it back.
*
- * @param string $type The type of this test.
- * @param string $input The input file.
- * @param string $output The output file.
- * @param string $debug The debug file.
- *
- * @return void
+ * @param string $type the type of this test
+ * @param string $input the input file
+ * @param string $output the output file
+ * @param string $debug the debug file
*/
public static function build($type, $input, $output, $debug = null)
{
@@ -112,7 +107,7 @@ class TestGenerator
/**
* The query that is used to generate the test.
*
- * @var string $query
+ * @var string
*/
$query = file_get_contents($input);
@@ -135,10 +130,8 @@ class TestGenerator
/**
* Generates recursively all tests preserving the directory structure.
*
- * @param string $input The input directory.
- * @param string $output The output directory.
- *
- * @return void
+ * @param string $input the input directory
+ * @param string $output the output directory
*/
public static function buildAll($input, $output, $debug = null)
{