PhpStorm 无法运行 PHP 代码 CodeSniffer

标签 php phpstorm codesniffer

我正在尝试在 PhpStorm 中使用 CodeSniffer。

设置->PHP->CLI 解释器 我使用 https://windows.php.net/ 链接到 php.exe Im但也尝试过使用 Cygwin 和 XAMPP。

PhpStorm 向我展示了正确的 PHP 版本 7.2.5 和 php.ini

在 CodeSniffer 配置中,我选择了 phpcs.bat 当我点击 Validate 时,我得到了

Can not run PHP Code

还将所有内容添加到 PATH

我错过了什么吗?

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

您应该将 phpcs.batphpcs 放在您的 PHP 文件夹中 - 例如d:\程序\php\phpcs。 CodeSniffer 本身应该位于 d:\program\php\PEAR\PHP\CodeSniffer - 将有一个脚本 autoload.php 和一个子文件夹 src.

然后在 Settings -> Languages & Frameworks -> PHP -> Code Sniffer 中指定 phpcs.bat 的路径并Validate .

然后在 Settings -> Editor -> Inspections 中找到节点 PHP Code Sniffer validation 并启用它。启用它后,您将能够对其进行配置 - 具体选择编码标准。

enter image description here enter image description here

这是我的phpcs

#!D:\PROGRAM\Inet\Design\php\php.exe
<?php
/**
 * PHP_CodeSniffer detects violations of a defined coding standard.
 *
 * @author    Greg Sherwood <gsherwood@squiz.net>
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 */

if (is_file(__DIR__.'/../autoload.php') === true) {
    include_once __DIR__.'/../autoload.php';
} else {
    include_once 'PHP/CodeSniffer/autoload.php';
}

$runner   = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCS();
exit($exitCode); 

这是我的phpcs.bat

@echo off
REM PHP_CodeSniffer detects violations of a defined coding standard.
REM 
REM @author    Greg Sherwood <gsherwood@squiz.net>
REM @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
REM @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence

if "%PHPBIN%" == "" set PHPBIN=D:\PROGRAM\Inet\Design\php\php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "D:\PROGRAM\Inet\Design\php\phpcs" %* 

这是我导入到 Windows 注册表中的 PEAR_ENV.reg

REGEDIT4
[HKEY_CURRENT_USER\Environment]
"PHP_PEAR_SYSCONF_DIR"="D:\\PROGRAM\\Inet\\Design\\php"
"PHP_PEAR_INSTALL_DIR"="D:\\PROGRAM\\Inet\\Design\\php\\pear"
"PHP_PEAR_DOC_DIR"="D:\\PROGRAM\\Inet\\Design\\php\\docs"
"PHP_PEAR_BIN_DIR"="D:\\PROGRAM\\Inet\\Design\\php"
"PHP_PEAR_DATA_DIR"="D:\\PROGRAM\\Inet\\Design\\php\\data"
"PHP_PEAR_PHP_BIN"="D:\\PROGRAM\\Inet\\Design\\php\\php.exe"
"PHP_PEAR_TEST_DIR"="Z:\\Temp\\"

关于PhpStorm 无法运行 PHP 代码 CodeSniffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51761642/

相关文章:

php - Pear CodeSniffer 循环复杂度

php - Laravel 查询构建器获取用户登录记录

javascript - 使用 AJAX 将 JSON 发送到 PHP

PHPStorm 命名空间支持不适用于 Symfony2 项目

PhpStorm 在注释 @throws 标记中无法识别我的自定义异常

php - 如何从 .phpcs.xml 中的 PHP Code Sniffer 检查中排除某些目录以外的所有内容?

php - 渐进式(增量)检查 PHP 样式

php zend framework 日志 mysql 查询

php - wamp服务器的图标没有变成绿色

php - 找不到 PDO 驱动程序(PhpStorm 和 SQLite)