Types in Laravel
summary
Argues that adding static analysis to Laravel catches bugs before runtime by using phpstan + larastan to analyze code, raising phpstan level gradually to avoid thousands of errors; shows enabling checking_missing_iterable_value_type in phpstan.neon and adding docblock generics (array<int,string>, Collection<TKey,TValue>) so phpstan infers wrong returns, unreachable dd, and mixed-value bugs. Demonstrates writing a fully generic Collection stub with templates and map return types, integrates checks into CI, and confirms phpstan then reports no remaining issues.
AI-written summary · about
chapters (12)
- 0:00Introduction and sponsor
- 1:27PHP type system basics
- 3:02The goal of type checking
- 5:12Introduction to PHPStan
- 7:17Fixing bugs with PHPStan
- 10:10Gradual strictness levels
- 12:29Debugging with PHPStan
- 15:51Using generics in PHP
- 20:07Laravel collections and stubs
- 24:34Implementing custom generics
- 32:41IDE autocompletion benefits
- 33:56Type consistency and summary
