Skip to content

Conversation

@emmadesilva
Copy link
Member

@emmadesilva emmadesilva commented May 11, 2025

Description

This PR improves the Routes facade API by renaming methods to better communicate their behavior:

  1. Renames Routes::get() (which returns null for missing routes) to Routes::find() to better indicate its trying to find, but is null safe
  2. Renames Routes::getOrFail() to Routes::get() to make the exception-throwing behavior the default

Benefits:

  • More predictable API: get() now fails fast with clear exceptions, matching Laravel conventions
  • More descriptive naming: find() indicates it may return null
  • Complete type safety: find() returns ?Route, get() returns Route

Breaking changes:

  • Code using Routes::get('some-route') needs to be updated to Routes::find('some-route') if it needs to handle missing routes nullably
  • Code using Routes::getOrFail('some-route') needs to be updated to Routes::get('some-route')

Migration guide:

// Old code:
$route = Routes::get('some-route'); // Returns null if not found
$route = Routes::getOrFail('some-route'); // Throws exception if not found

// New code:
$route = Routes::find('some-route'); // Returns null if not found
$route = Routes::get('some-route'); // Throws exception if not found

All internal uses have been updated to use the new method names.

Relations:

@emmadesilva emmadesilva changed the title [2.x] Invert route helper methods for improved developer flow [2.x] Improve Routes facade method naming with tryGet() and get() May 11, 2025
@emmadesilva emmadesilva force-pushed the improve-route-helper-methods branch from 5a49a91 to ea8455f Compare May 11, 2025 16:43
@emmadesilva emmadesilva changed the title [2.x] Improve Routes facade method naming with tryGet() and get() [2.x] Improve Routes facade method naming with find() and get() May 11, 2025
@codecov
Copy link

codecov bot commented May 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3407099) to head (f8537d4).
Report is 5 commits behind head on 2.x-dev.

Additional details and impacted files
@@             Coverage Diff             @@
##             2.x-dev     #2179   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity      1969      1969           
===========================================
  Files            198       198           
  Lines           5265      5265           
===========================================
  Hits            5265      5265           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@emmadesilva emmadesilva merged commit 3cc7af9 into 2.x-dev May 11, 2025
19 checks passed
@emmadesilva emmadesilva deleted the improve-route-helper-methods branch May 11, 2025 16:53
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