juststeveking/http-status-code
PHP package that turns HTTP status codes into a typed enum, with helpers for messages, code categories and Laravel validation. Replace magic numbers with descriptive cases for clearer, safer API and controller responses—no more guessing what 418 means.
composer require and a ^3.0 constraint. But the outcome is equally reachable by copying the enum internally or standardizing on Laravel/Symfony's Response::HTTP_*. Frame the decision as convention selection, not vendor selection; mixing conventions is worse than either choice.UNPROCESSABLE_ENTITY, IM_A_TEAPOT) cut review time spent decoding numbers and give static analysis something to check. A real but small productivity signal — use it to justify convention work, not headcount.Adopt it when:
^3.0 and treat 1.x → 2.x → 3.x as the only upgrade events worth reviewing.match support, type hints, and validation in a small, reversible, low-blast-radius change.Look elsewhere, or copy the enum internally, when:
symfony/http-foundation already ships Response::HTTP_*. A reviewer will reasonably ask why a constants list is a Composer dependency. This is the default answer for most Laravel shops and the decision is reversible in an afternoon.Retry-After companions). Backed enums cannot be extended — you must wrap, and at that point you own a class anyway.Executives (one paragraph, no procurement): This is a tiny, MIT-licensed convenience library that gives our PHP services a single, named vocabulary for HTTP status codes. Cost is effectively zero, runtime risk is negligible, and it removes a recurring class of inconsistency bugs in API responses and error contracts. The honest caveats: Laravel and Symfony already ship equivalent constants, the same result is achievable with roughly 50 lines of internal code, and the project is low-activity — 49 stars, zero downstream dependents, and a latest release (3.0.2) that is a minor patch with no new capability. Recommendation: delegate to engineering as a developer-convenience choice inside an API-conventions effort; no vendor review, no budget line, no roadmap slot. The decision is reversible in an afternoon, which is precisely why it should not consume planning cycles.
Engineering (the working brief): It is an enum of HTTP status codes with IANA-style case names — typed, autocompletable, static-analysis friendly, framework-agnostic, no service provider, no config, no container binding. Three integration patterns pay off: (1) enum cases at the response boundary in controllers; (2) a statusMap array in the exception handler mapping domain exceptions to cases; (3) a status(): HttpStatusCode method on domain exceptions so they are self-describing and testable without the framework. Guardrails: it is an enum, not an int — response()->json() and === comparisons need ->value, so run PHPStan/Larastan at a reasonable level; use tryFrom() and branch on null for dynamic codes, never from(), which turns bad input into a 500; reason phrases are English and not localised, so keep user-facing copy in lang files; and pick this enum or Response::HTTP_* project-wide — don't mix.
How can I help you explore Laravel packages today?