diff options
author | Damian Dlugosz <bigfootdd@gmail.com> | 2017-02-12 15:33:24 +0100 |
---|---|---|
committer | Damian Dlugosz <bigfootdd@gmail.com> | 2017-02-12 16:25:16 +0100 |
commit | 28be60a5645a93531d7ce34e9b099f7228c3d607 (patch) | |
tree | d18e9d109a460b201dab129466cff323c6955e4c | |
parent | 677de552c8577b9eebc3f8393a25f07e4bed2f31 (diff) | |
download | sql-parser-28be60a5645a93531d7ce34e9b099f7228c3d607.zip sql-parser-28be60a5645a93531d7ce34e9b099f7228c3d607.tar.gz sql-parser-28be60a5645a93531d7ce34e9b099f7228c3d607.tar.bz2 |
No useless else
-rw-r--r-- | .php_cs | 1 | ||||
-rw-r--r-- | src/Components/ArrayObj.php | 4 | ||||
-rw-r--r-- | src/Components/Condition.php | 4 | ||||
-rw-r--r-- | src/Components/CreateDefinition.php | 58 | ||||
-rw-r--r-- | src/Components/Expression.php | 36 | ||||
-rw-r--r-- | src/Components/IntoKeyword.php | 27 | ||||
-rw-r--r-- | src/Components/OrderKeyword.php | 4 | ||||
-rw-r--r-- | src/Components/ParameterDefinition.php | 16 | ||||
-rw-r--r-- | src/Components/PartitionDefinition.php | 25 | ||||
-rw-r--r-- | src/Components/RenameOperation.php | 4 | ||||
-rw-r--r-- | src/Components/SetOperation.php | 4 | ||||
-rw-r--r-- | src/Lexer.php | 6 | ||||
-rw-r--r-- | src/Statement.php | 3 | ||||
-rw-r--r-- | src/Statements/InsertStatement.php | 14 | ||||
-rw-r--r-- | src/Statements/ReplaceStatement.php | 17 |
15 files changed, 111 insertions, 112 deletions
@@ -14,6 +14,7 @@ return PhpCsFixer\Config::create() 'array_syntax' => array('syntax' => 'long'), 'concat_space' => array('spacing' => true), 'no_trailing_whitespace' => true, + 'no_useless_else' => true, 'phpdoc_order' => true, )) ->setFinder($finder) diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index feeb169..e86ddfd 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -182,8 +182,8 @@ class ArrayObj extends Component return implode(', ', $component); } elseif (!empty($component->raw)) { return '(' . implode(', ', $component->raw) . ')'; - } else { - return '(' . implode(', ', $component->values) . ')'; } + + return '(' . implode(', ', $component->values) . ')'; } } diff --git a/src/Components/Condition.php b/src/Components/Condition.php index 79899e8..99ab34c 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -220,8 +220,8 @@ class Condition extends Component { if (is_array($component)) { return implode(' ', $component); - } else { - return $component->expr; } + + return $component->expr; } } diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index 2bf6198..ed40518 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -201,8 +201,10 @@ class CreateDefinition extends Component 'An opening bracket was expected.', $token ); + break; } + } elseif ($state === 1) { if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'CONSTRAINT') { $expr->isConstraint = true; @@ -226,11 +228,11 @@ class CreateDefinition extends Component ); return $ret; - } else { - // Non-reserved keywords are allowed without backquotes - $expr->name = $token->value; - $state = 2; } + + // Non-reserved keywords are allowed without backquotes + $expr->name = $token->value; + $state = 2; } else { $parser->error( 'A symbol name was expected!', @@ -239,6 +241,7 @@ class CreateDefinition extends Component return $ret; } + } elseif ($state === 2) { $expr->type = DataType::parse($parser, $list); $state = 3; @@ -253,6 +256,7 @@ class CreateDefinition extends Component --$list->idx; } $state = 5; + } elseif ($state === 5) { if ((!empty($expr->type)) || (!empty($expr->key))) { $ret[] = $expr; @@ -302,35 +306,35 @@ class CreateDefinition extends Component { if (is_array($component)) { return "(\n " . implode(",\n ", $component) . "\n)"; - } else { - $tmp = ''; - - if ($component->isConstraint) { - $tmp .= 'CONSTRAINT '; - } + } - if ((isset($component->name)) && ($component->name !== '')) { - $tmp .= Context::escape($component->name) . ' '; - } + $tmp = ''; - if (!empty($component->type)) { - $tmp .= DataType::build( - $component->type, - array('lowercase' => true) - ) . ' '; - } + if ($component->isConstraint) { + $tmp .= 'CONSTRAINT '; + } - if (!empty($component->key)) { - $tmp .= $component->key . ' '; - } + if ((isset($component->name)) && ($component->name !== '')) { + $tmp .= Context::escape($component->name) . ' '; + } - if (!empty($component->references)) { - $tmp .= 'REFERENCES ' . $component->references . ' '; - } + if (!empty($component->type)) { + $tmp .= DataType::build( + $component->type, + array('lowercase' => true) + ) . ' '; + } - $tmp .= $component->options; + if (!empty($component->key)) { + $tmp .= $component->key . ' '; + } - return trim($tmp); + if (!empty($component->references)) { + $tmp .= 'REFERENCES ' . $component->references . ' '; } + + $tmp .= $component->options; + + return trim($tmp); } } diff --git a/src/Components/Expression.php b/src/Components/Expression.php index d3668d7..a5efde2 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -418,28 +418,28 @@ class Expression extends Component { if (is_array($component)) { return implode($component, ', '); + } + + if ($component->expr !== '' && !is_null($component->expr)) { + $ret = $component->expr; } else { - if ($component->expr !== '' && !is_null($component->expr)) { - $ret = $component->expr; - } else { - $fields = array(); - if ((isset($component->database)) && ($component->database !== '')) { - $fields[] = $component->database; - } - if ((isset($component->table)) && ($component->table !== '')) { - $fields[] = $component->table; - } - if ((isset($component->column)) && ($component->column !== '')) { - $fields[] = $component->column; - } - $ret = implode('.', Context::escape($fields)); + $fields = array(); + if ((isset($component->database)) && ($component->database !== '')) { + $fields[] = $component->database; } - - if (!empty($component->alias)) { - $ret .= ' AS ' . Context::escape($component->alias); + if ((isset($component->table)) && ($component->table !== '')) { + $fields[] = $component->table; + } + if ((isset($component->column)) && ($component->column !== '')) { + $fields[] = $component->column; } + $ret = implode('.', Context::escape($fields)); + } - return $ret; + if (!empty($component->alias)) { + $ret .= ' AS ' . Context::escape($component->alias); } + + return $ret; } } diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index a5c2d24..6c52f20 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -235,27 +235,26 @@ class IntoKeyword extends Component public static function build($component, array $options = array()) { if ($component->dest instanceof Expression) { - $columns = !empty($component->columns) ? - '(`' . implode('`, `', $component->columns) . '`)' : ''; + $columns = !empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; return $component->dest . $columns; } elseif (isset($component->values)) { return ExpressionArray::build($component->values); - } else { - $ret = 'OUTFILE "' . $component->dest . '"'; + } - $fields_options_str = OptionsArray::build($component->fields_options); - if (trim($fields_options_str) !== '') { - $ret .= ($component->fields_keyword) ? ' FIELDS' : ' COLUMNS'; - $ret .= ' ' . $fields_options_str; - } + $ret = 'OUTFILE "' . $component->dest . '"'; - $lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true)); - if (trim($lines_options_str) !== '') { - $ret .= ' LINES ' . $lines_options_str; - } + $fields_options_str = OptionsArray::build($component->fields_options); + if (trim($fields_options_str) !== '') { + $ret .= ($component->fields_keyword) ? ' FIELDS' : ' COLUMNS'; + $ret .= ' ' . $fields_options_str; + } - return $ret; + $lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true)); + if (trim($lines_options_str) !== '') { + $ret .= ' LINES ' . $lines_options_str; } + + return $ret; } } diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 8e628f0..77d5a3d 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -133,8 +133,8 @@ class OrderKeyword extends Component { if (is_array($component)) { return implode(', ', $component); - } else { - return $component->expr . ' ' . $component->type; } + + return $component->expr . ' ' . $component->type; } } diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php index 1f3c929..721fd97 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -143,15 +143,15 @@ class ParameterDefinition extends Component { if (is_array($component)) { return '(' . implode(', ', $component) . ')'; - } else { - $tmp = ''; - if (!empty($component->inOut)) { - $tmp .= $component->inOut . ' '; - } + } - return trim( - $tmp . Context::escape($component->name) . ' ' . $component->type - ); + $tmp = ''; + if (!empty($component->inOut)) { + $tmp .= $component->inOut . ' '; } + + return trim( + $tmp . Context::escape($component->name) . ' ' . $component->type + ); } } diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 3e3c1d8..59b34cb 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -203,19 +203,18 @@ class PartitionDefinition extends Component { if (is_array($component)) { return "(\n" . implode(",\n", $component) . "\n)"; - } else { - if ($component->isSubpartition) { - return trim('SUBPARTITION ' . $component->name . ' ' . $component->options); - } else { - $subpartitions = empty($component->subpartitions) - ? '' : ' ' . self::build($component->subpartitions); - - return trim( - 'PARTITION ' . $component->name - . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') - . $component->options . $subpartitions - ); - } } + + if ($component->isSubpartition) { + return trim('SUBPARTITION ' . $component->name . ' ' . $component->options); + } + + $subpartitions = empty($component->subpartitions) ? '' : ' ' . self::build($component->subpartitions); + + return trim( + 'PARTITION ' . $component->name + . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') + . $component->options . $subpartitions + ); } } diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php index 8ec8647..6405cb4 100644 --- a/src/Components/RenameOperation.php +++ b/src/Components/RenameOperation.php @@ -163,8 +163,8 @@ class RenameOperation extends Component { if (is_array($component)) { return implode(', ', $component); - } else { - return $component->old . ' TO ' . $component->new; } + + return $component->old . ' TO ' . $component->new; } } diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index 087ff6a..364165a 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -128,8 +128,8 @@ class SetOperation extends Component { if (is_array($component)) { return implode(', ', $component); - } else { - return $component->column . ' = ' . $component->value; } + + return $component->column . ' = ' . $component->value; } } diff --git a/src/Lexer.php b/src/Lexer.php index 627763b..918bdf6 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -391,9 +391,8 @@ class Lexer extends Core if ($lastSpace) { --$j; // The size of the keyword didn't increase. continue; - } else { - $lastSpace = true; } + $lastSpace = true; } else { $lastSpace = false; } @@ -453,9 +452,8 @@ class Lexer extends Core if ($lastSpace) { --$j; // The size of the keyword didn't increase. continue; - } else { - $lastSpace = true; } + $lastSpace = true; } elseif ($this->str[$this->last] === ':') { $token .= $this->str[$this->last]; $ret = new Token($token, Token::TYPE_LABEL); diff --git a/src/Statement.php b/src/Statement.php index e778d36..1e02a02 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -488,9 +488,8 @@ abstract class Statement ); return false; - } else { - $minIdx = $clauseStartIdx; } + $minIdx = $clauseStartIdx; } elseif ($clauseStartIdx != -1) { $minIdx = $clauseStartIdx; } diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index 5628103..4adb039 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -188,15 +188,15 @@ class InsertStatement extends Statement ) { $parser->error('Unexpected keyword.', $token); break; - } else { - ++$list->idx; - $this->into = IntoKeyword::parse( - $parser, - $list, - array('fromInsert' => true) - ); } + ++$list->idx; + $this->into = IntoKeyword::parse( + $parser, + $list, + array('fromInsert' => true) + ); + $state = 1; } elseif ($state === 1) { if ($token->type === Token::TYPE_KEYWORD) { diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index 3fa675a..4396ea2 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -87,8 +87,7 @@ class ReplaceStatement extends Statement */ public function build() { - $ret = 'REPLACE ' . $this->options - . ' INTO ' . $this->into; + $ret = 'REPLACE ' . $this->options . ' INTO ' . $this->into; if ($this->values != null && count($this->values) > 0) { $ret .= ' VALUES ' . Array2d::build($this->values); @@ -115,6 +114,7 @@ class ReplaceStatement extends Statement $list, static::$OPTIONS ); + ++$list->idx; /** @@ -154,14 +154,13 @@ class ReplaceStatement extends Statement ) { $parser->error('Unexpected keyword.', $token); break; - } else { - ++$list->idx; - $this->into = IntoKeyword::parse( - $parser, - $list, - array('fromReplace' => true) - ); } + ++$list->idx; + $this->into = IntoKeyword::parse( + $parser, + $list, + array('fromReplace' => true) + ); $state = 1; } elseif ($state === 1) { |