From ffbf9fcf85df81a53c69365a3ff27ac921c147ae Mon Sep 17 00:00:00 2001 From: Ali Padron Date: Mon, 9 Dec 2024 13:20:01 -0400 Subject: [PATCH] Apply early return to improve readability and prevent deep nesting --- src/HasTranslations.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/HasTranslations.php b/src/HasTranslations.php index 3f0282e..a5b8753 100644 --- a/src/HasTranslations.php +++ b/src/HasTranslations.php @@ -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