Skip to content

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

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions