简体   繁体   English

PhpStorm - 如何在类中找到所有错误的导入(使用)? (PHP)

[英]PhpStorm - how to find all wrong imports(use) in classes ? (PHP)

Look at my PHP code, my import is wrong but is there any feature in PhpStorm to find all wrong imports in all classes (codebase)?看看我的 PHP 代码,我的导入是错误的,但是 PhpStorm 中是否有任何功能可以在所有类(代码库)中找到所有错误的导入?

I don't want to check each class one by one manually.我不想手动一个一个地检查每个类。

错误的 phpstorm 导入(

You can use Code | Inspect Code...您可以使用Code | Inspect Code... Code | Inspect Code... .. or Code | Run Inspection by Name... Code | Inspect Code... .. 或Code | Run Inspection by Name... Code | Run Inspection by Name... if you know (or can guess) the exact inspection name. Code | Run Inspection by Name...如果您知道(或能猜到)确切的检查名称。 It can then be run on current file/folder or specific Scope.然后它可以在当前文件/文件夹或特定范围上运行。

In your case it most likely will be the Undefined class inspection.在您的情况下,它很可能是Undefined class检查。


Code | Optimize Imports Code | Optimize Imports may also be a little helpful here ... but: Code | Optimize Imports在这里也可能有点帮助......但是:

  • It will not report anything as it will modify the code straight away.它不会报告任何内容,因为它会立即修改代码。
  • It's more about removing definitely unused use statements (known classes but no longer/never used in this file) and rearranging their order: it will not tell what is wrong (ie it will not remove or report such PostAddToCartwrong line).更多的是删除绝对未use语句(已知的类,但不再/从未在此文件中使用)并重新排列它们的顺序:它不会告诉什么是错误的(即它不会删除或报告此类PostAddToCartwrong行)。

There is an option in Code menu for that.代码菜单中有一个选项。 For example it arranges imports, as well as removes unused ones.例如,它安排进口,以及删除未使用的。 More detailed info here https://blog.jetbrains.com/phpstorm/2013/03/optimize-imports-for-php/更详细的信息在这里https://blog.jetbrains.com/phpstorm/2013/03/optimize-imports-for-php/

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

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