laravel-swagger icon indicating copy to clipboard operation
laravel-swagger copied to clipboard

PHP 8 deprecation (ReflectionParameter::getClass())

Open viki53 opened this issue 3 years ago • 0 comments

  • 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();
            }
        }

viki53 avatar Mar 09 '21 17:03 viki53