phpstan-strict-rules
phpstan-strict-rules copied to clipboard
Add rule to disallow casting potential null values
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:
- Casting floats to ints, this should probably use
round
/floor
/ceil
instead; - Objects cannot be cast to int/string/float, but they can be cast to array;
- Many casts are nonsensical. Yes, you can
(float)[2.00,2.00]
and get1.00
, but should you want to?
I figured these cases would be better handled in other rule(s).