phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
604 stars 48 forks source link

Add rule to disallow casting potential null values #225

Open leongersen opened 1 year ago

leongersen commented 1 year ago

Implements #224

I've borrowed the $treatPhpDocTypesAsCertain logic from UselessCastRule.

I'm ignoring mixed type, as that would be covered by PhpStan itself on level 9.

I kept the scope small: there are many more things that could be asserted about casts, such as:

I figured these cases would be better handled in other rule(s).