I recently try to run the command below and I got this error:
$ artisan ide-helper:generate
Error
Call to a member function getMethods() on null
at vendor/barryvdh/laravel-ide-helper/src/Macro.php:64
60โ {
61โ $enclosingClass = $this->method->getClosureScopeClass();
62โ
63โ /** @var \ReflectionMethod $enclosingMethod */
โ 64โ $enclosingMethod = Collection::make($enclosingClass->getMethods())
65โ ->first(function (\ReflectionMethod $method) {
66โ return $method->getStartLine() <= $this->method->getStartLine()
67โ && $method->getEndLine() >= $this->method->getEndLine();
68โ });
+32 vendor frames
33 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Can you debug which method this is about?
Also maybe the code is simply buggy as getClosureScopeClass can return null, but nevertheless would be good to understand what specifically triggers this.
This seems to be caused by invokable classes. This how to reproduce this issue:
Versions:
Create class App\Foo:
<?php
namespace App;
class Foo
{
public function __invoke($var)
{
return $var;
}
}
Register the macro by passing a new instance of App\Foo:
<?php
namespace App\Providers;
use App\Foo;
// ...
class AppServiceProvider extends ServiceProvider
{
public function register()
{
UrlGenerator::macro('foo', new Foo());
}
// ...
}
Run php artisan ide-helper:generate.
Error
Call to a member function getMethods() on null
at vendor/barryvdh/laravel-ide-helper/src/Macro.php:64
60โ {
61โ $enclosingClass = $this->method->getClosureScopeClass();
62โ
63โ /** @var \ReflectionMethod $enclosingMethod */
โ 64โ $enclosingMethod = Collection::make($enclosingClass->getMethods())
65โ ->first(function (\ReflectionMethod $method) {
66โ return $method->getStartLine() <= $this->method->getStartLine()
67โ && $method->getEndLine() >= $this->method->getEndLine();
68โ });
+30 vendor frames
31 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Logging the value of $this->method at src/Macro.php:62 results in the following log entry:
[2020-12-10 10:26:38] local.DEBUG: Closure [ <user> public method Illuminate\Foundation\Providers\{closure} ] {
@@ /Users/standaniels/Desktop/temp/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php 83 - 85
}
[2020-12-10 10:26:38] local.DEBUG: Method [ <user> public method __invoke ] {
@@ /Users/standaniels/Desktop/temp/app/Foo.php 7 - 10
- Parameters [1] {
Parameter #0 [ <required> $string ]
}
}
I don't use these kind of things ๐คทโโ๏ธ
Can you propose a PR / test to fix this?
Most helpful comment
This seems to be caused by invokable classes. This how to reproduce this issue:
Versions:
Step 1.
Create class
App\Foo:Step 2.
Register the macro by passing a new instance of
App\Foo:Step 3.
Run
php artisan ide-helper:generate.Result
Logging the value of
$this->methodatsrc/Macro.php:62results in the following log entry: