AgentLint 实测验证 87/100基于 64 个 PHP 开源仓库统计

    PHP CLAUDE.md & AGENTS.md 模板

    Pest/PHPUnit 精准过滤、PHPStan 严格分析与 Composer 脚本规范,提炼自 64 个 PHP 仓库。

    # PHP Project — PHP 8.4 Harness
    
    Modern PHP 8.4 / Laravel codebase verified with Pest, PHPStan level 8, and Pint.
    
    ## Commands
    
    - Fast single test: `vendor/bin/pest --filter=InvoiceTest`
    - Full suite: `composer test`
    - Static analysis & style: `vendor/bin/phpstan analyse && vendor/bin/pint --test`
    
    ## Rules
    
    - Don't create new PHP files without `declare(strict_types=1);` and explicit parameter/return types. Because weak coercion hides silent type bugs.
    - Don't interpolate variables into raw SQL queries. Instead use parameterized bindings or Eloquent builders. Because string interpolation creates SQL injection holes.
    - When editing database migrations, read `docs/schema-changes.md` first.
    
    ## Continuity
    
    - Keep `.env` and `CLAUDE.local.md` out of git and summarize schema impacts in `HANDOFF.md`.

    PHP 开源生态中最常采用的工程规则

    基于 4,533 仓库研究中 64 个公开 PHP 仓库的实测统计:

    composer工具链

    Composer for package management

    53.1%34 个仓库
    phpunit测试

    PHPUnit for testing

    50.0%32 个仓库
    unit-tests测试

    Write unit tests for all changes

    40.6%26 个仓库
    laravel框架

    Laravel framework

    37.5%24 个仓库
    migrations代码规范

    Database migrations

    35.9%23 个仓库
    psr代码规范

    PSR coding standards

    29.7%19 个仓库
    docker工具链

    Docker for containerization

    29.7%19 个仓库
    ci-cd工具链

    CI/CD pipeline must pass

    29.7%19 个仓库
    必写验证命令(对应规则 W1 与 W7)
    安装依赖
    composer install --no-interaction
    快速单测(秒级迭代)
    vendor/bin/pest --filter=TargetTest
    全量测试
    composer test
    Lint 与静态检查
    vendor/bin/phpstan analyse && vendor/bin/pint --test
    生产构建
    composer validate --strict
    PHP 项目中 AI 代理常见踩坑
    • 01新建文件漏写 declare(strict_types=1); 或用无类型数组替代 DTO。
    • 02手写 SQL 字符串拼接绕过参数化查询,造成注入隐患。

    更多实证验证模板