Skip to content

Fix: evaluate#6

Merged
webard merged 2 commits intov3from
fix/evaluate
Feb 12, 2026
Merged

Fix: evaluate#6
webard merged 2 commits intov3from
fix/evaluate

Conversation

@webard
Copy link
Copy Markdown
Owner

@webard webard commented Feb 12, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 12, 2026 11:23
@webard webard merged commit 438caa2 into v3 Feb 12, 2026
@webard webard deleted the fix/evaluate branch February 12, 2026 11:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the FilamentTranslatablePlugin getters to evaluate closure-based configuration values (locales and default locale) at read time, aligning them with the existing evaluate() usage for other plugin options.

Changes:

  • getLocales() now evaluates $this->locales instead of returning the raw value.
  • getDefaultLocale() now evaluates $this->defaultLocale before falling back to config('app.fallback_locale', 'en').
  • Return types for both getters were narrowed to concrete evaluated values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +118 to 121
public function getLocales(): ?array
{
return $this->locales;
return $this->evaluate($this->locales);
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLocales() now evaluates $this->locales but returns array|null. If the configured closure returns an Illuminate\Support\Collection (e.g., Laravel pluck() as shown in the README), this will trigger a runtime TypeError because the method will return a Collection. Consider normalizing the evaluated value (convert Collection to array via all()) or widening the return type to include Collection.

Copilot uses AI. Check for mistakes.
@@ -115,9 +115,9 @@ public function getFlagWidth(): string
/**
* @return array<string>
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @return array<string> PHPDoc for getLocales() no longer matches the signature/behavior (array|null). Either update the docblock to include null or ensure the method always returns an array (e.g., default to []) to keep the contract consistent.

Suggested change
* @return array<string>
* @return array<string>|null

Copilot uses AI. Check for mistakes.
public function getDefaultLocale(): string
{
return $this->defaultLocale ?? config('app.fallback_locale', 'en');
return $this->evaluate($this->defaultLocale) ?? config('app.fallback_locale', 'en');
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDefaultLocale() is declared to return string, but config('app.fallback_locale', 'en') can still be null if the config key exists and is explicitly set to null. Add a final fallback (e.g., null-coalesce/empty check) so this method always returns a string and can’t throw a TypeError in that scenario.

Suggested change
return $this->evaluate($this->defaultLocale) ?? config('app.fallback_locale', 'en');
return $this->evaluate($this->defaultLocale)
?? config('app.fallback_locale')
?? 'en';

Copilot uses AI. Check for mistakes.
Comment on lines 118 to +132
@@ -127,8 +127,8 @@ public function defaultLocale(string | Closure $locale): static
return $this;
}

public function getDefaultLocale(): string | Closure
public function getDefaultLocale(): string
{
return $this->defaultLocale ?? config('app.fallback_locale', 'en');
return $this->evaluate($this->defaultLocale) ?? config('app.fallback_locale', 'en');
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both getLocales() and getDefaultLocale() have had their return types narrowed (previously allowed returning Closure, now array|null / string). Since these are public methods on the plugin, this is a backwards-incompatible API change for any consumers calling these getters directly. If BC is required, consider keeping the previous return types (or introducing new “evaluated” getters) and deprecating the old behavior.

Copilot uses AI. Check for mistakes.
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