kalessil/phpstorm-inspect

用于从命令行运行 PhpStorm 检查并显示结果的软件包

v1.2.1 2017-09-24 17:08 UTC

This package is auto-updated.

Last update: 2024-09-17 06:29:20 UTC


README

此软件包使您能够轻松地将 PhpStorm 作为 CLI 工具进行静态分析。

基本上,它是对 PhpStorm 的 inspect.sh 脚本的包装,并执行一些额外的工作

  • 等待 PhpStorm 完成已经运行的检查(因为 PhpStorm 无法同时运行多个 inspect.sh 实例;参见 IDEA-150272
  • 在每次运行之前清除 PhpStorm 缓存,以防止过时的缓存问题(否则当切换 GIT 分支时,PhpStorm 有时无法看到新文件)
  • 解析由 PhpStorm 生成的 XML 输出,并以可读的格式呈现(类似于 PHP CodeSniffer、PHPMD 或 PHP CS Fixer 等工具)

用法

php bin/phpstorm-inspect <inspectShExecutableFilepath> <phpstormSystemPath> <projectPath> <inspectionProfileFilepath> <inspectedDirectory> [<format>]

参数描述

  • inspectShExecutableFilepath - inspect.sh 脚本的路径
  • phpstormSystemPath - .WebIde*/system 目录的路径
  • projectPath - 包含 .idea 目录的项目目录的路径
  • inspectionProfileFilepath - 检查配置 XML 文件的路径
  • inspectedDirectory - 包含检查源文件的路径
  • format (可选) - 输出结果的格式,接受的值:"text"(默认值)/ "checkstyle"

示例(文本格式)

php bin/phpstorm-inspect \
  /opt/PhpStorm-139.1348/bin/inspect.sh ~/.WebIde80/system \
  . .idea/inspectionProfiles/Project_Default.xml ./src

输出

File: /home/user/project/src/MyBundle/Controller/UserController.php
--------------------------------------------------------------------------------
Found 1 problems
--------------------------------------------------------------------------------
Line 17: Undefined field: Field 'usre' not found in class
--------------------------------------------------------------------------------

File: /home/user/project/src/MyBundle/Controller/ArticleController.php
--------------------------------------------------------------------------------
Found 2 problems
--------------------------------------------------------------------------------
Line 26: Unused local variable: Unused local variable $articleId
Line 32: Unreachable statement: Unreachable statement
--------------------------------------------------------------------------------

示例(checkstyle 格式)

php bin/phpstorm-inspect \
  /opt/PhpStorm-139.1348/bin/inspect.sh ~/.WebIde80/system \
  . .idea/inspectionProfiles/Project_Default.xml ./src checkstyle > report.xml

report.xml 的内容

<?xml version="1.0"?>
<checkstyle version="1.0.0">
    <file name="/home/user/project/src/MyBundle/Controller/UserController.php">
        <error line="17" column="0" severity="warning" message="Undefined field: Field 'usre' not found in class" />
    </file>
    <file name="/home/user/project/src/MyBundle/Controller/ArticleController.php">
        <error line="26" column="0" severity="warning" message="Unused local variable: Unused local variable $articleId" />
        <error line="32" column="0" severity="warning" message="Unreachable statement: Unreachable statement" />
    </file>
</checkstyle>

常见问题解答 / 问题

为什么我要使用这个软件包,而不是直接从 IDE 运行检查呢?

在没有图形界面的环境中,这个软件包非常方便。

例如,您可以在持续集成服务器(例如 Jenkins)上运行静态代码分析。

当 PhpStorm IDE 运行时,CLI 检查是否工作?

遗憾的是,不行。目前 PhpStorm 不支持在 IDE 运行时运行 inspect.sh 脚本。您需要在从 CLI 运行检查时关闭 IDE。

支持哪些 PhpStorm 版本?

该软件包已在 PhpStorm 8.0 (139.732) 上进行了测试,但可能也适用于较新版本。