Conversation
WalkthroughThe PR modifies WikiClient initialization in SearchStructure to fetch locale configuration from a LocalesConfig lookup instead of using the user's default locale string directly, passing the configuration as an array to WikiClient while preserving the search result fetching flow. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/Src/UseCases/Domain/Context/Queries/SearchStructure.php (1)
7-7: UseLocalesConfig::getLocaleFromCode(and optionally guardAuth::user()) to avoid null casesThe change to pass a config array into
WikiClientis the right direction and matches theWikiClientconstructor. However, this lookup is a bit brittle:
LocalesConfig::whereCode(Auth::user()->default_locale)->first()will returnnullif:
- the user’s
default_localeincludes a country suffix (e.g.fr_FR) whileLocalesConfig.codestores onlyfr, or- no row exists yet for that code.
- Calling
$localeConfig->toArray()onnullwill then trigger a fatal error.Since
LocalesConfigalready exposesgetLocaleFromCode()with logic to:
- strip the country part from the code,
- choose a sensible default (and even prefer English), and
- throw a clear exception if the table is empty,
it’s safer to reuse that here. You may also want to defensively handle unauthenticated use (if this use case can ever be hit without a logged-in user).
For example:
use App\LocalesConfig; use App\Src\WikiClient; use Illuminate\Support\Facades\Auth; class SearchStructure { public function execute(string $search): array { - $localeConfig = LocalesConfig::whereCode(Auth::user()->default_locale)->first(); - $client = new WikiClient($localeConfig->toArray()); + $user = Auth::user(); + $preferredLocale = $user ? $user->default_locale : ''; + // Falls back and handles codes like "fr_FR" + $localeConfig = LocalesConfig::getLocaleFromCode($preferredLocale); + + $client = new WikiClient($localeConfig->toArray());If you’re certain that
default_localeis always a bare code present inlocales_configand that this use case is only ever called for authenticated users, then the current implementation is acceptable but more fragile than it needs to be. Please confirm those assumptions or consider the above refactor.Also applies to: 18-20
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/Src/UseCases/Domain/Context/Queries/SearchStructure.php(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Src/UseCases/Domain/Context/Queries/SearchStructure.php (2)
app/LocalesConfig.php (1)
LocalesConfig(11-73)app/Src/WikiClient.php (1)
WikiClient(10-103)
Fix #294
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.