staabm / phpstan-baseline-analysis
0.12.5
2024-04-15 13:33 UTC
Requires
- php: ^7.4 || ^8.0
- nette/neon: ^3.2
- symfony/polyfill-php80: ^1.26
- thecodingmachine/safe: ^1.3 || ^2.0
Requires (Dev)
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.6
- symfony/var-dumper: ^5.3
- thecodingmachine/phpstan-safe-rule: ^1.2
- tomasvotruba/cognitive-complexity: 0.2.3
- tomasvotruba/type-coverage: 0.2.5
- tomasvotruba/unused-public: 0.3.8
- dev-main
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12
- 0.11.1
- 0.11
- 0.10.1
- 0.10
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9
- 0.8.2
- 0.8.1
- 0.8
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6
- 0.5.1
- 0.5
- 0.4
- 0.3.1
- 0.3
- 0.2.2
- 0.2.1
- 0.2
- 0.1
- dev-dependabot/composer/tomasvotruba/unused-public-0.3.11
- dev-dependabot/composer/phpunit/phpunit-tw-11.3
- dev-dependabot/composer/nette/neon-tw-3.4
- dev-dependabot/composer/symfony/var-dumper-tw-7.1
- dev-dependabot/composer/tomasvotruba/type-coverage-0.3.1
- dev-staabm-patch-1
This package is auto-updated.
Last update: 2024-09-16 07:55:57 UTC
README
分析PHPStan基准文件并创建汇总的错误趋势报告。
您需要在项目中配置至少一个受支持的PHPStan RuleSets/Rules,才能获得有意义的分析结果。
安装
composer require staabm/phpstan-baseline-analysis --dev
支持的规则
PHPStan RuleSets
PHPStan Rules
- PHPStan\Rules\PhpDoc\InvalidPhpDocTagValueRule
Symplify PHPStan Rules
- Symplify\PHPStanRules\Rules\Explicit\NoMixedMethodCallerRule
- Symplify\PHPStanRules\Rules\Explicit\NoMixedPropertyFetcherRule
tomasvotruba/cognitive-complexity Rules
- TomasVotruba\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule
tomasvotruba/type-coverage Rules
- TomasVotruba\TypeCoverage\Rules\ParamTypeCoverageRule
- TomasVotruba\TypeCoverage\Rules\PropertyTypeCoverageRule
- TomasVotruba\TypeCoverage\Rules\ReturnTypeCoverageRule
tomasvotruba/unused-public Rules
- TomasVotruba\UnusedPublic\Rules\UnusedPublicClassConstRule
- TomasVotruba\UnusedPublic\Rules\UnusedPublicClassMethodRule
- TomasVotruba\UnusedPublic\Rules\UnusedPublicPropertyRule
示例报告
从当前目录开始,该命令将递归地搜索匹配glob模式的文件,并为每个找到的基准报告一个摘要。
$ phpstan-baseline-analyze *phpstan-baseline.neon
Analyzing app/portal/phpstan-baseline.neon
Overall-Errors: 41
Classes-Cognitive-Complexity: 70
Deprecations: 2
Invalid-Phpdocs: 5
Unknown-Types: 1
Anonymous-Variables: 4
Native-Property-Type-Coverage: 1
Native-Param-Type-Coverage: 27
Native-Return-Type-Coverage: 4
Unused-Symbols: 3
示例错误过滤
过滤现有基准并仅输出不匹配给定过滤键的错误
提示
这有助于从现有基准中删除一类错误,从而使PHPStan能够重新报告它们。
$ phpstan-baseline-filter *phpstan-baseline.neon --exclude=Unknown-Types
过滤现有基准并仅输出匹配给定过滤键的错误
$ phpstan-baseline-filter *phpstan-baseline.neon --include=Invalid-Phpdocs
当前支持的过滤键可以在源代码中找到。[目前支持的过滤键](https://github.com/staabm/phpstan-baseline-analysis/blob/1e8ea32a10e1a50c3fd21396201495a1ae1a5d1d/lib/ResultPrinter.php#L42-L51)
示例图形分析
$ git clone ...
$ phpstan-baseline-analyze *phpstan-baseline.neon --json > now.json
$ git checkout `git rev-list -n 1 --before="1 week ago" HEAD`
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > 1-week-ago.json
$ git checkout `git rev-list -n 1 --before="2 week ago" HEAD`
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > 2-weeks-ago.json
$ php phpstan-baseline-graph '*.json' > result.html
示例趋势分析
以下示例显示了您的phpstan基准中的错误演变。查看两个不同时间点的趋势,例如
$ git clone ...
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > now.json
$ git checkout `git rev-list -n 1 --before="1 week ago" HEAD`
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > reference.json
$ phpstan-baseline-trend reference.json now.json
Analyzing Trend for app/portal/phpstan-baseline.neon
Overall-Errors: 30 -> 17 => improved
Classes-Cognitive-Complexity: 309 -> 177 => improved
Deprecations: 1 -> 2 => worse
Invalid-Phpdocs: 3 -> 1 => good
Unknown-Types: 5 -> 15 => worse
Anonymous-Variables: 4 -> 3 => good
Unused-Symbols: 1 -> 1 => good
Native-Return-Type-Coverage: 20 -> 2 => worse
Native-Property-Type-Coverage: 3 -> 3 => good
Native-Param-Type-Coverage: 4 -> 40 => improved
在安排的GitHub操作中使用Mattermost通知的示例
将以下工作流程复制到您的仓库中。请确保根据需要进行调整
- 调整cron计划模式
- actions/checkout可能需要令牌 - 例如,用于私有仓库
- 根据需要调整比较周期
- 根据您的需要调整通知 - 例如,使用Slack、Discord、电子邮件等
name: Trends Analyse
on:
workflow_dispatch:
schedule:
- cron: '0 8 * * 4'
jobs:
behat:
name: Trends
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- run: "composer global require staabm/phpstan-baseline-analysis"
- run: echo "$(composer global config bin-dir --absolute --quiet)" >> $GITHUB_PATH
- uses: actions/checkout@v2
with:
fetch-depth: 50 # fetch the last X commits.
- run: "phpstan-baseline-analyze '*phpstan-baseline.neon' --json > ../now.json"
- run: git checkout `git rev-list -n 1 --before="1 week ago" HEAD`
- run: "phpstan-baseline-analyze '*phpstan-baseline.neon' --json > ../reference.json"
- name: analyze trend
shell: php {0}
run: |
<?php
exec('phpstan-baseline-trend ../reference.json ../now.json > ../trend.txt', $output, $exitCode);
$project = '${{ github.repository }}';
if ($exitCode == 0) {
# improvements
file_put_contents(
'mattermost.json',
json_encode(["username" => "github-action-trend-bot", "text" => $project ." :tada:\n". file_get_contents("../trend.txt")])
);
}
elseif ($exitCode == 1) {
# steady
file_put_contents(
'mattermost.json',
json_encode(["username" => "github-action-trend-bot", "text" => $project ." :green_heart:\n". file_get_contents("../trend.txt")])
);
}
elseif ($exitCode == 2) {
# got worse
file_put_contents(
'mattermost.json',
json_encode(["username" => "github-action-trend-bot", "text" => $project ." :broken_heart:\n". file_get_contents("../trend.txt")])
);
}
- run: 'curl -X POST -H "Content-Type: application/json" -d @mattermost.json ${{ secrets.MATTERMOST_WEBHOOK_URL }}'
if: always()
💌 回馈一些爱心
考虑支持项目[支持项目](https://github.com/sponsors/staabm),这样我们就可以更快地将此工具变得更好。