Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 1, 2021
1 parent 1c9a204 commit 530c180
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/DataIntegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static function coerceValueToColumn(
return (float) $value;

case 'null':
if ($value === nulL) {
if ($value === null) {
return null;
}

Expand Down
9 changes: 8 additions & 1 deletion src/Parser/FromParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,14 @@ private function buildJoin(string $left_table, Token $token)
if ($arg->type !== TokenType::IDENTIFIER) {
throw new ParserException("Expected identifier in USING clause");
}
$filter = self::addJoinFilterExpression($filter, $left_table, $table['name'], $arg->value, $arg->start);

$filter = self::addJoinFilterExpression(
$filter,
$left_table,
$table['name'],
$arg->value,
$arg->start
);
} else {
if ($arg->value !== ',') {
throw new ParserException("Expected , after argument in USING clause");
Expand Down
14 changes: 10 additions & 4 deletions src/Processor/Expression/BinaryOperatorEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ public static function evaluate(
&& \preg_match('/^[0-9]{2,4}-[0-1][0-9]-[0-3][0-9]$/', $r_value)
) {
$r_value .= ' 00:00:00';
} elseif (\preg_match('/^[0-9]{2,4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/', $r_value)
&& \preg_match('/^[0-9]{2,4}-[0-1][0-9]-[0-3][0-9]$/', $l_value)
} elseif (\preg_match(
'/^[0-9]{2,4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/',
$r_value
) && \preg_match('/^[0-9]{2,4}-[0-1][0-9]-[0-3][0-9]$/', $l_value)
) {
$l_value .= ' 00:00:00';
}
Expand All @@ -142,7 +144,8 @@ public static function evaluate(
switch ($expr->operator) {
case '=':
if ($as_string) {
return \strtolower((string) $l_value) === \strtolower((string) $r_value) ? 1 : 0 ^ $expr->negatedInt;
return (\strtolower((string) $l_value) === \strtolower((string) $r_value) ? 1 : 0)
^ $expr->negatedInt;
}

if (empty($l_value) && empty($r_value)) {
Expand All @@ -154,7 +157,8 @@ public static function evaluate(
case '<>':
case '!=':
if ($as_string) {
return \strtolower((string) $l_value) !== \strtolower((string) $r_value) ? 1 : 0 ^ $expr->negatedInt;
return (\strtolower((string) $l_value) !== \strtolower((string) $r_value) ? 1 : 0)
^ $expr->negatedInt;
}

if (empty($l_value) && empty($r_value)) {
Expand Down Expand Up @@ -192,6 +196,8 @@ public static function evaluate(
return (float) $l_value <= (float) $r_value ? 1 : 0 ^ $expr->negatedInt;
}

// PHPCS thinks there's a fallthrough here, but there provably is not

case '*':
case '%':
case 'MOD':
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Expression/Evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static function combineColumnTypes(array $types) : Column
$column = new Column\Varchar(255);
} elseif ($has_floating_point) {
$column = new Column\FloatColumn(10, 2);
} else if ($has_integer) {
} elseif ($has_integer) {
$column = new Column\IntColumn(false, 10);
} else {
$column = new Column\Varchar(255);
Expand Down
2 changes: 0 additions & 2 deletions src/Processor/Expression/ParameterEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ public static function evaluate(Scope $scope, ParameterExpression $expr)
throw new ProcessorException('Parameter offset ' . $expr->parameterName . ' out of range');
}
}


16 changes: 14 additions & 2 deletions src/Processor/JoinProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public static function process(
$left_row = $row;
$candidate_row = \array_merge($row, $r);
if (!$filter
|| ExpressionEvaluator::evaluate($conn, $scope, $filter, $candidate_row, new QueryResult([], $joined_columns))
|| ExpressionEvaluator::evaluate(
$conn,
$scope,
$filter,
$candidate_row,
new QueryResult([], $joined_columns)
)
) {
$rows[] = $candidate_row;
}
Expand Down Expand Up @@ -146,7 +152,13 @@ public static function process(
foreach ($right_result->rows as $r) {
$left_row = $row;
$candidate_row = \array_merge($left_row, $r);
if (ExpressionEvaluator::evaluate($conn, $scope, $filter, $candidate_row, new QueryResult([], $joined_columns))) {
if (ExpressionEvaluator::evaluate(
$conn,
$scope,
$filter,
$candidate_row,
new QueryResult([], $joined_columns)
)) {
$rows[] = $candidate_row;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Processor/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class Scope
{
/**
* @var array<string, mixed>
*/
public $variables = [];
/**
* @var array<string, mixed>
*/
public $variables = [];

/**
* @var array<string, mixed>
Expand Down
15 changes: 13 additions & 2 deletions src/Processor/SelectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,20 @@ private static function getSelectSchema(
}
} else {
if (!isset($existing_columns[$expr->name])) {
$columns[$expr->name] = Expression\Evaluator::getColumnSchema($expr, $scope, $from_columns, $use_cache);
$columns[$expr->name] = Expression\Evaluator::getColumnSchema(
$expr,
$scope,
$from_columns,
$use_cache
);
} elseif ($existing_columns[$expr->name] instanceof Column\NullColumn) {
$columns[$expr->name] = clone Expression\Evaluator::getColumnSchema($expr, $scope, $from_columns, $use_cache);
$columns[$expr->name] = clone Expression\Evaluator::getColumnSchema(
$expr,
$scope,
$from_columns,
$use_cache
);

$columns[$expr->name]->isNullable = true;
}
}
Expand Down
15 changes: 10 additions & 5 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ public function testAssignUndefinedIntToVariable()
$query = $pdo->prepare(
'SELECT @a := `id` as `id`, @b := @a AS `id_copy`
FROM `video_game_characters`
LIMIT 3');
LIMIT 3'
);

$query->execute();

Expand Down Expand Up @@ -563,7 +564,8 @@ public function testSelectHavingCount()
'SELECT `console`
FROM `video_game_characters`
GROUP BY `console`
HAVING COUNT(*) > 2');
HAVING COUNT(*) > 2'
);

$query->execute();

Expand All @@ -584,7 +586,8 @@ public function testSelectHavingOnAliasField()
'SELECT `console`, COUNT(*) as `c`
FROM `video_game_characters`
GROUP BY `console`
HAVING `c` > 2');
HAVING `c` > 2'
);

$query->execute();

Expand Down Expand Up @@ -648,7 +651,8 @@ public function testOrderBySecondDimensionAliased()
'SELECT `id`, `console` AS `console_name`
FROM `video_game_characters`
ORDER BY `console`, `powerups`, `name`
LIMIT 4');
LIMIT 4'
);

$query->execute();

Expand All @@ -671,7 +675,8 @@ public function testOrderByAliasedSecondDimension()
'SELECT `id`, `console` AS `console_name`
FROM `video_game_characters`
ORDER BY `console_name`, `powerups`, `name`
LIMIT 4');
LIMIT 4'
);

$query->execute();

Expand Down

0 comments on commit 530c180

Please sign in to comment.