Skip to content

Commit 664f095

Browse files
authored
Remove obsolete function_exists('enum_exists') calls (#46319)
1 parent d10c6df commit 664f095

File tree

7 files changed

+6
-16
lines changed

7 files changed

+6
-16
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,7 @@ protected function isEnumCastable($key)
15921592
return false;
15931593
}
15941594

1595-
if (function_exists('enum_exists') && enum_exists($castType)) {
1596-
return true;
1597-
}
1595+
return enum_exists($castType);
15981596
}
15991597

16001598
/**

src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithDictionary.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ protected function getDictionaryKey($attribute)
2323
return $attribute->__toString();
2424
}
2525

26-
if (function_exists('enum_exists') &&
27-
$attribute instanceof UnitEnum) {
26+
if ($attribute instanceof UnitEnum) {
2827
return $attribute instanceof BackedEnum ? $attribute->value : $attribute->name;
2928
}
3029

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,11 +3703,7 @@ public function addBinding($value, $type = 'where')
37033703
*/
37043704
public function castBinding($value)
37053705
{
3706-
if (function_exists('enum_exists') && $value instanceof BackedEnum) {
3707-
return $value->value;
3708-
}
3709-
3710-
return $value;
3706+
return $value instanceof BackedEnum ? $value->value : $value;
37113707
}
37123708

37133709
/**

src/Illuminate/Http/Concerns/InteractsWithInput.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ public function date($key, $format = null, $tz = null)
402402
public function enum($key, $enumClass)
403403
{
404404
if ($this->isNotFilled($key) ||
405-
! function_exists('enum_exists') ||
406405
! enum_exists($enumClass) ||
407406
! method_exists($enumClass, 'tryFrom')) {
408407
return null;

src/Illuminate/Routing/UrlGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ public function toRoute($route, $parameters, $absolute)
484484
? $value->{$route->bindingFieldFor($key)}
485485
: $value;
486486

487-
return function_exists('enum_exists') && $value instanceof BackedEnum
488-
? $value->value
489-
: $value;
487+
return $value instanceof BackedEnum ? $value->value : $value;
490488
})->all();
491489

492490
return $this->routeUrl()->to(

src/Illuminate/Support/Reflector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function isParameterBackedEnumWithStringBackingType($parameter)
150150
{
151151
$backedEnumClass = (string) $parameter->getType();
152152

153-
if (function_exists('enum_exists') && enum_exists($backedEnumClass)) {
153+
if (enum_exists($backedEnumClass)) {
154154
$reflectionBackedEnum = new ReflectionEnum($backedEnumClass);
155155

156156
return $reflectionBackedEnum->isBacked()

src/Illuminate/Validation/Rules/Enum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function passes($attribute, $value)
3838
return true;
3939
}
4040

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

0 commit comments

Comments
 (0)