By using assert() and throwing an Exception if the condition fails, PHPStan is now happy with the code and my code passes level 9.
Here's the thing
Although the extra code gets PHPStan to pass, it it worth it?
Is this extra code adding value? Does it make the code more readable or is it likely to prevent a bug?
In this case, I know the value will always be the type I expect.
I can work around this using a baseline or annotations for PHPStan to ignore these lines, or is level 8 good enough for this project?
Similar to 100% test coverage, is aiming for the highest PHPStan level an objective to be met, or is enough value being added added by the lower level?
Which level is right for you and this codebase?
- Oliver
Was this interesting?
About me
I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.