~/talk

Crafting Custom PHPStan Rules

Talkat PHP UK Conference 2026 · on Friday, 2026-02-20· [php]
slides:none on file

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

  1. 0:00PHPStan and static analysis
  2. 3:32Custom PHPStan rules
  3. 7:44PHPStan's Abstract Syntax Tree
  4. 11:55First custom rule
  5. 20:39Scope for rule logic
  6. 23:50Types and expressions
  7. 31:02Datetime comparison rule
  8. 39:30Advanced rule ideas
  9. 41:19Missing code detection
  10. 42:46Autofixable custom rules
  11. 44:56Architecture restrictions
  12. 47:03Cross-file analysis
  13. 48:52Testing custom rules
  14. 49:36AI for custom rules
  15. 50:39Third-party extensions
  16. 53:29Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.