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

Deprecated method calls are used #25

Closed WouterSioen closed 4 years ago

WouterSioen commented 4 years ago

Description:

The Generator tries to call __toString()` on a ReflectionType which is deprecated since PHP7.1.

https://www.php.net/manual/en/reflectiontype.tostring.php

This means that you get an error when error reporting for deprecations is on.

php artisan laravel-swagger:generate

   ErrorException  : Function ReflectionType::__toString() is deprecated

  at /var/www/html/vendor/mtrajano/laravel-swagger/src/Generator.php:156
    152|
    153|         $parameters = $this->getActionClassInstance($this->action)->getParameters();
    154|
    155|         foreach ($parameters as $parameter) {
  > 156|             $class = (string) $parameter->getType();
    157|
    158|             if (is_subclass_of($class, FormRequest::class)) {
    159|                 return (new $class)->rules();
    160|             }

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Function ReflectionType::__toString() is deprecated", "/var/www/html/vendor/mtrajano/laravel-swagger/src/Generator.php", [Object(ReflectionParameter)])
      /var/www/html/vendor/mtrajano/laravel-swagger/src/Generator.php:156

  2   Mtrajano\LaravelSwagger\Generator::getFormRules()
      /var/www/html/vendor/mtrajano/laravel-swagger/src/Generator.php:134
WouterSioen commented 4 years ago

FYI: you can use the undocumented getName method instead of casting to a string. See https://www.php.net/manual/en/class.reflectiontype.php#124658

WouterSioen commented 4 years ago

Thanks for fixing!

mtrajano commented 4 years ago

No prob, weird that ci didn't pick this up if it has been deprecated since 7.1, in any case the fix was released on v0.6.2