shopsys / phpstorm-inspect
用于从CLI运行PhpStorm检查并显示结果的包
v1.1.1
2017-09-11 07:02 UTC
Requires
- php: >=5.4
- arvenil/ninja-mutex: 0.4.1
- symfony/filesystem: @stable
Requires (Dev)
- shopsys/coding-standards: 3.0.0
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"
示例(text格式)
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
脚本。您需要关闭IDE才能从CLI运行检查。
支持哪些PhpStorm版本?
该包已在PhpStorm 8.0(139.732)上进行测试,但新版本可能也能工作。