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

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

Open
viki53 opened this issue Mar 9, 2021 · 0 comments · May be fixed by #61
Open

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

viki53 opened this issue Mar 9, 2021 · 0 comments · May be fixed by #61
Labels
bug Something isn't working

Comments

@viki53
Copy link

viki53 commented Mar 9, 2021

  • 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 viki53 added the bug Something isn't working label Mar 9, 2021
@viki53 viki53 changed the title PHP 8 deprecations PHP 8 deprecation (ReflectionParameter::getClass()) Mar 9, 2021
viki53 added a commit to viki53/laravel-swagger that referenced this issue Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant