Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to disallow casting potential null values #225

Open
wants to merge 13 commits into
base: 1.5.x
Choose a base branch
from

Conversation

leongersen
Copy link

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 get 1.00, but should you want to?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants