Skip to content

Commit

Permalink
fix return types for enums (#57)
Browse files Browse the repository at this point in the history
* Add MixedValueToScalarConverter for fixing a problem with SQL binding of non-scalar values such as enums

* fix return types

---------

Co-authored-by: korotkov <korotkov@mubert.com>
  • Loading branch information
Miteugene and korotkov authored Jul 1, 2024
1 parent a921c98 commit 621f8aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Converters/MixedValueToScalarConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

class MixedValueToScalarConverter
{
public function handle(mixed $value): int|float|bool|string
public function handle(mixed $value): int|float|bool|string|null
{
if (is_scalar($value) || $value === null) {
return $value;
} elseif (is_object($value) && PHP_VERSION_ID >= 80100 && enum_exists(get_class($value))) {
return $value->value;
} elseif (is_object($value) && method_exists($value, '__toString')) {
$value->__toString();
} else {
throw new BulkValueTypeIsNotSupported($value);
}

throw new BulkValueTypeIsNotSupported($value);
}
}

0 comments on commit 621f8aa

Please sign in to comment.