BaseEnumRoutable : case to int only if is really an integer

This commit is contained in:
Jérémy Munsch 2021-09-11 22:44:54 +02:00
parent 4cc27e6769
commit b3f54a65c5
No known key found for this signature in database
GPG key ID: 677E1F9F80C16560

View file

@ -46,7 +46,10 @@ abstract class BaseEnumRoutable extends BaseEnum implements UrlRoutable
{
// try to cast numeric value first
try {
return static::make(is_numeric($value) ? intval($value) : $value);
// try cast to int
$iValue = (is_numeric($value) and floatval(intval($value)) === floatval($value)) ?
(int)$value : $value;
return static::make($iValue);
} catch (BadMethodCallException $e) {
// try string value after that
try {