【发布时间】:2019-02-26 08:52:54
【问题描述】:
首先,让我列出一些版本,以便您了解设置。
操作系统: Windows 10
php: 7.2.7 NTS,xDebug 2.6.1 处于活动状态
PhpStorm: 2016.2。 2
PHP_CodeSniffer: 3.4.0 版(稳定版),由 Squiz (http://www.squiz.net)
PEAR:1.10.7
现在让我描述一下问题:
代码嗅探器是通过 pear 安装的。我正在使用以下 bat 脚本来启动嗅探器。
@echo off
set folder=C:\Program Files\php
set phpcs=%folder%\phpcs
php "%phpcs%" %*
如果我通过 PowerShell 使用以下命令启动代码嗅探器:
phpcs.bat index.php --standard=PSR2 --encoding=utf-8 --report=xml
我得到了一个有效的输出:
xml version="1.0" encoding="UTF-8"?>
<file name="C:\Users\simon\Documents\Repositories\mm-BIT\CatalogGenerator\index.php" errors="3" warnings="0" fixable="3">
<error line="1" column="1" source="Generic.Files.LineEndings.InvalidEOLChar" severity="5" fixable="1">End of line character is invalid; expected "\n" but found "\r\n"</error>
<error line="124" column="1" source="PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket" severity="5" fixable="1">Space before opening parenthesis of function call prohibited</error>
<error line="129" column="1" source="PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket" severity="5" fixable="1">Space before opening parenthesis of function call prohibited</error>
</file>
</phpcs>
在 PHPStorm 中,设置如下所示:
如果我验证安装 PhpStorm 告诉我一切都很好:
Inspections 页面上的编码标准数据是自动加载的,所以这似乎也有效。
如果 PhpStorm 正在运行脚本,我会收到以下错误:
PHP Code Sniffer
phpcs: xml version="1.0" encoding="UTF-8"?>
我通过被调用的脚本暴露了一些数据:
PHP 代码嗅探器
phpcs: C:/temp/___1.tmp/Core/DataContainers/Language.php --standard=PSR2 --encoding=utf-8 --report=xml
command: php "C:\Program Files\php\phpcs" C:/temp/___1.tmp/Core/DataContainers/Language.php --standard=PSR2 --encoding=utf-8 --report=xml
xml version="1.0" encoding="UTF-8"?>
我确实检查了临时文件夹的写入权限,并检查了文件是否在上述路径上正确创建。我确实在创建文件夹后立即复制了该文件夹,并在 PowerShell 中成功手动运行了命令行。
php "C:\Program Files\php\phpcs"
C:/temp/___.tmp/Core/DataContainers/Modules/SimpleTableModule.php --
standard=PSR2 --encoding=utf-8 --report=xml
wich 提供以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<phpcs version="3.4.0">
xml version="1.0" encoding="UTF-8"?>
<file name="C:\temp\___.tmp\Core\DataContainers\Modules\SimpleTableModule.php" errors="1" warnings="1" fixable="1">
<warning line="82" column="114" source="Generic.Files.LineLength.TooLong" severity="5" fixable="0">Line exceeds 120 characters; contains 123 characters</warning>
<error line="106" column="1" source="PSR2.Files.EndFileNewline.NoneFound" severity="5" fixable="1">Expected 1 newline at end of file; 0 found</error>
</file>
</phpcs>
如果你能给我一些想法,我不知道如何解决这个问题,我会非常高兴。
【问题讨论】: