Skip to content

Commit f845214

Browse files
Fix a few PHP 8 related issues. (#42)
1 parent efb1538 commit f845214

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Processor/Expression/BinaryOperatorEvaluator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,18 @@ public static function evaluate(
226226
case 'MOD':
227227
return \fmod((double) $left_number, (double) $right_number);
228228
case '/':
229+
// Ensure division by 0 cannot occur and 0 divided by anything is also 0
230+
if ($right_number === 0 || $left_number === 0) {
231+
return 0;
232+
}
233+
229234
return $left_number / $right_number;
230235
case 'DIV':
236+
// Ensure division by 0 cannot occur and 0 divided by anything is also 0
237+
if ($right_number === 0 || $left_number === 0) {
238+
return 0;
239+
}
240+
231241
return (int) ($left_number / $right_number);
232242
case '-':
233243
return $left_number - $right_number;

src/Processor/SelectProcessor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function ($expr) {
301301
$parts = \explode(".%.", (string) $col);
302302

303303
if ($expr->tableName() !== null) {
304-
list($col_table_name, $col_name) = $parts;
304+
[$col_table_name, $col_name] = $parts;
305305
if ($col_table_name == $expr->tableName()) {
306306
if (!\array_key_exists($col, $formatted_row)) {
307307
$formatted_row[$col_name] = $val;
@@ -320,11 +320,15 @@ function ($expr) {
320320
continue;
321321
}
322322

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

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

479483
if ($expr_table_name = $expr->tableName()) {
480-
list($column_table_name) = $parts;
484+
[$column_table_name] = $parts;
481485

482486
if ($column_table_name === $expr_table_name) {
483487
$columns[$column_id] = $from_column;

0 commit comments

Comments
 (0)