Crafting Custom PHPStan Rules
summary
Custom PHPStan rules actually enforce concrete constraints, not vague style guides: demos include a new Person rule that flags direct instantiation (and is made non‑ignorable) and an identical datetime comparison rule that detects === between DateTime objects using nikic/php‑parser, RuleErrorBuilder, scope/type queries and Xdebug dumps for development; collectors enable whole‑project checks, restricted‑uses extensions simplify architectural limits, and autofix callbacks can edit files. The implementation notes that classes can be referenced in 27 different locations, and phpstan‑dba and code‑detector extensions are recommended and work.
AI-written summary · about
chapters (16)
- 0:00PHPStan and static analysis
- 3:32Custom PHPStan rules
- 7:44PHPStan's Abstract Syntax Tree
- 11:55First custom rule
- 20:39Scope for rule logic
- 23:50Types and expressions
- 31:02Datetime comparison rule
- 39:30Advanced rule ideas
- 41:19Missing code detection
- 42:46Autofixable custom rules
- 44:56Architecture restrictions
- 47:03Cross-file analysis
- 48:52Testing custom rules
- 49:36AI for custom rules
- 50:39Third-party extensions
- 53:29Q&A
related talks
33mCustom PHPStan Rules: Automate Standards and Save Time
44mTuning PHPStan to Maximum Strictness
57mTuning PHPStan to Maximum Strictness
01h 00mTuning PHPStan to Maximum Strictness
38mWhy you should be using PHPStan in all your projects
32mFrom Zero to Static Analysis Hero
48mPHPStan: How the Sausage Is Made
57mExtending the PHP Language with Static Analysis- Dave Liddament
