Skip to content

Commit

Permalink
Fix a few PHP 8 related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
MelechMizrachi committed Feb 15, 2024
1 parent efb1538 commit cedc46c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit cedc46c

Please sign in to comment.