Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 30, 2021
1 parent bfb8759 commit 7aa564c
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 88 deletions.
2 changes: 0 additions & 2 deletions src/FakePdoStatementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ function ($row) {
},
$this->result ?: []
);

return $this->result ?: [];
}

if ($fetch_style === \PDO::FETCH_NUM) {
Expand Down
10 changes: 3 additions & 7 deletions src/Parser/CreateTableParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function lexImpl(string $sql)
}
continue;
}
$match = \preg_match('!(\d+\.?\d*|\.\d+)!A', $sql, $matches, 0, $pos);
\preg_match('!(\d+\.?\d*|\.\d+)!A', $sql, $matches, 0, $pos);
if ($matches) {
$source_map[] = [$pos, \strlen($matches[0])];
$pos += \strlen($matches[0]);
Expand Down Expand Up @@ -159,7 +159,7 @@ private static function walk(array $tokens, string $sql, array $source_map)
$temp = [];
$start = 0;

foreach ($tokens as $i => $t) {
foreach ($tokens as $i => $_t) {
$t = $tokens[$i];
if ($t === ';') {
if (\count($temp)) {
Expand Down Expand Up @@ -293,12 +293,8 @@ private static function parseCreateDefinition(array &$tokens)
*/
private static function parseFieldOrKey(array &$tokens, array &$fields, array &$indexes)
{
$has_constraint = false;
$constraint = null;

if ($tokens[0] === 'CONSTRAINT') {
$has_constraint = true;

if ($tokens[1] === 'PRIMARY KEY'
|| $tokens[1] === 'UNIQUE'
|| $tokens[1] === 'UNIQUE KEY'
Expand All @@ -308,7 +304,7 @@ private static function parseFieldOrKey(array &$tokens, array &$fields, array &$
\array_shift($tokens);
} else {
\array_shift($tokens);
$constraint = \array_shift($tokens);
\array_shift($tokens);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Parser/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ function ($token) {
public function build()
{
$token = $this->nextToken();
$break_while = false;
while ($token !== null) {
switch ($token->type) {
case TokenType::PAREN:
Expand All @@ -303,7 +302,6 @@ public function build()
}

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

if ($arg_tokens[0]->value === 'SELECT') {
$subquery_sql = \implode(
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/FromParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function getSubquery()
throw new ParserException("Empty parentheses found");
}
$this->pointer = $close;
$expr = new StubExpression();

$subquery_sql = \implode(
' ',
\array_map(
Expand Down
4 changes: 1 addition & 3 deletions src/Parser/InsertParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function parse()
$query = new InsertQuery($token->value, $this->sql, $ignore_dupes);
$count = \count($this->tokens);
$needs_comma = false;
$end_of_set = false;

while ($this->pointer < $count) {
$token = $this->tokens[$this->pointer];
Expand Down Expand Up @@ -221,7 +220,6 @@ protected function parseValues(array $tokens)
$count = \count($tokens);
$expressions = [];
$needs_comma = false;
$end_of_set = false;
while ($pointer < $count) {
$token = $tokens[$pointer];
switch ($token->type) {
Expand All @@ -238,7 +236,7 @@ protected function parseValues(array $tokens)
);
}
$expression_parser = new ExpressionParser($tokens, $pointer - 1);
$start = $pointer;

list($pointer, $expression) = $expression_parser->buildWithPointer();
$expressions[] = $expression;
$needs_comma = true;
Expand Down
2 changes: 0 additions & 2 deletions src/Parser/SQLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ public static function findMatchingParen(int $pointer, array $tokens)
{
$paren_count = 0;
$remaining_tokens = \array_slice($tokens, $pointer);
$token_count = \count($remaining_tokens);
foreach ($remaining_tokens as $i => $token) {
if ($token->type === TokenType::PAREN) {
$paren_count++;
Expand All @@ -425,7 +424,6 @@ public static function findMatchingEnd(int $pointer, array $tokens)
{
$paren_count = 0;
$remaining_tokens = \array_slice($tokens, $pointer);
$token_count = \count($remaining_tokens);
foreach ($remaining_tokens as $i => $token) {
if ($token->type === TokenType::OPERATOR
&& $token->value === 'CASE'
Expand Down
5 changes: 2 additions & 3 deletions src/Parser/SelectParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function parse() : SelectQuery

if (\array_key_exists($this->pointer, $this->tokens)) {
$next = $this->tokens[$this->pointer] ?? null;
$val = $next ? $next->value : 'null';
while ($next !== null
&& ($next->value === 'UNION' || $next->value === 'INTERSECT' || $next->value === 'EXCEPT')
) {
Expand Down Expand Up @@ -180,7 +179,7 @@ private function parseMainSelect() : SelectQuery
$this->pointer++;
$next = $this->tokens[$this->pointer] ?? null;
$expressions = [];
$sort_directions = [];

if ($next === null || $next->value !== 'BY') {
throw new ParserException("Expected BY after GROUP");
}
Expand Down Expand Up @@ -224,7 +223,7 @@ private function parseMainSelect() : SelectQuery
case 'EXCEPT':
case 'INTERSECT':
return $query;
break;

default:
throw new ParserException("Unexpected {$token->value}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/SetParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function parse(bool $skip_set = false)
throw new ParserException("Expected , between expressions in SET clause");
}
$expression_parser = new ExpressionParser($this->tokens, $this->pointer - 1);
$start = $this->pointer;

list($this->pointer, $expression) = $expression_parser->buildWithPointer();

if (!$expression instanceof BinaryOperatorExpression || $expression->operator !== '=') {
Expand Down
4 changes: 0 additions & 4 deletions src/Processor/Expression/BinaryOperatorEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public static function evaluate(
throw new ProcessorException("Operator recognized but not implemented");

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

$left_string = (string) Evaluator::evaluate($conn, $scope, $left, $row, $result);
Expand Down Expand Up @@ -356,8 +355,6 @@ public static function getColumnSchema(
if ($right instanceof IntervalOperatorExpression
&& ($expr->operator === '+' || $expr->operator === '-')
) {
$functionName = $expr->operator === '+' ? 'DATE_ADD' : 'DATE_SUB';

return new Column\DateTime();
}

Expand Down Expand Up @@ -486,7 +483,6 @@ private static function evaluateRowComparison(
throw new ProcessorException("Mismatched column count in row comparison expression");
}
$last_index = \array_key_last($left_elems);
$match = true;
foreach ($left_elems as $index => $le) {
$re = $right_elems[$index];
if ($le == $re && $index !== $last_index) {
Expand Down
1 change: 0 additions & 1 deletion src/Processor/Expression/Evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public static function combineColumnTypes(array $types) : Column
$has_floating_point = false;
$has_integer = false;
$has_string = false;
$has_date = false;

$non_null_types = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Expression/FunctionEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ private static function sqlConcat(
}

$final_concat = "";
foreach ($args as $k => $arg) {
foreach ($args as $arg) {
$val = (string) Evaluator::evaluate($conn, $scope, $arg, $row, $result);
$final_concat .= $val;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Processor/FromProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public static function process(
Scope $scope,
FromClause $stmt
) : QueryResult {
$is_first_table = true;
$left_column_list = [];

$result = null;

Expand Down
4 changes: 1 addition & 3 deletions src/Processor/InsertProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public static function process(

$rows_affected = 0;

$row = [];

$last_insert_id = null;

$conn->setLastInsertId("0");

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

if ($stmt->setClause) {
list($set_rows_affected) = self::applySet(
list($rows_affected) = self::applySet(
$conn,
$scope,
$database,
Expand Down
41 changes: 3 additions & 38 deletions src/Processor/JoinProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static function process(

foreach ($left_result->rows as $row) {
foreach ($right_result->rows as $r) {
$left_row = $row;
$candidate_row = \array_merge($row, $r);
if (!$filter
|| ExpressionEvaluator::evaluate(
Expand Down Expand Up @@ -95,41 +94,7 @@ public static function process(
break;

case JoinType::RIGHT:
$null_placeholder = [];

foreach ($right_result->columns as $name => $_) {
$parts = explode('.%.', $name);
$null_placeholder[$right_table_name . '.%.' . end($parts)] = null;
}

$joined_columns = array_merge($left_result->columns, $right_result->columns);

foreach ($right_result->rows as $raw) {
$any_match = false;

foreach ($left_result->rows as $row) {
$left_row = $row;
$candidate_row = \array_merge($left_row, $raw);

if (!$filter
|| ExpressionEvaluator::evaluate(
$conn,
$scope,
$filter,
$candidate_row,
new QueryResult([], $joined_columns)
)
) {
$rows[] = $candidate_row;
$any_match = true;
}
}

if (!$any_match) {
$rows[] = $raw;
}
}
break;
throw new \Exception('Right joins are currently unsupported');

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

foreach ($left as $column => $val) {
foreach ($left as $column => $_val) {
$name_parts = \explode('.%.', $column);
$name = end($name_parts);
foreach ($right as $col => $v) {
foreach ($right as $col => $_v) {
$col_parts = \explode('.%.', $col);
$colname = end($col_parts);
if ($colname === $name) {
Expand Down
3 changes: 1 addition & 2 deletions src/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function ($a, $b) use ($sort_fun) {
);

$rows = [];
foreach ($rows_temp as $index => $item) {
foreach ($rows_temp as $item) {
$rows[$item[0]] = $item[1];
}

Expand Down Expand Up @@ -231,7 +231,6 @@ protected static function applySet(
}
}
} else {
$changes_found = true;
$row = [];

foreach ($set_clauses as $clause) {
Expand Down
16 changes: 4 additions & 12 deletions src/Processor/SelectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected static function applyHaving(

$out_groups = [];

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

$first_row = reset($rows);
Expand Down Expand Up @@ -279,7 +279,7 @@ function ($expr) {

$have_reevaluated_columns = false;

foreach ($grouped_rows as $group_id => $rows) {
foreach ($grouped_rows as $rows) {
$group_result = $result->grouped_rows !== null
? new QueryResult($rows, $result->columns)
: $result;
Expand Down Expand Up @@ -392,20 +392,12 @@ function ($expr) {
}

$out[$i][$name] = $val;

if ($expr->hasAggregate()) {
$found_aggregate = true;
}
}
}

$i = 0;

foreach ($grouped_rows as $group_id => $rows) {
$group_result = $result->grouped_rows !== null
? new QueryResult($rows, $result->columns)
: $result;

foreach ($grouped_rows as $rows) {
foreach ($rows as $row) {
$found_aggregate = false;

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

if ($expr_table_name = $expr->tableName()) {
list($column_table_name, $column_name) = $parts;
list($column_table_name) = $parts;

if ($column_table_name === $expr_table_name) {
$columns[$column_id] = $from_column;
Expand Down
2 changes: 0 additions & 2 deletions src/Processor/UpdateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public static function process(
) : int {
list($table_name, $database) = self::processUpdateClause($conn, $stmt);

$table_definition = $conn->getServer()->getTableDefinition($database, $table_name);

$existing_rows = $conn->getServer()->getTable($database, $table_name) ?: [];

//Metrics::trackQuery(QueryType::UPDATE, $conn->getServer()->name, $table_name, $this->sql);
Expand Down
1 change: 0 additions & 1 deletion src/Schema/Column/CharacterColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function getPhpCode() : string
if ($this->getDefault() === null) {
$default = '->setDefault(null)';
} else {
$use_quotes = $this->getPhpType() === 'string';
$default = '->setDefault(\'' . $this->getDefault() . '\')';
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CreateTableParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function testSimpleParse()
$new_table = eval('return ' . $new_table_php_code . ';');

$this->assertSame(\var_export($table, true), \var_export($new_table, true));
}
}
}
}

0 comments on commit 7aa564c

Please sign in to comment.