PhpStorm 无法运行 PHP 代码 CodeSniffer

Ted*_*gan 5 php codesniffer phpstorm

我试图在 PhpStorm 中使用 CodeSniffer。

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

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

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

无法运行 PHP 代码

还添加了所有内容 PATH

我错过了什么?

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

IVO*_*LOV 3

您应该将phpcs.bat和放在phpcs您的 PHP 文件夹中 - 例如d:\program\php\phpcs. CodeSniffer 本身应该驻留在d:\program\php\PEAR\PHP\CodeSniffer- 将有一个脚本autoload.php和一个子文件夹src

然后指定它Settings -> Languages & Frameworks -> PHP -> Code Sniffer的路径。phpcs.batValidate

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

在此输入图像描述 在此输入图像描述

这是我的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); 
Run Code Online (Sandbox Code Playgroud)

这是我的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" %* 
Run Code Online (Sandbox Code Playgroud)

这是我的PEAR_ENV.reg,我已将其导入到 Windows 注册表中

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\\"
Run Code Online (Sandbox Code Playgroud)