From 7982c89598cb272e762201b0185f299067734e8c Mon Sep 17 00:00:00 2001 From: salarmotevalli Date: Wed, 13 Sep 2023 16:42:42 +0330 Subject: [PATCH 1/2] symplify if statments --- src/Traits/Favoriteable.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Traits/Favoriteable.php b/src/Traits/Favoriteable.php index 9dba3e1..fbf7b82 100644 --- a/src/Traits/Favoriteable.php +++ b/src/Traits/Favoriteable.php @@ -25,16 +25,16 @@ public function hasFavoriter(Model $user): bool public function hasBeenFavoritedBy(Model $user): bool { - if (\is_a($user, config('auth.providers.users.model'))) { - if ($this->relationLoaded('favoriters')) { - return $this->favoriters->contains($user); - } + if (! \is_a($user, config('auth.providers.users.model'))) { + return false; + } - return ($this->relationLoaded('favorites') ? $this->favorites : $this->favorites()) - ->where(\config('favorite.user_foreign_key'), $user->getKey())->count() > 0; + if ($this->relationLoaded('favoriters')) { + return $this->favoriters->contains($user); } - return false; + return ($this->relationLoaded('favorites') ? $this->favorites : $this->favorites()) + ->where(\config('favorite.user_foreign_key'), $user->getKey())->count() > 0; } public function favorites(): \Illuminate\Database\Eloquent\Relations\MorphMany @@ -52,4 +52,4 @@ public function favoriters(): \Illuminate\Database\Eloquent\Relations\BelongsToM ) ->where('favoriteable_type', $this->getMorphClass()); } -} +} \ No newline at end of file From 66682f992eaefe47a3d2a9e34443360dca515adc Mon Sep 17 00:00:00 2001 From: salarmotevalli Date: Wed, 13 Sep 2023 17:18:37 +0330 Subject: [PATCH 2/2] add return type for isFavaritedBy function --- src/Traits/Favoriteable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/Favoriteable.php b/src/Traits/Favoriteable.php index fbf7b82..6242d12 100644 --- a/src/Traits/Favoriteable.php +++ b/src/Traits/Favoriteable.php @@ -13,7 +13,7 @@ trait Favoriteable /** * @deprecated renamed to `hasBeenFavoritedBy`, will be removed at 5.0 */ - public function isFavoritedBy(Model $user) + public function isFavoritedBy(Model $user): bool { return $this->hasBeenFavoritedBy($user); } @@ -52,4 +52,4 @@ public function favoriters(): \Illuminate\Database\Eloquent\Relations\BelongsToM ) ->where('favoriteable_type', $this->getMorphClass()); } -} \ No newline at end of file +}