forked from eatvio/eatvio-infra
refactoring static analyse code
This commit is contained in:
@@ -12,6 +12,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* App\Models\Recipe
|
||||
@@ -93,26 +95,16 @@ class Recipe extends Model implements Viewable
|
||||
// ->doNotGenerateSlugsOnUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route key for the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRouteKeyName()
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
public function tags()
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
/* public function author() */
|
||||
/* { */
|
||||
/* return $this->belongsToMany(User::class, 'recipe_author', 'recipe_id', 'user_id'); */
|
||||
/* } */
|
||||
|
||||
public function author(): HasOneThrough
|
||||
{
|
||||
return $this
|
||||
@@ -126,7 +118,7 @@ class Recipe extends Model implements Viewable
|
||||
);
|
||||
}
|
||||
|
||||
public function comments()
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(RecipeComment::class);
|
||||
}
|
||||
@@ -136,17 +128,17 @@ class Recipe extends Model implements Viewable
|
||||
return $this->hasMany(RecipeLike::class);
|
||||
}
|
||||
|
||||
public function scopeNegativeComments(Builder $query)
|
||||
public function scopeNegativeComments(Builder $query): Builder
|
||||
{
|
||||
return static::comments()->where('grade', '<=', '3');
|
||||
}
|
||||
|
||||
public function scopePositiveComments(Builder $query)
|
||||
public function scopePositiveComments(Builder $query): Builder
|
||||
{
|
||||
return static::comments()->where('grade', '>', '3');
|
||||
}
|
||||
|
||||
public function isLiked(): bool
|
||||
public function isLiked(): bool|int
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
@@ -156,7 +148,7 @@ class Recipe extends Model implements Viewable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeLike(): bool
|
||||
public function removeLike(): bool|int
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
@@ -166,7 +158,7 @@ class Recipe extends Model implements Viewable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function scopeContainsTag($query, $tagString): Builder
|
||||
public function scopeContainsTag(Builder $query, string $tagString): Builder
|
||||
{
|
||||
$tagId = Str::of($tagString)->split('/-/')->first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user