Skip to content
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: 8 additions & 2 deletions src/core/etl/src/Flow/ETL/Function/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,17 @@ public function asNumber(Row $row, FlowContext $context, int|float|null $default
{
$result = $this->eval($row, $context);

if (\is_string($result)) {
if (!\is_numeric($result)) {
return $default;
}

return \is_numeric($result) ? $result : $default;
return match (true) {
\is_int($result),
\is_float($result) => $result,
($result == (int) $result) => (int) $result,
($result == (float) $result) => (float) $result,
default => $default,
};
}

public function asObject(Row $row, FlowContext $context) : ?object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static function number_data_provider() : \Generator
yield 'zero' => [0, null, 0];
yield 'negative integer' => [-42, null, -42];
yield 'negative float' => [-3.14, null, -3.14];
yield 'integer as string' => ['99', null, 99];
yield 'float as string' => ['99.5', null, 99.5];
yield 'negative integer as string' => ['-42', null, -42];
yield 'negative float as string' => ['-3.14', null, -3.14];
yield 'string with default' => ['not numeric', 99, 99];
yield 'string with float default' => ['not numeric', 99.5, 99.5];
yield 'boolean with default' => [true, 99, 99];
Expand Down
Loading