Custom PHPStan Rules: Automate Standards and Save Time
summary
Creates three custom PHPStan rules that run on the AST using nikic/php-parser and PHPStan’s Rule interface, including a route validator (regex-based) that enforces kebab-case URLs and camelCase params, an alert-service upgrade rule that finds calls missing the new type argument, and an extension.neon checker that detects rule classes not registered in the extension file. Implements rules with RuleErrorBuilder, packages them as a PHPStan extension via composer, and reports concrete missing-argument and registration errors during analysis.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:46Enforcing coding standards
- 5:15Abstract Syntax Tree
- 8:10PHPStan custom rules
- 11:40First rule: URL validation
- 17:22Library upgrade assistance
- 21:20Alert service upgrade rule
- 24:54Sharing upgrade rules
- 28:26Automating rule registration
- 31:13Bug prevention with rules
- 32:19Summary
related talks
54mCrafting Custom PHPStan Rules
57mTuning PHPStan to Maximum Strictness
32mFrom Zero to Static Analysis Hero
44mTuning PHPStan to Maximum Strictness
38mWhy you should be using PHPStan in all your projects
01h 00mTuning PHPStan to Maximum Strictness
48mPHPStan: How the Sausage Is Made
57mExtending the PHP Language with Static Analysis- Dave Liddament
