简体   繁体   English

PhpStorm无法识别方法

[英]PhpStorm not recognizing methods

So this has been asked several times but I'm yet to find an answer that works. 所以这个问题已经被问了好几次了,但是我还没有找到有效的答案。

I'm using PhpStorm - 2016.3.2 and Laravel 5.4 我正在使用PhpStorm-2016.3.2和Laravel 5.4

在此处输入图片说明

I have tried using https://github.com/barryvdh/laravel-ide-helper and also the Laravel plugin for PhpStorm. 我尝试过使用https://github.com/barryvdh/laravel-ide-helper以及PhpStorm的Laravel插件。

I tried checking the option "Downgrade severity if_magic methods are present in class" - this didn't work. 我尝试检查“在类中存在降级严重性if_magic方法”选项-无法正常工作。

The only thing I can do to solve this is to turn the warnings off completely for undefined methods, but turning features like this off defeat the point of using an IDE. 解决此问题的唯一方法是完全关闭未定义方法的警告,但是关闭此类功能将无法使用IDE。

Has anyone found a way to solve this? 有没有人找到解决这个问题的方法?

Sources: 资料来源:

https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15 https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15

https://laracasts.com/discuss/channels/general-discussion/why-does-phpstorm-not-recognise-all-the-classes?page=1 https://laracasts.com/discuss/channels/general-discussion/why-does-phpstorm-not-recognise-all-the-classes?page=1

PhpStorm laravel 5 method not found 找不到PhpStorm Laravel 5方法

https://github.com/barryvdh/laravel-ide-helper https://github.com/barryvdh/laravel-ide-helper

PHPDoc blocks can come in handy for this. PHPDoc块可以派上用场。

You can add this PHP comment just before the statement return $query , inside the function 您可以在函数内部的语句返回$ query之前添加此PHP注释。

/** @var $query \Illuminate\Database\Query\Builder */

In this way PHPStorm will correctly recognize the method 这样,PHPStorm将正确识别该方法

The reason this is happening is because PHPStorm doesn't know what that variable is meant to be (it has nothing to be with Laravel). 发生这种情况的原因是因为PHPStorm不知道该变量的含义(与Laravel无关)。 As far as PHPStorm knows it's just a param for a method. 据PHPStorm知道,这只是方法的一个参数。

As @LazyOne suggested, you can type hint the variable eg 正如@LazyOne建议的那样,您可以键入提示变量,例如

public function scopeIncomplete(Builder $query)

Then at the top of the class just add the following use statement 然后在类的顶部添加以下use语句

use Illuminate\Database\Eloquent\Builder;

Alternatively, if you're using a OS X (I'm not sure of the shortcuts for Windows or Linux) you can move the caret in the Builder reference and then hit alt enter to import the class. 另外,如果您使用的是OS X(我不确定Windows或Linux的快捷方式),则可以在Builder参考中移动插入符号,然后按alt enter来导入该类。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM