Skip to content

Skip only the offending area when a locator entry is unusable - #35

Merged
stixx merged 2 commits into
mainfrom
fix/area-check-skips-remaining-areas
Aug 30, 2026
Merged

Skip only the offending area when a locator entry is unusable#35
stixx merged 2 commits into
mainfrom
fix/area-check-skips-remaining-areas

Conversation

@stixx

@stixx stixx commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Follow-up to #33 and #34 — spotted while reviewing those.

Problem

NelmioAreaRoutesChecker::matchesByRouteName() bailed out of the whole loop when a locator entry was not a RouteCollection:

foreach (array_keys($this->routesLocator->getProvidedServices()) as $area) {
    $routeCollection = $this->routesLocator->get($area);
    if (!$routeCollection instanceof RouteCollection) {
        return false;   // ← abandons every remaining area
    }
    ...
}

Areas are iterated in locator order, so one unusable entry hides every area after it. Routes in those areas would be reported as non-API, silently disabling OpenAPI request validation and RFC 7807 error responses for them.

Reachability — this is a defensive path, not a live bug

Checked against Nelmio 5.8: nelmio_api_doc.routes.{area} is always a RouteCollection, on both branches of NelmioApiDocExtension:

  • no filters configured → Definition(RouteCollection::class) with factory [router, 'getRouteCollection']
  • any filter configured → register(..., RouteCollection::class) with a FilteredRouteCollectionBuilder::filter factory

CollectNelmioApiDocRoutesPass also skips areas whose service is missing, so the locator only ever holds services that exist. Reaching the guard means someone has replaced or decorated nelmio_api_doc.routes.{area} with a non-RouteCollection — possible, but not something a stock setup hits.

So this is hardening a defensive branch, not fixing user-visible breakage. Merge it on the strength of the test change rather than any urgency.

Change

continue past the offending entry so the remaining areas are still checked. Kept as skip-and-continue rather than throwing: the guard is unreachable in normal operation, and turning an exotic-but-working setup into a hard failure is not worth it here.

Tests

The more valuable half. testNonRouteCollectionServiceCausesFalse asserted the old behaviour, and its fixture is the bug in miniature: would_match sits in the second area, the first entry is unusable, and the test asserted false — locking in a wrong invariant under a name that read as intentional. It now asserts the route is found, and is renamed to say what it covers.

Added testUnusableAreasAloneStillReturnFalse so the genuine false path stays pinned when nothing usable is on offer.

Verified the updated test fails against the old return false. 224 tests pass; PHPStan max and PHP-CS-Fixer clean.

matchesByRouteName() returned false as soon as a locator entry was not a
RouteCollection, abandoning every area after it. A single unusable entry
therefore made routes in later areas look like non-API routes, silently turning
off request validation and RFC 7807 error responses for them.

Continue past the bad entry instead. testNonRouteCollectionServiceCausesFalse
asserted the old behaviour with a fixture whose route sat in the very area that
went unchecked; it now asserts the route is found, with a companion test keeping
false for a locator that offers nothing usable at all.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 5 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 933732ee-f943-41c2-8f1e-9a4f8893f5ad

📥 Commits

Reviewing files that changed from the base of the PR and between 957df9c and ef7730f.

📒 Files selected for processing (2)
  • src/Routing/NelmioAreaRoutesChecker.php
  • tests/Unit/Routing/NelmioAreaRoutesTest.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@stixx
stixx merged commit bcc7480 into main Aug 30, 2026
6 checks passed
@stixx
stixx deleted the fix/area-check-skips-remaining-areas branch August 30, 2026 16:22
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.

1 participant