mtrajano / laravel-swagger

Auto generates the swagger documentation of a laravel project based on best practices and simple assumptions
167 stars 71 forks source link

PHP 8 deprecation (ReflectionParameter::getClass()) #60

Open viki53 opened 3 years ago

viki53 commented 3 years ago

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