Skip to content

Commit 140040f

Browse files
committed
Fixed some Scrutinizer issues.
1 parent 3723f62 commit 140040f

2 files changed

Lines changed: 23 additions & 26 deletions

File tree

src/Lexer.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,8 @@ public function parseNumber()
516516
$state = 1;
517517
for (; $this->last < $this->len; ++$this->last) {
518518
if ($state === 1) {
519-
if ($this->str[$this->last] === '+') {
520-
// Do nothing.
521-
} elseif ($this->str[$this->last] === '-') {
519+
if ($this->str[$this->last] === '-') {
522520
$flags |= Token::FLAG_NUMBER_NEGATIVE;
523-
// Do nothing.
524521
} elseif (($this->str[$this->last] === '0') && ($this->last + 1 < $this->len)
525522
&& (($this->str[$this->last + 1] === 'x') || ($this->str[$this->last + 1] === 'X'))
526523
) {
@@ -530,36 +527,33 @@ public function parseNumber()
530527
$state = 3;
531528
} elseif ($this->str[$this->last] === '.') {
532529
$state = 4;
533-
} else {
530+
} elseif ($this->str[$this->last] !== '+') {
531+
// `+` is a valid character in a number.
534532
break;
535533
}
536534
} elseif ($state === 2) {
537535
$flags |= Token::FLAG_NUMBER_HEX;
538-
if ((($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9'))
536+
if (!((($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9'))
539537
|| (($this->str[$this->last] >= 'A') && ($this->str[$this->last] <= 'F'))
540-
|| (($this->str[$this->last] >= 'a') && ($this->str[$this->last] <= 'f'))
538+
|| (($this->str[$this->last] >= 'a') && ($this->str[$this->last] <= 'f')))
541539
) {
542-
// Do nothing.
543-
} else {
544540
break;
545541
}
546542
} elseif ($state === 3) {
547-
if (($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9')) {
548-
// Do nothing.
549-
} elseif ($this->str[$this->last] === '.') {
543+
if ($this->str[$this->last] === '.') {
550544
$state = 4;
551545
} elseif (($this->str[$this->last] === 'e') || ($this->str[$this->last] === 'E')) {
552546
$state = 5;
553-
} else {
547+
} elseif (($this->str[$this->last] < '0') || ($this->str[$this->last] > '9')) {
548+
// Just digits and `.`, `e` and `E` are valid characters.
554549
break;
555550
}
556551
} elseif ($state === 4) {
557552
$flags |= Token::FLAG_NUMBER_FLOAT;
558-
if (($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9')) {
559-
// Do nothing.
560-
} elseif (($this->str[$this->last] === 'e') || ($this->str[$this->last] === 'E')) {
553+
if (($this->str[$this->last] === 'e') || ($this->str[$this->last] === 'E')) {
561554
$state = 5;
562-
} else {
555+
} elseif (($this->str[$this->last] < '0') || ($this->str[$this->last] > '9')) {
556+
// Just digits, `e` and `E` are valid characters.
563557
break;
564558
}
565559
} elseif ($state === 5) {
@@ -572,9 +566,8 @@ public function parseNumber()
572566
break;
573567
}
574568
} elseif ($state === 6) {
575-
if (($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9')) {
576-
// Do nothing.
577-
} else {
569+
if (($this->str[$this->last] < '0') || ($this->str[$this->last] > '9')) {
570+
// Just digits are valid characters.
578571
break;
579572
}
580573
}

src/Statements/CreateStatement.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ class CreateStatement extends Statement
215215
*/
216216
public function build()
217217
{
218+
$fields = '';
219+
if (!empty($this->fields)) {
220+
if (is_array($this->fields)) {
221+
$fields = FieldDefinition::build($this->fields) . ' ';
222+
} elseif ($this->fields instanceof ArrayObj) {
223+
$fields = ArrayObj::build($this->fields);
224+
}
225+
}
218226
if ($this->options->has('DATABASE')) {
219227
return 'CREATE '
220228
. OptionsArray::build($this->options) . ' '
@@ -224,17 +232,13 @@ public function build()
224232
return 'CREATE '
225233
. OptionsArray::build($this->options) . ' '
226234
. Expression::build($this->name) . ' '
227-
. FieldDefinition::build($this->fields) . ' '
235+
. $fields
228236
. OptionsArray::build($this->entityOptions);
229237
} elseif ($this->options->has('VIEW')) {
230-
$tmp = '';
231-
if (!empty($this->fields)) {
232-
$tmp = ArrayObj::build($this->fields);
233-
}
234238
return 'CREATE '
235239
. OptionsArray::build($this->options) . ' '
236240
. Expression::build($this->name) . ' '
237-
. $tmp . ' AS ' . TokensList::build($this->body) . ' '
241+
. $fields . ' AS ' . TokensList::build($this->body) . ' '
238242
. OptionsArray::build($this->entityOptions);
239243
} elseif ($this->options->has('TRIGGER')) {
240244
return 'CREATE '

0 commit comments

Comments
 (0)