wikimedia/assert
A lightweight PHP assertion library from Wikimedia providing methods for parameter type checks, preconditions, postconditions and invariants. Enforce contracts and validate input in MediaWiki-style projects with clear, descriptive exceptions and no extra dependencies.
if (...) { throw new InvalidArgumentException(...) } blocks scattered across services. At ~100 LOC, "vendor into an internal app/Support package" is a legitimate third option worth scoring against adoption.Adopt when most of the following hold:
Look elsewhere when:
webmozart/assert is the better-known choice and pairs with PHPStan/Psalm assertion annotations; this package gives you runtime checks only.throw_if, throw_unless, abort_if, and a small custom exception hierarchy cover most of it with zero new dependencies.To executives: This is a tiny, MIT-licensed PHP utility that lets engineers declare and enforce the assumptions their code depends on, so bugs surface at the boundary instead of deep in the data layer. Cost of adoption is near zero and the license risk is nil. The honest caveat is that it carries no strategic weight: low adoption, no dependents, and a contribution workflow that runs through Wikimedia's Gerrit rather than GitHub. Recommendation: adopt it narrowly, behind an internal wrapper, if the team wants contract-style assertions as a standard — and do not let any roadmap item depend on it.
To engineering: It gives you explicit, greppable contract semantics — precondition, postcondition, parameter type, invariant — and a distinct exception type, which makes "this is a bug in the caller" obvious in logs. The trade-offs are real: it overlaps with Laravel's throw_if/throw_unless helpers and with webmozart/assert, it does nothing for static analysis, and it is the wrong tool for user input. Suggested path is a one-service spike, wrapped so the dependency stays swappable, judged on whether the contract vocabulary actually changes how the team reviews code — not on line count saved.
How can I help you explore Laravel packages today?