Skip to content

Commit 28be60a

Browse files
committed
No useless else
1 parent 677de55 commit 28be60a

15 files changed

Lines changed: 111 additions & 112 deletions

.php_cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ return PhpCsFixer\Config::create()
1414
'array_syntax' => array('syntax' => 'long'),
1515
'concat_space' => array('spacing' => true),
1616
'no_trailing_whitespace' => true,
17+
'no_useless_else' => true,
1718
'phpdoc_order' => true,
1819
))
1920
->setFinder($finder)

src/Components/ArrayObj.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public static function build($component, array $options = array())
182182
return implode(', ', $component);
183183
} elseif (!empty($component->raw)) {
184184
return '(' . implode(', ', $component->raw) . ')';
185-
} else {
186-
return '(' . implode(', ', $component->values) . ')';
187185
}
186+
187+
return '(' . implode(', ', $component->values) . ')';
188188
}
189189
}

src/Components/Condition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ public static function build($component, array $options = array())
220220
{
221221
if (is_array($component)) {
222222
return implode(' ', $component);
223-
} else {
224-
return $component->expr;
225223
}
224+
225+
return $component->expr;
226226
}
227227
}

src/Components/CreateDefinition.php

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
201201
'An opening bracket was expected.',
202202
$token
203203
);
204+
204205
break;
205206
}
207+
206208
} elseif ($state === 1) {
207209
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'CONSTRAINT') {
208210
$expr->isConstraint = true;
@@ -226,11 +228,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
226228
);
227229

228230
return $ret;
229-
} else {
230-
// Non-reserved keywords are allowed without backquotes
231-
$expr->name = $token->value;
232-
$state = 2;
233231
}
232+
233+
// Non-reserved keywords are allowed without backquotes
234+
$expr->name = $token->value;
235+
$state = 2;
234236
} else {
235237
$parser->error(
236238
'A symbol name was expected!',
@@ -239,6 +241,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
239241

240242
return $ret;
241243
}
244+
242245
} elseif ($state === 2) {
243246
$expr->type = DataType::parse($parser, $list);
244247
$state = 3;
@@ -253,6 +256,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
253256
--$list->idx;
254257
}
255258
$state = 5;
259+
256260
} elseif ($state === 5) {
257261
if ((!empty($expr->type)) || (!empty($expr->key))) {
258262
$ret[] = $expr;
@@ -302,35 +306,35 @@ public static function build($component, array $options = array())
302306
{
303307
if (is_array($component)) {
304308
return "(\n " . implode(",\n ", $component) . "\n)";
305-
} else {
306-
$tmp = '';
307-
308-
if ($component->isConstraint) {
309-
$tmp .= 'CONSTRAINT ';
310-
}
309+
}
311310

312-
if ((isset($component->name)) && ($component->name !== '')) {
313-
$tmp .= Context::escape($component->name) . ' ';
314-
}
311+
$tmp = '';
315312

316-
if (!empty($component->type)) {
317-
$tmp .= DataType::build(
318-
$component->type,
319-
array('lowercase' => true)
320-
) . ' ';
321-
}
313+
if ($component->isConstraint) {
314+
$tmp .= 'CONSTRAINT ';
315+
}
322316

323-
if (!empty($component->key)) {
324-
$tmp .= $component->key . ' ';
325-
}
317+
if ((isset($component->name)) && ($component->name !== '')) {
318+
$tmp .= Context::escape($component->name) . ' ';
319+
}
326320

327-
if (!empty($component->references)) {
328-
$tmp .= 'REFERENCES ' . $component->references . ' ';
329-
}
321+
if (!empty($component->type)) {
322+
$tmp .= DataType::build(
323+
$component->type,
324+
array('lowercase' => true)
325+
) . ' ';
326+
}
330327

331-
$tmp .= $component->options;
328+
if (!empty($component->key)) {
329+
$tmp .= $component->key . ' ';
330+
}
332331

333-
return trim($tmp);
332+
if (!empty($component->references)) {
333+
$tmp .= 'REFERENCES ' . $component->references . ' ';
334334
}
335+
336+
$tmp .= $component->options;
337+
338+
return trim($tmp);
335339
}
336340
}

src/Components/Expression.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -418,28 +418,28 @@ public static function build($component, array $options = array())
418418
{
419419
if (is_array($component)) {
420420
return implode($component, ', ');
421+
}
422+
423+
if ($component->expr !== '' && !is_null($component->expr)) {
424+
$ret = $component->expr;
421425
} else {
422-
if ($component->expr !== '' && !is_null($component->expr)) {
423-
$ret = $component->expr;
424-
} else {
425-
$fields = array();
426-
if ((isset($component->database)) && ($component->database !== '')) {
427-
$fields[] = $component->database;
428-
}
429-
if ((isset($component->table)) && ($component->table !== '')) {
430-
$fields[] = $component->table;
431-
}
432-
if ((isset($component->column)) && ($component->column !== '')) {
433-
$fields[] = $component->column;
434-
}
435-
$ret = implode('.', Context::escape($fields));
426+
$fields = array();
427+
if ((isset($component->database)) && ($component->database !== '')) {
428+
$fields[] = $component->database;
436429
}
437-
438-
if (!empty($component->alias)) {
439-
$ret .= ' AS ' . Context::escape($component->alias);
430+
if ((isset($component->table)) && ($component->table !== '')) {
431+
$fields[] = $component->table;
432+
}
433+
if ((isset($component->column)) && ($component->column !== '')) {
434+
$fields[] = $component->column;
440435
}
436+
$ret = implode('.', Context::escape($fields));
437+
}
441438

442-
return $ret;
439+
if (!empty($component->alias)) {
440+
$ret .= ' AS ' . Context::escape($component->alias);
443441
}
442+
443+
return $ret;
444444
}
445445
}

src/Components/IntoKeyword.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,26 @@ public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'F
235235
public static function build($component, array $options = array())
236236
{
237237
if ($component->dest instanceof Expression) {
238-
$columns = !empty($component->columns) ?
239-
'(`' . implode('`, `', $component->columns) . '`)' : '';
238+
$columns = !empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : '';
240239

241240
return $component->dest . $columns;
242241
} elseif (isset($component->values)) {
243242
return ExpressionArray::build($component->values);
244-
} else {
245-
$ret = 'OUTFILE "' . $component->dest . '"';
243+
}
246244

247-
$fields_options_str = OptionsArray::build($component->fields_options);
248-
if (trim($fields_options_str) !== '') {
249-
$ret .= ($component->fields_keyword) ? ' FIELDS' : ' COLUMNS';
250-
$ret .= ' ' . $fields_options_str;
251-
}
245+
$ret = 'OUTFILE "' . $component->dest . '"';
252246

253-
$lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true));
254-
if (trim($lines_options_str) !== '') {
255-
$ret .= ' LINES ' . $lines_options_str;
256-
}
247+
$fields_options_str = OptionsArray::build($component->fields_options);
248+
if (trim($fields_options_str) !== '') {
249+
$ret .= ($component->fields_keyword) ? ' FIELDS' : ' COLUMNS';
250+
$ret .= ' ' . $fields_options_str;
251+
}
257252

258-
return $ret;
253+
$lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true));
254+
if (trim($lines_options_str) !== '') {
255+
$ret .= ' LINES ' . $lines_options_str;
259256
}
257+
258+
return $ret;
260259
}
261260
}

src/Components/OrderKeyword.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public static function build($component, array $options = array())
133133
{
134134
if (is_array($component)) {
135135
return implode(', ', $component);
136-
} else {
137-
return $component->expr . ' ' . $component->type;
138136
}
137+
138+
return $component->expr . ' ' . $component->type;
139139
}
140140
}

src/Components/ParameterDefinition.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ public static function build($component, array $options = array())
143143
{
144144
if (is_array($component)) {
145145
return '(' . implode(', ', $component) . ')';
146-
} else {
147-
$tmp = '';
148-
if (!empty($component->inOut)) {
149-
$tmp .= $component->inOut . ' ';
150-
}
146+
}
151147

152-
return trim(
153-
$tmp . Context::escape($component->name) . ' ' . $component->type
154-
);
148+
$tmp = '';
149+
if (!empty($component->inOut)) {
150+
$tmp .= $component->inOut . ' ';
155151
}
152+
153+
return trim(
154+
$tmp . Context::escape($component->name) . ' ' . $component->type
155+
);
156156
}
157157
}

src/Components/PartitionDefinition.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,18 @@ public static function build($component, array $options = array())
203203
{
204204
if (is_array($component)) {
205205
return "(\n" . implode(",\n", $component) . "\n)";
206-
} else {
207-
if ($component->isSubpartition) {
208-
return trim('SUBPARTITION ' . $component->name . ' ' . $component->options);
209-
} else {
210-
$subpartitions = empty($component->subpartitions)
211-
? '' : ' ' . self::build($component->subpartitions);
212-
213-
return trim(
214-
'PARTITION ' . $component->name
215-
. (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ')
216-
. $component->options . $subpartitions
217-
);
218-
}
219206
}
207+
208+
if ($component->isSubpartition) {
209+
return trim('SUBPARTITION ' . $component->name . ' ' . $component->options);
210+
}
211+
212+
$subpartitions = empty($component->subpartitions) ? '' : ' ' . self::build($component->subpartitions);
213+
214+
return trim(
215+
'PARTITION ' . $component->name
216+
. (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ')
217+
. $component->options . $subpartitions
218+
);
220219
}
221220
}

src/Components/RenameOperation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ public static function build($component, array $options = array())
163163
{
164164
if (is_array($component)) {
165165
return implode(', ', $component);
166-
} else {
167-
return $component->old . ' TO ' . $component->new;
168166
}
167+
168+
return $component->old . ' TO ' . $component->new;
169169
}
170170
}

0 commit comments

Comments
 (0)