Skip to content

refactor(api): HttpStatus single-source for HTTP codes#231

Open
biz87 wants to merge 2 commits into
betafrom
refactor/http-status-response-constants
Open

refactor(api): HttpStatus single-source for HTTP codes#231
biz87 wants to merge 2 commits into
betafrom
refactor/http-status-response-constants

Conversation

@biz87
Copy link
Copy Markdown
Member

@biz87 biz87 commented Apr 26, 2026

Не для патч-релиза. Готов к мержу в момент следующего минорного релиза. До тех пор лежит open как ready-to-go.

Контекст

Восстановление #209, который автоматически закрылся, когда его base-ветку (fix/gh-207-manager-order-product-events) удалили при мерже #208 в beta. Reopen GitHub отказал — пришлось пересобрать веткой и открыть свежий PR. Тред старого ревью читается в #209.

Что внутри

Два коммита:

  1. 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.

  2. 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) — без импорта.

Тип изменений

  • Рефакторинг (без изменения функциональности)
  • Breaking change — формально появляется новый публичный класс MiniShop3\Router\HttpStatus, но Response::HTTP_* константы, существовавшие в refactor(api): HttpStatus and Response HTTP_* constants #209, удалены — наружу до мержа они не уходили, поэтому фактически ломать нечего.

Тестирование

  • PHPStan на затронутых 26 PHP-файлах — 0 новых ошибок. Существующие 3 closure.unusedUse в config/routes/web.php pre-existing на beta (этот путь вне default analyse-scope в phpstan.neon).
  • Ручная проверка API endpoints — желательно перед мержем.
  • CHANGELOG обновить при подготовке минор-релиза.

Размер

30 файлов, +422/−370. Большой, но механический — Response::HTTP_XHttpStatus::X + добавление импортов + замена литералов. Риск регрессии минимальный.

Связанные

Ibochkarev and others added 2 commits April 27, 2026 01:07
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants