Skip to content

Commit 576b70d

Browse files
committed
Fixed coding style.
Fixed a bug which caused an infinite loop when a invalid DELIMITER statement was provided.
1 parent 67067a5 commit 576b70d

12 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/Component.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ abstract class Component
5151
* @param TokensList $list The list of tokens that are being parsed.
5252
* @param array $options Parameters for parsing.
5353
*
54+
* @throws \Exception Not implemented yet.
55+
*
5456
* @return mixed
5557
*/
5658
public static function parse(
@@ -69,6 +71,8 @@ public static function parse(
6971
*
7072
* @param mixed $component The component to be built.
7173
*
74+
* @throws \Exception Not implemented yet.
75+
*
7276
* @return string
7377
*/
7478
public static function build($component)

src/Components/UnionKeyword.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
namespace SqlParser\Components;
1010

1111
use SqlParser\Component;
12-
use SqlParser\Parser;
13-
use SqlParser\Token;
14-
use SqlParser\TokensList;
12+
use SqlParser\Statements\SelectStatement;
1513

1614
/**
1715
* `UNION` keyword builder.

src/Context.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public static function isSeparator($str)
416416
*/
417417
public static function load($context = '')
418418
{
419+
/**
420+
* @var Context $context
421+
*/
422+
419423
if (empty($context)) {
420424
$context = self::$defaultContext;
421425
}
@@ -467,6 +471,7 @@ public static function loadClosest($context = '')
467471
);
468472
continue;
469473
}
474+
470475
// Last generated context was valid (did not throw any exceptions).
471476
// So we return it, to let the user know what context was loaded.
472477
return $context;

src/Lexer.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ public function lex()
255255
&& ($token->type === Token::TYPE_SYMBOL)
256256
&& ($token->flags & Token::FLAG_SYMBOL_VARIABLE)
257257
&& (($lastToken->type === Token::TYPE_STRING)
258-
|| (($lastToken->type === Token::TYPE_SYMBOL)
259-
&& ($lastToken->flags & Token::FLAG_SYMBOL_BACKTICK)))
258+
|| (($lastToken->type === Token::TYPE_SYMBOL)
259+
&& ($lastToken->flags & Token::FLAG_SYMBOL_BACKTICK)))
260260
) {
261261
// Handles ```... FROM 'user'@'%' ...```.
262262
$lastToken->token .= $token->token;
@@ -266,7 +266,6 @@ public function lex()
266266
continue;
267267
} elseif (($lastToken !== null)
268268
&& ($token->type === Token::TYPE_KEYWORD)
269-
&& ($token->flags & Token::FLAG_KEYWORD_RESERVED)
270269
&& ($lastToken->type === Token::TYPE_OPERATOR)
271270
&& ($lastToken->value === '.')
272271
) {
@@ -316,6 +315,16 @@ public function lex()
316315
while ((++$this->last < $this->len) && (!Context::isWhitespace($this->str[$this->last]))) {
317316
$this->delimiter .= $this->str[$this->last];
318317
}
318+
319+
if (empty($this->delimiter)) {
320+
$this->error(
321+
__('Expected delimiter.'),
322+
'',
323+
$this->last
324+
);
325+
$this->delimiter = ';';
326+
}
327+
319328
--$this->last;
320329

321330
// Saving the delimiter and its token.
@@ -608,7 +617,7 @@ public function parseNumber()
608617
} elseif (($this->last + 1 < $this->len)
609618
&& ($this->str[$this->last] === '0')
610619
&& (($this->str[$this->last + 1] === 'x')
611-
|| ($this->str[$this->last + 1] === 'X'))
620+
|| ($this->str[$this->last + 1] === 'X'))
612621
) {
613622
$token .= $this->str[$this->last++];
614623
$state = 2;

src/Parser.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function parse()
332332

333333
/**
334334
* Last transaction.
335-
* @var TransactionStatement
335+
* @var TransactionStatement $lastTransaction
336336
*/
337337
$lastTransaction = null;
338338

@@ -435,6 +435,10 @@ public function parse()
435435
&& ($lastStatement instanceof SelectStatement)
436436
&& ($statement instanceof SelectStatement)
437437
) {
438+
/**
439+
* This SELECT statement.
440+
* @var SelectStatement $statement
441+
*/
438442

439443
/**
440444
* Last SELECT statement.
@@ -459,6 +463,10 @@ public function parse()
459463

460464
// Handles transactions.
461465
if ($statement instanceof TransactionStatement) {
466+
467+
/**
468+
* @var TransactionStatement $statement
469+
*/
462470
if ($statement->type === TransactionStatement::TYPE_BEGIN) {
463471
$lastTransaction = $statement;
464472
$this->statements[] = $statement;

src/Statement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function build()
124124

125125
/**
126126
* The builder (parser) of this clause.
127-
* @var string $class
127+
* @var Component $class
128128
*/
129129
$class = Parser::$KEYWORD_PARSERS[$name]['class'];
130130

@@ -213,7 +213,7 @@ public function parse(Parser $parser, TokensList $list)
213213

214214
/**
215215
* The name of the class that is used for parsing.
216-
* @var string $class
216+
* @var Component $class
217217
*/
218218
$class = null;
219219

src/Statements/SetStatement.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
namespace SqlParser\Statements;
1010

1111
use SqlParser\Statement;
12-
use SqlParser\Components\Expression;
13-
use SqlParser\Components\Limit;
14-
use SqlParser\Components\OrderKeyword;
1512
use SqlParser\Components\SetOperation;
16-
use SqlParser\Components\Condition;
1713

1814
/**
1915
* `SET` statement.

src/Statements/TransactionStatement.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
use SqlParser\Parser;
1212
use SqlParser\Statement;
13-
use SqlParser\Token;
1413
use SqlParser\TokensList;
15-
use SqlParser\Components\Expression;
1614
use SqlParser\Components\OptionsArray;
1715

1816
/**
@@ -51,7 +49,7 @@ class TransactionStatement extends Statement
5149
/**
5250
* The list of statements in this transaction.
5351
*
54-
* @var Statements[]
52+
* @var Statement[]
5553
*/
5654
public $statements;
5755

@@ -110,6 +108,9 @@ public function build()
110108
$ret = OptionsArray::build($this->options);
111109
if ($this->type === TransactionStatement::TYPE_BEGIN) {
112110
foreach ($this->statements as $statement) {
111+
/**
112+
* @var SelectStatement $statement
113+
*/
113114
$ret .= ';' . $statement->build();
114115
}
115116
$ret .= ';' . $this->end->build();

src/UtfString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function length()
209209
/**
210210
* Returns the contained string.
211211
*
212-
* @return strin
212+
* @return string
213213
*/
214214
public function __toString()
215215
{

tests/Lexer/LexerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function testLexProvider()
6464
array('lexer/lexDelimiter2'),
6565
array('lexer/lexDelimiterErr1'),
6666
array('lexer/lexDelimiterErr2'),
67+
array('lexer/lexDelimiterErr3'),
6768
array('lexer/lexKeyword'),
6869
array('lexer/lexKeyword2'),
6970
array('lexer/lexNumber'),

0 commit comments

Comments
 (0)