php Visual Studio Code:无法找到 phpcs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47174009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Code: Unable to locate phpcs
提问by Monika Rani
I am facing this issue in Visual Studio Code. I have already tried reinstalling the phpcs extension but still facing this issue.
我在 Visual Studio Code 中遇到了这个问题。我已经尝试重新安装 phpcs 扩展,但仍然面临这个问题。
Unable to locate phpcs
Please add
phpcs
to your global path or use the composer dependency manager to install it in your project locally in Visual studio Code
无法找到 phpcs
请添加
phpcs
到您的全局路径或使用 composer 依赖管理器在 Visual Studio Code 中本地安装到您的项目中
回答by Jekayode
I had the same issue, I did the following to fix it:
我遇到了同样的问题,我做了以下修复:
Install the phpcs by using composer with
composer global require squizlabs/php_codesniffer
Press
Command + ,
(Click Code -> Preferences -> Settings)- Select User Settings and locate '
PHP CodeSniffer
' Scroll to '
Executatble Path
' and put/Users/your-username/.composer/vendor/bin/phpcs
使用 composer 安装 phpcs
composer global require squizlabs/php_codesniffer
按
Command + ,
(单击代码 -> 首选项 -> 设置)- 选择用户设置并找到“
PHP CodeSniffer
” 滚动到“
Executatble Path
”并放置/用户/您的用户名/.composer/vendor/bin/phpcs
This fixed the issue for me, I hope it does for you too. Cheers!
这为我解决了这个问题,我希望它也适用于你。干杯!
回答by Cengkuru Michael
open the project in the terminal and run this command
在终端中打开项目并运行此命令
composer global require squizlabs/php_codesniffer
Hope that helps!
希望有帮助!
回答by Kevin Mbugua
I think uninstalling it does not solve the issue.
我认为卸载它并不能解决问题。
i had the same issue. So,
我遇到过同样的问题。所以,
- Go to extensions and install the plugin...."phpcs".
- Search for the extension if you had install it.
- Disable the extension.
- 转到扩展并安装插件......“phpcs”。
- 如果您安装了扩展程序,请搜索它。
- 禁用扩展。
it resolved the issue in my VS code.
它解决了我的 VS 代码中的问题。
回答by moazzem
On Debian based systems run as root:
在基于 Debian 的系统上以 root 身份运行:
apt-get install php-codesniffer
回答by Karem Shawky
From a GitHub comment.
来自GitHub 评论。
If someone still needs help about this "Unable to locate phpcs ..." error message, try this: you just need to install
phpcs
globally via Composer.
- Install Composer from this resourceif you don't have it,
After Composer is installed, open a command prompt wherever you want and run this command
composer global require squizlabs/php_codesniffer
如果有人仍然需要有关“无法找到 phpcs ...”错误消息的帮助,请尝试以下操作:您只需要
phpcs
通过 Composer 全局安装即可。
- 如果您没有,请从此资源安装 Composer ,
安装 Composer 后,在任意位置打开命令提示符并运行此命令
composer global require squizlabs/php_codesniffer
回答by SandroMarques
My solution without the need to install php_codesniffer globally.
我的解决方案无需全局安装 php_codesniffer。
Just go to VSCode settings and define the local path ./vendor/squizlabs/php_codesniffer/bin/phpcs
只需转到 VSCode 设置并定义本地路径 ./vendor/squizlabs/php_codesniffer/bin/phpcs
Or you can set the path directly in your settings.json
或者你可以直接在你的路径中设置路径 settings.json
"phpcs.executablePath": "./vendor/squizlabs/php_codesniffer/bin/phpcs"
回答by alireza
In my case and in Windows 10, composer located at:
就我而言,在 Windows 10 中,composer 位于:
C:\Users\{user_name}\AppData\Roaming\Composer\vendor\bin\
and when i added this to VSCode settings at PHP CodeSniffer section this solve my problem.
当我将它添加到 PHP CodeSniffer 部分的 VSCode 设置时,这解决了我的问题。
回答by Fusion Bolt
paste the following in your terminal for system-wide installation
将以下内容粘贴到您的终端中以进行系统范围的安装
composer global require squizlabs/php_codesniffer
This stopped the error message from popping up in mine.
这阻止了我的错误消息弹出。
回答by migli
Install PHP Snifferinstead of phpcs
安装PHP Sniffer而不是phpcs
PHP Snifferworked on the fly without any extra configuration
PHP Sniffer即时工作,无需任何额外配置
phpcscould not recognize my commands, despite a configured PATH, Composer & PHPCS installed.
尽管已配置 PATH、Composer 和 PHPCS,但phpcs无法识别我的命令。
The commands were recognized in the terminal, but not by the plugin (under windows 10)
命令在终端中被识别,但不能被插件识别(在 Windows 10 下)
回答by David Najman
I had the same issue on my Mac in Visual Studio Code (I used PEAR to install PHPCS). I do not know why but PHPCS couldn't find autoload.php of CodeSniffer. You can try to type on terminal command line:
我在我的 Mac 上的 Visual Studio Code 上遇到了同样的问题(我使用 PEAR 来安装 PHPCS)。我不知道为什么,但 PHPCS 找不到 CodeSniffer 的 autoload.php。您可以尝试在终端命令行中输入:
$?phpcs
I got an error:
我有一个错误:
Warning: include_once(PHP/CodeSniffer/autoload.php): failed to open stream: No such file or directory in /Users/david/pear/bin/phpcs on line 14
Warning: include_once(): Failed opening 'PHP/CodeSniffer/autoload.php' for inclusion (include_path='.:') in /Users/david/pear/bin/phpcs on line 14
警告:include_once(PHP/CodeSniffer/autoload.php):无法打开流:第 14 行的 /Users/david/pear/bin/phpcs 中没有这样的文件或目录
警告:include_once():在第 14 行的 /Users/david/pear/bin/phpcs 中打开“PHP/CodeSniffer/autoload.php”以包含(include_path='.:')失败
Solution:
解决方案:
Open Pear Bin folder in your user folder, e.g. in my case: /Users/david/pear/bin/
in Finder,
在您的用户文件夹中打开 Pear Bin 文件夹,例如在我的情况下:/Users/david/pear/bin/
在 Finder 中,
Find phpcs
file inside and edit it (e.g. in Visual Studio Code :),
phpcs
在里面找到文件并编辑它(例如在 Visual Studio Code 中:),
You will find these lines there:
你会在那里找到这些行:
if (is_file(__DIR__.'/../autoload.php') === true) {
include_once __DIR__.'/../autoload.php';
} else {
include_once 'PHP/CodeSniffer/autoload.php';
}
Add two new lines there with the proper location of CodeSniffer/autoload.php file (place it before } else {
line and modify the path according to your needs - replace "david" with your user name...):
在 CodeSniffer/autoload.php 文件的正确位置添加两行新行(将其放在} else {
行前并根据您的需要修改路径 - 将“david”替换为您的用户名...):
} else if (is_file('/users/david/pear/share/pear/PHP/CodeSniffer/autoload.php')) {
include_once '/users/david/pear/share/pear/PHP/CodeSniffer/autoload.php';
So the final code of the condition is:
所以条件的最终代码是:
if (is_file(__DIR__.'/../autoload.php') === true) {
include_once __DIR__.'/../autoload.php';
} else if (is_file('/users/david/pear/share/pear/PHP/CodeSniffer/autoload.php')) {
include_once '/users/david/pear/share/pear/PHP/CodeSniffer/autoload.php';
} else {
include_once 'PHP/CodeSniffer/autoload.php';
}
Then save it and restart Visual Studio Code. That's it.
然后保存并重新启动 Visual Studio Code。就是这样。