laravel-request-docs
laravel-request-docs copied to clipboard
Error: Call to undefined method ReflectionUnionType::getName()
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.
Let me check.
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 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;
}
Thanks, I ll submit a pull req with the changes that you have proposed or you can submit it and I ll merge it.
Added in #124