leovie/clover-crap-check
Composer 安装命令:
composer require --dev leovie/clover-crap-check
包简介
关键字:
README 文档
README
This tool reads the clover.xml report from phpunit and checks, if all files have a CRAP index below a specified threshold.
Installation
PHAR (recommended)
You can download the latest PHAR from https://github.com/LeoVie/clover-crap-check/releases/latest
Composer
Install via composer as a dev dependency
composer require --dev leovie/clover-crap-check
Usage
The tool has two required arguments
- The path of the clover.xml file, that's generated by phpunit. The path can be absolute or relative to cwd.
- The CRAP index threshold that is acceptable (min
1)
Generate the clover.xml file by using phpunit and run clover-crap-check afterwards:
vendor/bin/phpunit --coverage-clover clover.xml vendor/bin/clover-crap-check clover.xml 50
This can give you an output like the following
[ERROR] The following methods are crappier than allowed
------------ -------- ------
Class method CRAP
------------ -------- ------
ClassA m1 100
Foo\ClassB m2 60
------------ -------- ------
Baseline feature
When using clover-crap-check with legacy code, likely you don't want
to refactor all your files to have a low CRAP index. At the same time
you want your new code to be as less CRAPpy as possible.
To achieve this with clover-crap check, there is a baseline feature.
1. Generate the baseline
In addition to the required arguments, pass the option --generate-baseline
with a path to where the baseline file should get stored.
The path can be absolute or relative to cwd.
vendor/bin/clover-crap-check clover.xml 50 \ --generate-baseline=baseline.json
This will run clover-crap-check and generate a baseline file that
contains all your files with a CRAP index over the defined threshold
(50 in this case).
The baseline files looks like the following
[
{
"classFQN": "ClassA",
"name": "m1",
"crap": 100
},
{
"classFQN": "Foo\\ClassB",
"name": "m2",
"crap": 60
}
]
2. Use the baseline
After generating the baseline, you can use it in the next runs.
To do this, simply pass the path to the baseline file
via the option --baseline to the tool.
The path can be absolute or relative to cwd.
vendor/bin/clover-crap-check clover.xml 50 \ --baseline=baseline.json
clover-crap-check should not report anything in that case.
Now, when you add new files with a CRAP index over the defined threshold
(50 in this case), you will get noticed about that. The same thing
happens, when files in your baseline get CRAPpier, than they were
when the baseline was generated.
This can give you an output like the following
[ERROR] The baseline is not up to date
[ERROR] The following methods are newly occurring
-------- -------- ------
Class method CRAP
-------- -------- ------
ClassC m3 70
-------- -------- ------
[ERROR] The following methods got crappier
-------- -------- ------
Class method CRAP
-------- -------- ------
ClassA m1 65
-------- -------- ------
3. Keeping the baseline up to date
You can decide to generate the baseline once and then never touch it again. This can be useful when you have very many files in the baseline and don't want to bother with improving the legacy code over the time.
But you can also decide to get noticed, when a file gets less
CRAPpy. To do this, you can pass the option --report-less-crappy-methods
to clover-crap-check
vendor/bin/clover-crap-check clover.xml 50 \ --baseline=baseline.json \ --report-less-crappy-methods
This will give you a hint, e.g. when a file that had a CRAP index
of 100 when you generated the baseline now has a CRAP index of 60.
[ERROR] The baseline is not up to date
[INFO] The following methods got less crappy
-------- -------- ------
Class method CRAP
-------- -------- ------
ClassA m1 60
-------- -------- ------
You can than manually update the CRAP value in the baseline file
(to 60 in this case).
There's also another option --report-vanished-methods. When activated,
clover-crap-check will notice you when there are methods in your
baseline, that are not occurring anymore in the clover report or have
a CRAP index below your threshold, now.
[ERROR] The baseline is not up to date
[INFO] The following methods vanished
-------- -------- ------
Class method CRAP
-------- -------- ------
ClassA m1 100
-------- -------- ------
leovie/clover-crap-check 适用场景与选型建议
leovie/clover-crap-check 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 leovie/clover-crap-check 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leovie/clover-crap-check 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 leovie/clover-crap-check 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Monolog bridge for PHP Debugbar
Simple and fast methods to read private properties and call private methods
Analysis module for finding problematical shop data.
Analysis module for finding problematical shop data.
Enforce architecture by defining modules with allowed dependencies. Detects forbidden, uncovered, missing and unused module dependencies in PHP projects.
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 43
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-23