uzulla/phpstorm-inspect-code-cli-runner
Composer 安装命令:
composer require uzulla/phpstorm-inspect-code-cli-runner
包简介
CLI tool that runs PhpStorm's code inspections and outputs structured results for easier refactoring and find bugs.
README 文档
README
This package enables you to comfortably use PhpStorm as a CLI tool for static analysis.
Features
- Wrapper for PhpStorm's
inspect.shscript with additional functionality - Waits for PhpStorm to finish already running inspections
- Clears PhpStorm's cache before every run to prevent stale cache issues
- Parses XML output generated by PhpStorm and presents it in a readable form
- Supports both text and checkstyle output formats
- Modern PHP 8.3 implementation with Symfony Console integration
- Tested with PHPStorm 2024.3
Installation
composer require shopsys/phpstorm-inspect
Usage
vendor/bin/phpstorm-inspect inspect \
--inspect-sh=/path/to/PhpStorm/bin/inspect.sh \
--system-path=/path/to/.WebIde*/system \
--project-path=/path/to/project \
--profile=/path/to/project/.idea/inspectionProfiles/Project_Default.xml \
--directory=/path/to/inspect \
--format=text
Arguments
--inspect-sh: Path toinspect.shscript--system-path: Path to.WebIde*/systemdirectory--project-path: Path to project directory (that contains.ideadirectory)--profile: Path to inspection profile XML file--directory: Path in which are the inspected sources--format: Format of output result, accepted values: "text" (default) / "checkstyle"
Environment Configuration
You can configure PhpStorm binary paths using a .env file:
-
Copy the
.env.examplefile to.envin the project root:cp .env.example .env
-
Edit the
.envfile with your specific paths:PHPSTORM_INSPECT_SH=/path/to/PhpStorm/bin/inspect.sh PHPSTORM_SYSTEM_PATH=/path/to/.WebIde*/system
When environment variables are set, you can omit the corresponding command-line options:
vendor/bin/phpstorm-inspect inspect \ --project-path=/path/to/project \ --profile=/path/to/project/.idea/inspectionProfiles/Project_Default.xml \ --directory=/path/to/inspect \ --format=text
Example Usage
Creating a Simple Inspection Profile
If you don't have an existing inspection profile, you can create a simple one:
<?xml version="1.0" encoding="UTF-8"?> <inspections version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="PhpDocMissingReturnTagInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpDocSignatureInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingDocCommentInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingParentCallCommonInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingParentCallMagicInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMultipleClassesDeclarationsInOneFile" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpRedundantCatchClauseInspection" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpSingleClassInspection" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpStanGlobal" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> </inspections>
Save this to a file named inspection-profile.xml in your project directory.
Running the Inspection
You can run the inspection on your project's source code:
php bin/phpstorm-inspect --project-path=$(pwd) --profile=$(pwd)/inspection-profile.xml --directory=$(pwd)/src
Self-Inspection Example
A good way to test the tool is to use it to inspect its own code:
# Create a simple inspection profile cat > inspection-profile.xml << 'EOF' <?xml version="1.0" encoding="UTF-8"?> <inspections version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="PhpDocMissingReturnTagInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpDocSignatureInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingDocCommentInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingParentCallCommonInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMissingParentCallMagicInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PhpMultipleClassesDeclarationsInOneFile" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpRedundantCatchClauseInspection" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpSingleClassInspection" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PhpStanGlobal" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> </inspections> EOF # Run the inspection on the tool's own code php bin/phpstorm-inspect --project-path=$(pwd) --profile=$(pwd)/inspection-profile.xml --directory=$(pwd)/src
Sample Output (Text Format)
When running the self-inspection example above, you'll get output similar to this:
File: /path/to/project/src/PhpStormInspect/Command/InspectCommand.php
--------------------------------------------------------------------------------
Found 15 problems
--------------------------------------------------------------------------------
Line 25: Missing PHPDoc comment: Missing PHPDoc comment for class
Line 27: Class constant type is missing: Class constant type is missing
Line 28: Class constant type is missing: Class constant type is missing
Line 30: Missing parent call for method: Missing parent method call
Line 30: unused declaration: Method is never used.
Line 72: Missing parent call for method: Missing parent method call
Line 72: unused declaration: Method is never used.
Line 83: Fully qualified name usage: Qualifier can be replaced with an import
Line 89: Fully qualified name usage: Qualifier can be replaced with an import
Line 110: Fully qualified name usage: Qualifier can be replaced with an import
Line 120: Fully qualified name usage: Qualifier can be replaced with an import
Line 125: Fully qualified name usage: Qualifier can be replaced with an import
Line 142: Fully qualified name usage: Qualifier can be replaced with an import
Line 152: Fully qualified name usage: Qualifier can be replaced with an import
Line 165: Fully qualified name usage: Qualifier can be replaced with an import
--------------------------------------------------------------------------------
File: /path/to/project/src/PhpStormInspect/Inspection/InspectionRunner.php
--------------------------------------------------------------------------------
Found 5 problems
--------------------------------------------------------------------------------
Line 10: Missing PHPDoc comment: Missing PHPDoc comment for class
Line 12: Class constant type is missing: Class constant type is missing
Line 13: Class constant type is missing: Class constant type is missing
Line 69: Fully qualified name usage: Qualifier can be replaced with an import
Line 73: Fully qualified name usage: Qualifier can be replaced with an import
--------------------------------------------------------------------------------
... (more files and issues) ...
This output shows various code quality issues that PhpStorm's inspection has found, such as:
- Missing PHPDoc comments
- Missing class constant types
- Missing parent method calls
- Fully qualified name usage that could be replaced with imports
- Unused declarations
- And more
Sample Output (Checkstyle Format)
You can also get the output in checkstyle format, which is useful for integration with CI tools:
php bin/phpstorm-inspect --project-path=$(pwd) --profile=$(pwd)/inspection-profile.xml --directory=$(pwd)/src --format=checkstyle
Output:
<?xml version="1.0"?> <checkstyle version="1.0.0"> <file name="/path/to/project/src/PhpStormInspect/Command/InspectCommand.php"> <error line="25" column="0" severity="weak warning" message="Missing PHPDoc comment for class"/> <error line="27" column="0" severity="weak warning" message="Class constant type is missing"/> <error line="28" column="0" severity="weak warning" message="Class constant type is missing"/> <error line="30" column="0" severity="weak warning" message="Missing parent method call"/> <error line="30" column="0" severity="weak warning" message="Method is never used."/> <!-- More errors... --> </file> <file name="/path/to/project/src/PhpStormInspect/Inspection/InspectionRunner.php"> <error line="10" column="0" severity="weak warning" message="Missing PHPDoc comment for class"/> <error line="12" column="0" severity="weak warning" message="Class constant type is missing"/> <error line="13" column="0" severity="weak warning" message="Class constant type is missing"/> <error line="69" column="0" severity="weak warning" message="Qualifier can be replaced with an import"/> <error line="73" column="0" severity="weak warning" message="Qualifier can be replaced with an import"/> </file> <!-- More files... --> </checkstyle>
The checkstyle format is particularly useful for integrating with CI/CD pipelines and other tools that can process this standard format.
Tips for Effective Usage
Customizing Inspection Profiles
For more comprehensive code quality checks, you can create a custom inspection profile in PhpStorm:
- Open your project in PhpStorm
- Go to Settings/Preferences → Editor → Inspections
- Configure the inspections you want to enable/disable
- Click the gear icon and select "Export" to save your profile as an XML file
- Use this exported file with the
--profileoption
Integrating with CI/CD
To integrate with CI/CD pipelines:
- Use the checkstyle output format (
--format=checkstyle) - Save the output to a file:
php bin/phpstorm-inspect ... --format=checkstyle > phpstorm-inspection.xml - Use a tool like checkstyle-formatter to convert the output to HTML or other formats
- Configure your CI system to fail the build if certain types or numbers of issues are found
Performance Considerations
- The first run may take longer as PhpStorm builds its indexes
- For large projects, consider inspecting specific directories rather than the entire project
- Clearing the cache (which this tool does automatically) helps prevent stale cache issues but may increase inspection time
License
MIT License (see LICENSE file)
This is a modernized version of shopsys/phpstorm-inspect updated for PHP 8.3.
uzulla/phpstorm-inspect-code-cli-runner 适用场景与选型建议
uzulla/phpstorm-inspect-code-cli-runner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「inspection」 「refactoring」 「phpstorm」 「code quality」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 uzulla/phpstorm-inspect-code-cli-runner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uzulla/phpstorm-inspect-code-cli-runner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 uzulla/phpstorm-inspect-code-cli-runner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Cassandra php driver library IDE stubs which enables autocompletion in modern IDEs.
PhpStorm meta data for expected arguments completion in Doctrine projects.
Editable JSON AST with visitor traversal and formatting-preserving printing.
An extensible package of custom Rector rules for automated PHP refactoring and coding standard enforcement.
Stubs to let Psalm understand Doctrine MongoDb ODM better
Repository resolver to show psalm how to resolve getRepository method
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-18