Skip to content

Conversation

@abhihyder
Copy link

Summary

This PR refactors repetitive logic in the Illuminate\Routing\RouteCollection class related to populating the $nameList lookup array. Previously, both refreshNameLookups() and addLookups() contained duplicated code for checking and assigning named routes to the lookup table.

✅ Improvements included in this PR:

  • Extracted name lookup logic into a dedicated addToNameLookup() method.
  • refreshNameLookups() now delegates to the new helper method.
  • Maintains existing behavior with zero breaking changes.
  • Supports better readability, extensibility, and single-responsibility adherence.

Why?

This cleanup:

  • Removes redundancy in the name lookup initialization logic.
  • Makes route registration code more maintainable.
  • Helps future customization or enhancements to named routing.

Before

Logic duplicated inside both:

  • addLookups()
  • refreshNameLookups()

After

Single clean implementation:

  • addLookups() → calls addToNameLookup()
  • refreshNameLookups() → calls addToNameLookup() during iteration
  • Ensures consistent behavior

Tests

No functional modifications, so no new tests were required. All existing route tests already pass with these changes.

@abhihyder abhihyder changed the title Refactor the duplicate code by extracting it into a reusable method. [12.x] Refactor the duplicate code by extracting it into a reusable method. Oct 25, 2025
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.

2 participants