refactor(api): HttpStatus single-source for HTTP codes#231
Open
biz87 wants to merge 2 commits into
Open
Conversation
Introduce MiniShop3\Router\HttpStatus; Response aliases it and uses explicit nullable/mixed signatures. Replace literal status codes in API Response::error call sites. OrdersController keeps msOrderProduct lifecycle events from the parent branch with named constants for HTTP statuses.
…orts, cover all used codes Address review feedback on PR #209 (which was auto-closed when its base branch was merged). Changes since the original 60dfb6a refactor: - HttpStatus is the single source of truth for HTTP codes. Drop the Response::HTTP_* re-exports — every call site now imports HttpStatus directly. - Add the codes the codebase actually emits but were left as literals: CREATED (201), UNAUTHORIZED (401), METHOD_NOT_ALLOWED (405), CONFLICT (409), UNPROCESSABLE_ENTITY (422), TOO_MANY_REQUESTS (429), SERVICE_UNAVAILABLE (503). - Replace the remaining numeric literals across controllers, middleware and routes with the matching HttpStatus constants. - Insert the use statement alphabetically between the existing MiniShop3\Router imports. - Pick up the literal 400/500 codes added to OrdersController by the msOrderProduct events fix (PR #208 v2) and merge-conflict-resolve the three after-event blocks in favour of the new WARN-log behaviour introduced there. PHPStan clean on touched files (3 closure.unusedUse warnings in config/routes/web.php are pre-existing on beta — that path is outside the default analyse scope).
This was referenced Apr 26, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Контекст
Восстановление #209, который автоматически закрылся, когда его base-ветку (
fix/gh-207-manager-order-product-events) удалили при мерже #208 вbeta. Reopen GitHub отказал — пришлось пересобрать веткой и открыть свежий PR. Тред старого ревью читается в #209.Что внутри
Два коммита:
f9af467(от @Ibochkarev) — оригинальный refactor из refactor(api): HttpStatus and Response HTTP_* constants #209, ребейзнутый на актуальныйbeta. Конфликты вOrdersController.php(after-event блоки) разрешены в пользу WARN-log поведения, введённого PR fix(manager): invoke msOrderProduct lifecycle events in Manager API #208 v2.7ae99d9— правки по ревью refactor(api): HttpStatus and Response HTTP_* constants #209:HttpStatusостаётся,Response::HTTP_*re-exports удалены. Везде толькоHttpStatus::*.OK/BAD_REQUEST/NOT_FOUND/INTERNAL_SERVER_ERRORдобавлены:CREATED(201),UNAUTHORIZED(401),METHOD_NOT_ALLOWED(405),CONFLICT(409),UNPROCESSABLE_ENTITY(422),TOO_MANY_REQUESTS(429),SERVICE_UNAVAILABLE(503) — ровно те, что реально эмитит кодовая база, без YAGNI.OptionsController,ModelFieldsController,CategoryOptionsController,CartController,CustomerAddressController,CustomerOrderController,OrderController), middleware (AuthMiddleware,TokenMiddleware,ServiceCheckMiddleware,RateLimitMiddleware) и вRouter::dispatch()(405).use MiniShop3\Router\HttpStatus;добавлен в 27 файлов алфавитно передuse MiniShop3\Router\Response;. ГдеHttpStatusв том же namespace (Router/Router.php) — без импорта.Тип изменений
MiniShop3\Router\HttpStatus, ноResponse::HTTP_*константы, существовавшие в refactor(api): HttpStatus and Response HTTP_* constants #209, удалены — наружу до мержа они не уходили, поэтому фактически ломать нечего.Тестирование
closure.unusedUseвconfig/routes/web.phppre-existing наbeta(этот путь вне defaultanalyse-scope вphpstan.neon).Размер
30 файлов, +422/−370. Большой, но механический —
Response::HTTP_X→HttpStatus::X+ добавление импортов + замена литералов. Риск регрессии минимальный.Связанные
beta, конфликты с ним разрешены при ребейзе.