用途:为 Laravel 项目提供测试、静态分析与代码质量强制执行的工具集,适合在配置或运行静态分析、代码风格、lint 时使用。
主要能力:通过 composer.json 脚本统一入口,包含 test(pest)、analyse(phpstan analyse)、format(pint)与 quality(依次执行 analyse 和 test)。要求所有文件顶部声明 declare(strict_types=1),并在每次提交前运行质量检查。
静态分析:安装 phpstan/phpstan、phpstan/phpstan-strict-rules、larastan/larastan(均为 --dev)。配置 phpstan.neon,引入 larastan 与 strict-rules 扩展,level 最低 5、可按项目提升至 8,paths 为 app 与 tests,可排除指定路径,并开启 checkMissingIterableValueType、checkGenericClassInNonGenericObjectType。运行命令:./vendor/bin/phpstan analyse。
代码风格:安装 laravel/pint --dev,配置 pint.json(preset 为 laravel,可加规则)。运行 ./vendor/bin/pint,检查用 ./vendor/bin/pint --test。
测试覆盖:在 phpunit.xml 配置 coverage 报告,运行 ./vendor/bin/pest --coverage,可用 --min=80 强制最低覆盖率。
CI 与钩子:提供 GitHub Actions 示例,依次执行 pint --test、phpstan analyse、pest --coverage --min=80;可用 brainmaestro/composer-git-hooks 配置 pre-commit 钩子运行 pint、phpstan、pest。
质量指标与限制:建议覆盖率 80%+、PHPStan 最高 level 8、架构测试通过率 100%、风格违规 0。资料还列出常见反模式与类型安全问题,但未提供具体价格、平台支持范围或效果保证。