Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few PHP 8 related issues #42

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Processor/Expression/BinaryOperatorEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,18 @@ public static function evaluate(
case 'MOD':
return \fmod((double) $left_number, (double) $right_number);
case '/':
// Ensure division by 0 cannot occur and 0 divided by anything is also 0
if ($right_number === 0 || $left_number === 0) {
return 0;
}

return $left_number / $right_number;
case 'DIV':
// Ensure division by 0 cannot occur and 0 divided by anything is also 0
if ($right_number === 0 || $left_number === 0) {
return 0;
}

return (int) ($left_number / $right_number);
case '-':
return $left_number - $right_number;
Expand Down
12 changes: 8 additions & 4 deletions src/Processor/SelectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function ($expr) {
$parts = \explode(".%.", (string) $col);

if ($expr->tableName() !== null) {
list($col_table_name, $col_name) = $parts;
[$col_table_name, $col_name] = $parts;
if ($col_table_name == $expr->tableName()) {
if (!\array_key_exists($col, $formatted_row)) {
$formatted_row[$col_name] = $val;
Expand All @@ -320,11 +320,15 @@ function ($expr) {
continue;
}

/**
* Evaluator case \Vimeo\MysqlEngine\Query\Expression\SubqueryExpression::class:
* should ensure the value of $val is never an array, and only the value of the
* column requested, but we'll leave this code just to make sure of that.
*/
$val = Expression\Evaluator::evaluate($conn, $scope, $expr, $row, $group_result);
$name = $expr->name;

if ($expr instanceof SubqueryExpression) {
assert(\is_array($val), 'subquery results must be KeyedContainer');
if ($expr instanceof SubqueryExpression && \is_array($val)) {
if (\count($val) > 1) {
throw new ProcessorException("Subquery returned more than one row");
}
Expand Down Expand Up @@ -477,7 +481,7 @@ private static function getSelectSchema(
$parts = \explode(".", $column_id);

if ($expr_table_name = $expr->tableName()) {
list($column_table_name) = $parts;
[$column_table_name] = $parts;

if ($column_table_name === $expr_table_name) {
$columns[$column_id] = $from_column;
Expand Down
Loading