laravel-request-docs icon indicating copy to clipboard operation
laravel-request-docs copied to clipboard

Error: Call to undefined method ReflectionUnionType::getName()

Open andreaspabst opened this issue 3 years ago • 4 comments

Having laravel 8.5.8 installed and LRD in 1.22 running into the error:

$ php artisan lrd:generate

   Error

  Call to undefined method ReflectionUnionType::getName()

  at C:\Users\****\****\vendor\rakutentech\laravel-request-docs\src\LaravelRequestDocs.php:126
    122▕             foreach ($params as $param) {
    123▕                 if (!$param->getType()) {
    124▕                     continue;
    125▕                 }
  ➜ 126▕                 $requestClassName = $param->getType()->getName();
    127▕                 $requestClass = null;
    128▕                 try {
    129▕                     $requestClass = new $requestClassName();
    130▕                 } catch (Throwable $th) {

  1   C:\Users\****\****\vendor\rakutentech\laravel-request-docs\src\LaravelRequestDocs.php:18
      Rakutentech\LaravelRequestDocs\LaravelRequestDocs::appendRequestRules()

  2   C:\Users\****\****\vendor\rakutentech\laravel-request-docs\src\Commands\LaravelRequestDocsCommand.php:30
      Rakutentech\LaravelRequestDocs\LaravelRequestDocs::getDocs()

php artisan route:list is emitting every single route correctly. I haven't changed anything in config, project etc.

andreaspabst avatar May 03 '22 08:05 andreaspabst

Let me check.

kevincobain2000 avatar May 03 '22 14:05 kevincobain2000

Can you please let me know your PHP version as well? Probably need to add a condition such as below:

You can try it updating inside the vendor and see if it works for you on Line 126.

C:\Users\****\****\vendor\rakutentech\laravel-request-docs\src\LaravelRequestDocs.php:126

           // on line 126
            if (class_exists(ReflectionUnionType::class)
                && $paramType instanceof ReflectionUnionType) {
                $requestClassName = $param->getName();
            } else {
               $requestClassName = $param->getType()->getName();
            }

kevincobain2000 avatar May 04 '22 09:05 kevincobain2000

@kevincobain2000 It's not working. PHP is 8.1. After adding you code with condition "class_exists(ReflectionUnionType::class) && $paramType instanceof ReflectionUnionType" a got the same error.

In LaravelRequestDocs.php line 130: Call to undefined method ReflectionUnionType::getName()

But this works fine:

            if (class_exists(ReflectionUnionType::class)
                && $paramType instanceof ReflectionUnionType) {
                $requestClassName = $param->getName();
            } else {
               $requestClassName = $param->name;
            }

hamrak avatar Aug 30 '22 08:08 hamrak

Thanks, I ll submit a pull req with the changes that you have proposed or you can submit it and I ll merge it.

kevincobain2000 avatar Aug 30 '22 10:08 kevincobain2000

Added in #124

kevincobain2000 avatar Feb 18 '23 14:02 kevincobain2000