marcin-orlowski/type-asserts
A lightweight PHP library of type assertion helpers for Laravel and standalone projects, letting you validate values against expected types with simple, readable calls and clear failures.
Architecture fit
Illuminate\Validation for HTTP input, (2) PHP 8 native type declarations, union types, and enums for internal contracts, and (3) webmozart/assert / beberlei/assert, which are the de facto standard and are already transitively present in most Laravel installs via Symfony/Composer tooling. The package must therefore justify itself on ergonomics alone.Integration feasibility
composer require plus code review of one class.\InvalidArgumentException/\RuntimeException, Laravel's exception handler renders these as HTTP 500, not 422. That makes it unsafe at the HTTP boundary and confines it to the domain layer unless wrapped.@psalm-assert / @phpstan-assert annotations so the type is narrowed after the assertion. Without these, the library adds runtime checks but gives no IDE/PHPStan benefit — which materially changes the value case.Technical risk
webmozart/assert (already in the dependency tree) creates two idioms for one concern and splits code-review standards.Key questions
\InvalidArgumentException (catchable/mappable) or a package-specific base?@psalm-assert/@phpstan-assert annotations for type narrowing?composer.json PHP constraint — does it permit ^8.2/^8.3?false vs 0, empty array)?webmozart/assert, which is already transitively available and community-maintained?Stack fit
Rule object).Migration path
if (!is_string($x)) throw new InvalidArgumentException(...) guards and Assert:: calls, and route them through one idiom.App\Support\Asserts adapter (or interface) that delegates to the chosen library. This makes the third-party package an implementation detail and lets you swap to webmozart/assert, native typing, or a fork without touching call sites. Cost: ~half a day. Payoff: eliminates the vendor-lock and abandonment risk entirely.webmozart/assert in the same spike. Given zero dependents and a stale release, the migration path most likely to be recommended is "do not adopt; standardize on webmozart/assert or native types."Compatibility
ext-* or symfony/* bounds.bootstrap/app.php / Handler::render if any usage leaks near the HTTP layer.Sequencing
webmozart/assert.Maintenance
composer audit CI gate.Support
Scaling
Failure modes
0 vs false, empty arrays) that differs from webmozart/assert, producing inconsistent validation behavior across modules.Ramp-up
webmozart/assert plus native PHP 8 typing.How can I help you explore Laravel packages today?