Skip to content

Add non-zero int type#2449

Merged
ondrejmirtes merged 2 commits intophpstan:1.10.xfrom
PrinsFrank:add-non-zero-int
Jun 19, 2023
Merged

Add non-zero int type#2449
ondrejmirtes merged 2 commits intophpstan:1.10.xfrom
PrinsFrank:add-non-zero-int

Conversation

@PrinsFrank
Copy link
Copy Markdown
Contributor

For integers and floats that are used as divisors, a non-zero integer/float has to be used. This was easy to implement with integer ranges, but not easy for float ranges. How could we add that?

@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@PrinsFrank PrinsFrank changed the base branch from 1.11.x to 1.10.x June 10, 2023 21:06
@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, how common is to require all integers except zero? You can already express them today with int<min, -1>|int<1, max>.

As for floats - we don't have a FloatRangeType, it'd have to be added, and update all arithmetic operations in order to correctly calculate it.

@PrinsFrank
Copy link
Copy Markdown
Contributor Author

I've used that exact annotation in three different projects now, so I thought It'd be time to add an alias. If you don't think it's needed I can still use the full written form, I just thought it would be nice to have this alias.

Would you see value in adding float ranges? I would be happy to contribute something more and check if I can implement this in a new PR.

@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, yes, I see value in it, you can definitely try it out :) Thank you.

@ondrejmirtes ondrejmirtes merged commit 65ff783 into phpstan:1.10.x Jun 19, 2023
@PrinsFrank PrinsFrank deleted the add-non-zero-int branch January 11, 2024 12:28
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