Static Analysis with PHPStan
PHP is very much a dynamically typed language. You can write entire applications without ever so much as type hinting a string.
But, if you prefer a stricter approach, there is a tool that makes PHP more akin to TypeScript or Rust - PHPStan! Let me show you the ropes in this short series.
Progress
Series Info
- Episodes
- 5
- Run Time
- 59m
- Difficulty
- Intermediate
- Last Updated
- Nov 10, 2023
- Version
- Latest
Series Episodes
- Episodes (5)
Static What Now?
If you've only ever worked with PHP and JavaScript, you might not even understand why there is so much fuss surrounding types. That's because PHP is dynamically typed. What does that mean? Let's take a look at an example.Installation and First Run
With PHPStan as our static analyzer of choice, let's install it in a Laravel project, configure thephpstan.neonfile and fix some of the initial errors it finds in our application.Ignoring Errors
Some 'errors' that PHPStan detects will be logically impossible. Rather than twist your code to make PHPStan happy, you can tell PHPStan to ignore errors of that type. Let's discuss a few different approaches to ignoring errors.Use Phpdocs to Provide Context
PHPStan makes heavy use of PHPDocs to provide extra information it requires to fully inspect your code. Let's take a look at some of the powerful analysis features made possible by adding a few docblocks to your code.An Introduction to Generics
You may never have heard of generics before. They're a little complicated to wrap your head around, but it is well worth the time and effort to learn because they add very powerful insights to PHPStan that can help catch edge case bugs.
