withinboredom / common-records
Common scalar records
v0.2.0
2025-06-09 15:46 UTC
Requires
- withinboredom/records: ^0.1.0
Requires (Dev)
- laravel/pint: ^1.22
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.1
This package is auto-updated.
Last update: 2025-06-10 07:09:40 UTC
README
Install:
composer require withinboredom/common-records
This is a generated collection of common records (see generator.php).
Included:
- DateTime
- NegativeFloat
- NegativeInt
- NonNegativeInt
- NonZeroFloat
- NonZeroInt
- Percentage
- PositiveFloat
- PositiveInt
- AlphaNumericString
- AlphaString
- LowercaseString
- NonEmptyString
- Slug
- TrimmedString
- UppercaseString
Convention
- Every type is also created as a function of the same name.
- Every type implements
__invoke(): self
to extract the original value - Every type is strongly equal to another type of the same value (a record)
Example Usage
class User { public function __construct( public NonEmptyString $name, public PositiveInt $id, ) {} } $user = new User(NonEmptyString('Rob'), PositiveInt(123)) function getById(int $id) { /* do stuff */ } getById($user->id() /* call __invoke to get the integer value */);
Contributing
- Fork this repository.
- Add the new type to
generator.php
. - Execute
generator.php
and maybe add some tests. - Update the list in this readme.
- Open a PR.