Addition of two new assert functions for better validation of differe…
…nt integer types
Unfortunately, I had accidentally deleted the fork in my profile.
An older discussion can be found under the closed PR: https://github.com/webmozarts/assert/pull/297
@shadowhand
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, positive-int means > 0 but non-negative-int means ! < 0?
@Dropelikeit in any case, this would need to be rebased to current master.
@Dropelikeit so,
positive-intmeans> 0butnon-negative-intmeans! < 0?
@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, $value was undefined in the return value. I replaced the variable with the variable $classOrObject, as in the methodExist method.