laravel-swagger
laravel-swagger copied to clipboard
PHP 8 deprecation (ReflectionParameter::getClass())
- Laravel Swagger Version: 0.6.4
- Laravel Version: 8.32.1
- PHP Version: 8.0.3
Description:
When attempting to generate the docs for my API after switching to PHP 8 I get the following error:
In Generator.php line 193:
Method ReflectionParameter::getClass() is deprecated
After some quick digging I found this to help solve the issue: https://php.watch/versions/8.0/deprecated-reflectionparameter-methods
Proposed fix:
I tested the following code in that foreach
block which seems to do the trick:
foreach ($parameters as $parameter) {
$class_name = $name = $parameter->getType() && !$parameter->getType()->isBuiltin()
? new \ReflectionClass($parameter->getType()->getName())
: null;
if (is_subclass_of($class_name, FormRequest::class)) {
return (new $class_name)->rules();
}
}