Closed Dropelikeit closed 4 months ago
I guess you are missing a positiveInteger
check?
@loevgaard that one exists already
@loevgaard sorry, I think the naming is poorly chosen. Maybe it is wise to rename the nonNegativeInteger
to unsignedInteger
, because it should only be checked if the value is 0 or higher.
What do you think?
@loevgaard that one exists already
Didn't know that :)
@loevgaard sorry, I think the naming is poorly chosen. Maybe it is wise to rename the nonNegativeInteger to unsignedInteger, because it should only be checked if the value is 0 or higher. What do you think?
I think nonNegativeInteger
is the way to go because that's what's used in other places, .e.g https://psalm.dev/docs/annotating_code/type_syntax/scalar_types/
@loevgaard The psalm was the motivation to write this pull request. I think it would be great if this missing implementation could be added to make such checks so that Psalm understands the variables correctly:
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;
}
}
Yeah, exactly. Makes a lot of sense :)
To complete the integer checks,
nonNegativeInteger
andnegativeInteger
checks have been added.This PR belongs to the ticket https://github.com/webmozarts/assert/issues/296