在Laravel中解决类导致PhpStorm报错”Cannot find declaration to go to”。

huangapple go评论55阅读模式
英文:

Resolving classes in Laravel leads to PhpStorm "Cannot find declaration to go to"

问题

我正在解决一个类似以下方式的Laravel 10中的类:

$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();

然而,在PhpStorm中,我不能点击到这个方法,并且它显示:

"无法找到要跳转的声明"

这与Laravel的resolve()方法有关,我的IDE没有识别到吗?这令人沮丧,因为函数名现在变成灰色,好像它没有被使用。

我不得不使用resolve(),因为之前我写了$myService = new MyService(),但是我的依赖注入没有工作,除非我解决这个类。

请问有什么建议吗?谢谢。

英文:

I am resolving a class in Laravel 10 like the following:

$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();

However, in PhpStorm, I cannot click through to the method, and it says:

> "Cannot find declaration to go to"

Is this something to do with the Laravel resolve() method that my IDE is not recognising? It's frustrating because the function name is now greyed out like it's not being used.

I'm having to use resolve() because I was previously writing $myService = new MyService(), but my dependency injection was not working without me resolving the class.

Any ideas please? Thanks.

答案1

得分: 0

/** @var MyService $myService */
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();
英文:

You can give a doc line by specifying the type of a variable. This will help the IDE understand it's class

/** @var MyService $myService */
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();

huangapple
  • 本文由 发表于 2023年6月29日 19:29:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定