Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Remove obsolete function_exists('enum_exists') calls #46319

Merged
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
4 changes: 1 addition & 3 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,7 @@ protected function isEnumCastable($key)
return false;
}

if (function_exists('enum_exists') && enum_exists($castType)) {
return true;
}
return enum_exists($castType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ protected function getDictionaryKey($attribute)
return $attribute->__toString();
}

if (function_exists('enum_exists') &&
$attribute instanceof UnitEnum) {
if ($attribute instanceof UnitEnum) {
return $attribute instanceof BackedEnum ? $attribute->value : $attribute->name;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3703,11 +3703,7 @@ public function addBinding($value, $type = 'where')
*/
public function castBinding($value)
{
if (function_exists('enum_exists') && $value instanceof BackedEnum) {
return $value->value;
}

return $value;
return $value instanceof BackedEnum ? $value->value : $value;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ public function date($key, $format = null, $tz = null)
public function enum($key, $enumClass)
{
if ($this->isNotFilled($key) ||
! function_exists('enum_exists') ||
! enum_exists($enumClass) ||
! method_exists($enumClass, 'tryFrom')) {
return null;
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ public function toRoute($route, $parameters, $absolute)
? $value->{$route->bindingFieldFor($key)}
: $value;

return function_exists('enum_exists') && $value instanceof BackedEnum
? $value->value
: $value;
return $value instanceof BackedEnum ? $value->value : $value;
})->all();

return $this->routeUrl()->to(
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function isParameterBackedEnumWithStringBackingType($parameter)
{
$backedEnumClass = (string) $parameter->getType();

if (function_exists('enum_exists') && enum_exists($backedEnumClass)) {
if (enum_exists($backedEnumClass)) {
$reflectionBackedEnum = new ReflectionEnum($backedEnumClass);

return $reflectionBackedEnum->isBacked()
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Rules/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function passes($attribute, $value)
return true;
}

if (is_null($value) || ! function_exists('enum_exists') || ! enum_exists($this->type) || ! method_exists($this->type, 'tryFrom')) {
if (is_null($value) || ! enum_exists($this->type) || ! method_exists($this->type, 'tryFrom')) {
return false;
}

Expand Down