-
Notifications
You must be signed in to change notification settings - Fork 152
Add isNegativeInteger and notNegativeInteger #301
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 isNegativeInteger and notNegativeInteger #301
Conversation
|
Unfortunately, I had accidentally deleted the fork in my profile. An older discussion can be found under the closed PR: #297 |
shadowhand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a duplicate of positiveInteger and notPositiveInteger?
|
Not directly, notNegativeInt simply checks whether it is 0 or greater than 0 to definitively avoid it being a negative integer. With this assert, as with the other assert functions, Psalm directly understands that the number can never be negative. In the other case, negative-int, Psalm should understand that the given integer can never be 0 (neutral) or positive. That is my goal with this PR here, a small clarification that Psalm would then also understand: class MyObject {
/**
* @psalm-param non-negative-int $age
*/
public function __construct(private readonly $age)
{
}
public static function create(int $age): self
{
Assert::nonNegativeInteger($age);
return new self($age);
}
/**
* @psalm-return non-negative-int
*/
public function getAge(): int
{
return $this->age;
} |
|
@Dropelikeit so, |
|
@Dropelikeit in any case, this would need to be rebased to current master. |
…ive-integer-asserts # Conflicts: # CHANGELOG.md # src/Assert.php # src/Mixin.php # tests/AssertTest.php
…in static analysis tests
@shadowhand Exactly. 0 (zero) is neither positive nor negative. Non-negative is similar to positive-int, but also includes zero. The only difference is that negative numbers are excluded here. I have rebased my branch so that there are no more conflicts. I have also fixed a small bug in the Assert.php file. In the propertyExists method, |
…e, non-negative, and negative integer asserts
…codebase for consistency
shadowhand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more small fix, then looks good.
…iveInteger` addition
No description provided.