Skip to content

Commit 7aa564c

Browse files
committed
Remove unused code
1 parent bfb8759 commit 7aa564c

19 files changed

+19
-88
lines changed

src/FakePdoStatementTrait.php

-2
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ function ($row) {
405405
},
406406
$this->result ?: []
407407
);
408-
409-
return $this->result ?: [];
410408
}
411409

412410
if ($fetch_style === \PDO::FETCH_NUM) {

src/Parser/CreateTableParser.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function lexImpl(string $sql)
117117
}
118118
continue;
119119
}
120-
$match = \preg_match('!(\d+\.?\d*|\.\d+)!A', $sql, $matches, 0, $pos);
120+
\preg_match('!(\d+\.?\d*|\.\d+)!A', $sql, $matches, 0, $pos);
121121
if ($matches) {
122122
$source_map[] = [$pos, \strlen($matches[0])];
123123
$pos += \strlen($matches[0]);
@@ -159,7 +159,7 @@ private static function walk(array $tokens, string $sql, array $source_map)
159159
$temp = [];
160160
$start = 0;
161161

162-
foreach ($tokens as $i => $t) {
162+
foreach ($tokens as $i => $_t) {
163163
$t = $tokens[$i];
164164
if ($t === ';') {
165165
if (\count($temp)) {
@@ -293,12 +293,8 @@ private static function parseCreateDefinition(array &$tokens)
293293
*/
294294
private static function parseFieldOrKey(array &$tokens, array &$fields, array &$indexes)
295295
{
296-
$has_constraint = false;
297-
$constraint = null;
298296

299297
if ($tokens[0] === 'CONSTRAINT') {
300-
$has_constraint = true;
301-
302298
if ($tokens[1] === 'PRIMARY KEY'
303299
|| $tokens[1] === 'UNIQUE'
304300
|| $tokens[1] === 'UNIQUE KEY'
@@ -308,7 +304,7 @@ private static function parseFieldOrKey(array &$tokens, array &$fields, array &$
308304
\array_shift($tokens);
309305
} else {
310306
\array_shift($tokens);
311-
$constraint = \array_shift($tokens);
307+
\array_shift($tokens);
312308
}
313309
}
314310

src/Parser/ExpressionParser.php

-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ function ($token) {
291291
public function build()
292292
{
293293
$token = $this->nextToken();
294-
$break_while = false;
295294
while ($token !== null) {
296295
switch ($token->type) {
297296
case TokenType::PAREN:
@@ -303,7 +302,6 @@ public function build()
303302
}
304303

305304
$this->pointer = $close;
306-
$expr = new StubExpression();
307305

308306
if ($arg_tokens[0]->value === 'SELECT') {
309307
$subquery_sql = \implode(

src/Parser/FromParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function getSubquery()
185185
throw new ParserException("Empty parentheses found");
186186
}
187187
$this->pointer = $close;
188-
$expr = new StubExpression();
188+
189189
$subquery_sql = \implode(
190190
' ',
191191
\array_map(

src/Parser/InsertParser.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function parse()
7777
$query = new InsertQuery($token->value, $this->sql, $ignore_dupes);
7878
$count = \count($this->tokens);
7979
$needs_comma = false;
80-
$end_of_set = false;
8180

8281
while ($this->pointer < $count) {
8382
$token = $this->tokens[$this->pointer];
@@ -221,7 +220,6 @@ protected function parseValues(array $tokens)
221220
$count = \count($tokens);
222221
$expressions = [];
223222
$needs_comma = false;
224-
$end_of_set = false;
225223
while ($pointer < $count) {
226224
$token = $tokens[$pointer];
227225
switch ($token->type) {
@@ -238,7 +236,7 @@ protected function parseValues(array $tokens)
238236
);
239237
}
240238
$expression_parser = new ExpressionParser($tokens, $pointer - 1);
241-
$start = $pointer;
239+
242240
list($pointer, $expression) = $expression_parser->buildWithPointer();
243241
$expressions[] = $expression;
244242
$needs_comma = true;

src/Parser/SQLParser.php

-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ public static function findMatchingParen(int $pointer, array $tokens)
400400
{
401401
$paren_count = 0;
402402
$remaining_tokens = \array_slice($tokens, $pointer);
403-
$token_count = \count($remaining_tokens);
404403
foreach ($remaining_tokens as $i => $token) {
405404
if ($token->type === TokenType::PAREN) {
406405
$paren_count++;
@@ -425,7 +424,6 @@ public static function findMatchingEnd(int $pointer, array $tokens)
425424
{
426425
$paren_count = 0;
427426
$remaining_tokens = \array_slice($tokens, $pointer);
428-
$token_count = \count($remaining_tokens);
429427
foreach ($remaining_tokens as $i => $token) {
430428
if ($token->type === TokenType::OPERATOR
431429
&& $token->value === 'CASE'

src/Parser/SelectParser.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function parse() : SelectQuery
7171

7272
if (\array_key_exists($this->pointer, $this->tokens)) {
7373
$next = $this->tokens[$this->pointer] ?? null;
74-
$val = $next ? $next->value : 'null';
7574
while ($next !== null
7675
&& ($next->value === 'UNION' || $next->value === 'INTERSECT' || $next->value === 'EXCEPT')
7776
) {
@@ -180,7 +179,7 @@ private function parseMainSelect() : SelectQuery
180179
$this->pointer++;
181180
$next = $this->tokens[$this->pointer] ?? null;
182181
$expressions = [];
183-
$sort_directions = [];
182+
184183
if ($next === null || $next->value !== 'BY') {
185184
throw new ParserException("Expected BY after GROUP");
186185
}
@@ -224,7 +223,7 @@ private function parseMainSelect() : SelectQuery
224223
case 'EXCEPT':
225224
case 'INTERSECT':
226225
return $query;
227-
break;
226+
228227
default:
229228
throw new ParserException("Unexpected {$token->value}");
230229
}

src/Parser/SetParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function parse(bool $skip_set = false)
5858
throw new ParserException("Expected , between expressions in SET clause");
5959
}
6060
$expression_parser = new ExpressionParser($this->tokens, $this->pointer - 1);
61-
$start = $this->pointer;
61+
6262
list($this->pointer, $expression) = $expression_parser->buildWithPointer();
6363

6464
if (!$expression instanceof BinaryOperatorExpression || $expression->operator !== '=') {

src/Processor/Expression/BinaryOperatorEvaluator.php

-4
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ public static function evaluate(
246246
throw new ProcessorException("Operator recognized but not implemented");
247247

248248
case 'LIKE':
249-
$l_value = Evaluator::evaluate($conn, $scope, $left, $row, $result);
250249
$r_value = Evaluator::evaluate($conn, $scope, $right, $row, $result);
251250

252251
$left_string = (string) Evaluator::evaluate($conn, $scope, $left, $row, $result);
@@ -356,8 +355,6 @@ public static function getColumnSchema(
356355
if ($right instanceof IntervalOperatorExpression
357356
&& ($expr->operator === '+' || $expr->operator === '-')
358357
) {
359-
$functionName = $expr->operator === '+' ? 'DATE_ADD' : 'DATE_SUB';
360-
361358
return new Column\DateTime();
362359
}
363360

@@ -486,7 +483,6 @@ private static function evaluateRowComparison(
486483
throw new ProcessorException("Mismatched column count in row comparison expression");
487484
}
488485
$last_index = \array_key_last($left_elems);
489-
$match = true;
490486
foreach ($left_elems as $index => $le) {
491487
$re = $right_elems[$index];
492488
if ($le == $re && $index !== $last_index) {

src/Processor/Expression/Evaluator.php

-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ public static function combineColumnTypes(array $types) : Column
306306
$has_floating_point = false;
307307
$has_integer = false;
308308
$has_string = false;
309-
$has_date = false;
310309

311310
$non_null_types = [];
312311

src/Processor/Expression/FunctionEvaluator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ private static function sqlConcat(
833833
}
834834

835835
$final_concat = "";
836-
foreach ($args as $k => $arg) {
836+
foreach ($args as $arg) {
837837
$val = (string) Evaluator::evaluate($conn, $scope, $arg, $row, $result);
838838
$final_concat .= $val;
839839
}

src/Processor/FromProcessor.php

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public static function process(
1111
Scope $scope,
1212
FromClause $stmt
1313
) : QueryResult {
14-
$is_first_table = true;
15-
$left_column_list = [];
1614

1715
$result = null;
1816

src/Processor/InsertProcessor.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ public static function process(
2525

2626
$rows_affected = 0;
2727

28-
$row = [];
2928

30-
$last_insert_id = null;
3129

3230
$conn->setLastInsertId("0");
3331

@@ -98,7 +96,7 @@ public static function process(
9896
$conn->getServer()->saveTable($database, $table_name, $table);
9997

10098
if ($stmt->setClause) {
101-
list($set_rows_affected) = self::applySet(
99+
list($rows_affected) = self::applySet(
102100
$conn,
103101
$scope,
104102
$database,

src/Processor/JoinProcessor.php

+3-38
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static function process(
3939

4040
foreach ($left_result->rows as $row) {
4141
foreach ($right_result->rows as $r) {
42-
$left_row = $row;
4342
$candidate_row = \array_merge($row, $r);
4443
if (!$filter
4544
|| ExpressionEvaluator::evaluate(
@@ -95,41 +94,7 @@ public static function process(
9594
break;
9695

9796
case JoinType::RIGHT:
98-
$null_placeholder = [];
99-
100-
foreach ($right_result->columns as $name => $_) {
101-
$parts = explode('.%.', $name);
102-
$null_placeholder[$right_table_name . '.%.' . end($parts)] = null;
103-
}
104-
105-
$joined_columns = array_merge($left_result->columns, $right_result->columns);
106-
107-
foreach ($right_result->rows as $raw) {
108-
$any_match = false;
109-
110-
foreach ($left_result->rows as $row) {
111-
$left_row = $row;
112-
$candidate_row = \array_merge($left_row, $raw);
113-
114-
if (!$filter
115-
|| ExpressionEvaluator::evaluate(
116-
$conn,
117-
$scope,
118-
$filter,
119-
$candidate_row,
120-
new QueryResult([], $joined_columns)
121-
)
122-
) {
123-
$rows[] = $candidate_row;
124-
$any_match = true;
125-
}
126-
}
127-
128-
if (!$any_match) {
129-
$rows[] = $raw;
130-
}
131-
}
132-
break;
97+
throw new \Exception('Right joins are currently unsupported');
13398

13499
case JoinType::CROSS:
135100
$joined_columns = array_merge($left_result->columns, $right_result->columns);
@@ -185,10 +150,10 @@ protected static function buildNaturalJoinFilter(array $left_dataset, array $rig
185150
throw new ParserException("Attempted NATURAL join with no data present");
186151
}
187152

188-
foreach ($left as $column => $val) {
153+
foreach ($left as $column => $_val) {
189154
$name_parts = \explode('.%.', $column);
190155
$name = end($name_parts);
191-
foreach ($right as $col => $v) {
156+
foreach ($right as $col => $_v) {
192157
$col_parts = \explode('.%.', $col);
193158
$colname = end($col_parts);
194159
if ($colname === $name) {

src/Processor/Processor.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function ($a, $b) use ($sort_fun) {
9393
);
9494

9595
$rows = [];
96-
foreach ($rows_temp as $index => $item) {
96+
foreach ($rows_temp as $item) {
9797
$rows[$item[0]] = $item[1];
9898
}
9999

@@ -231,7 +231,6 @@ protected static function applySet(
231231
}
232232
}
233233
} else {
234-
$changes_found = true;
235234
$row = [];
236235

237236
foreach ($set_clauses as $clause) {

src/Processor/SelectProcessor.php

+4-12
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected static function applyHaving(
204204

205205
$out_groups = [];
206206

207-
foreach ($result->grouped_rows as $group_id => $rows) {
207+
foreach ($result->grouped_rows as $rows) {
208208
$group_result = new QueryResult($rows, $result->columns);
209209

210210
$first_row = reset($rows);
@@ -279,7 +279,7 @@ function ($expr) {
279279

280280
$have_reevaluated_columns = false;
281281

282-
foreach ($grouped_rows as $group_id => $rows) {
282+
foreach ($grouped_rows as $rows) {
283283
$group_result = $result->grouped_rows !== null
284284
? new QueryResult($rows, $result->columns)
285285
: $result;
@@ -392,20 +392,12 @@ function ($expr) {
392392
}
393393

394394
$out[$i][$name] = $val;
395-
396-
if ($expr->hasAggregate()) {
397-
$found_aggregate = true;
398-
}
399395
}
400396
}
401397

402398
$i = 0;
403399

404-
foreach ($grouped_rows as $group_id => $rows) {
405-
$group_result = $result->grouped_rows !== null
406-
? new QueryResult($rows, $result->columns)
407-
: $result;
408-
400+
foreach ($grouped_rows as $rows) {
409401
foreach ($rows as $row) {
410402
$found_aggregate = false;
411403

@@ -485,7 +477,7 @@ private static function getSelectSchema(
485477
$parts = \explode(".", $column_id);
486478

487479
if ($expr_table_name = $expr->tableName()) {
488-
list($column_table_name, $column_name) = $parts;
480+
list($column_table_name) = $parts;
489481

490482
if ($column_table_name === $expr_table_name) {
491483
$columns[$column_id] = $from_column;

src/Processor/UpdateProcessor.php

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public static function process(
1010
) : int {
1111
list($table_name, $database) = self::processUpdateClause($conn, $stmt);
1212

13-
$table_definition = $conn->getServer()->getTableDefinition($database, $table_name);
14-
1513
$existing_rows = $conn->getServer()->getTable($database, $table_name) ?: [];
1614

1715
//Metrics::trackQuery(QueryType::UPDATE, $conn->getServer()->name, $table_name, $this->sql);

src/Schema/Column/CharacterColumn.php

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function getPhpCode() : string
6363
if ($this->getDefault() === null) {
6464
$default = '->setDefault(null)';
6565
} else {
66-
$use_quotes = $this->getPhpType() === 'string';
6766
$default = '->setDefault(\'' . $this->getDefault() . '\')';
6867
}
6968
}

tests/CreateTableParseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public function testSimpleParse()
2727
$new_table = eval('return ' . $new_table_php_code . ';');
2828

2929
$this->assertSame(\var_export($table, true), \var_export($new_table, true));
30-
}
30+
}
3131
}
3232
}

0 commit comments

Comments
 (0)