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

Implement InvalidDivisionOperationRule #3417

Closed
wants to merge 1 commit into from
Closed

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 7, 2024

@ondrejmirtes
Copy link
Member

There is already InvalidBinaryOperationRule so we don't need a new rule: https://phpstan.org/r/42eed56b-0bb3-42b9-8f97-8c53752c4d35

@VincentLanglet
Copy link
Contributor

Also, exception checks about DivisionByZeroError already covering this case.
It require

  • Either to catch the DivisionByZeroError
  • Either to add it to the phpdoc

https://phpstan.org/r/06bc1121-7847-4c30-9d19-59c34c9369a0

Adding a new rule will create a duplicate and false positive since

	/**
	 * @throws DivisionByZeroError
	 */
	public function sayHello2(int $i, int $j): void
	{
		echo $i / $j; // Not error it's documented
	}

is fully valid code.

@staabm
Copy link
Contributor Author

staabm commented Sep 8, 2024

thanks for pointing this out.

You have to enable "missingCheckedExceptionInThrows", "DivisionByZeroError"

I don't think coverage for a division-by-zero error should be a opt-in thing and "hidden" in the config file.

There is already InvalidBinaryOperationRule

@ondrejmirtes wdyt about adding the logic of this PR into InvalidBinaryOperationRule (or the type system) while checking the config whether DivisionByZeroError was configured as missingCheckedExceptionInThrows to prevent duplicate errors?

@staabm
Copy link
Contributor Author

staabm commented Sep 8, 2024

submitted a alternative impl as a base for discussion: #3419

@staabm staabm closed this Sep 10, 2024
@staabm staabm deleted the div branch September 10, 2024 12:00
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.

3 participants