Skip to content

Commit

Permalink
Apply early return to improve readability and prevent deep nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
alipadron authored and freekmurze committed Dec 11, 2024
1 parent 859db44 commit ffbf9fc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ protected function mutateAttributeForArray($key, $value): mixed

public function setAttribute($key, $value)
{
if ($this->isTranslatableAttribute($key)) {
if (is_array($value) && ! array_is_list($value)) {
return $this->setTranslations($key, $value);
}
return $this->setTranslation($key, $this->getLocale(), $value);
if (!$this->isTranslatableAttribute($key)) {
return parent::setAttribute($key, $value);
}

if (is_array($value) && ! array_is_list($value)) {
return $this->setTranslations($key, $value);
}

return parent::setAttribute($key, $value);
return $this->setTranslation($key, $this->getLocale(), $value);
}

public function translate(string $key, string $locale = '', bool $useFallbackLocale = true): mixed
Expand Down

0 comments on commit ffbf9fc

Please sign in to comment.