From bc2c8df9afa49c0610df3363e61e51cf9ccf4efb Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Mon, 15 Jan 2024 01:05:10 +0300 Subject: [PATCH] make static-analyse code --- .../Fortify/UpdateUserProfileInformation.php | 3 +- app/Console/Commands/UpdateSlugs.php | 3 +- app/Events/ChatMessageUpdated.php | 2 +- app/Livewire/Chat/LastUsers.php | 14 ++-- app/Livewire/Chat/MessageWindow.php | 30 ++++---- app/Livewire/Chat/Tracker.php | 15 ++-- app/Livewire/Consultant/ListConsultants.php | 3 +- app/Livewire/Counter.php | 9 ++- app/Livewire/Diary/ConsultantCommentsEdit.php | 33 ++++---- app/Livewire/Diary/MealPhotos.php | 7 +- app/Livewire/Feed/Index.php | 5 +- app/Livewire/Forms/ProfileEditDetailzForm.php | 50 ++++++------ app/Livewire/MealForm.php | 46 ++++++----- app/Livewire/PortionShow.php | 3 +- app/Livewire/Profile/EditDetailzForm.php | 4 +- app/Livewire/TagsComponent.php | 11 ++- app/Models/BlogPost.php | 2 +- app/Models/Chat.php | 7 +- app/Models/CircumferenceMeasure.php | 3 +- app/Models/ConsultantEducation.php | 3 +- app/Models/Diary.php | 11 ++- app/Models/Meal.php | 11 ++- app/Models/Portion.php | 3 +- app/Models/Tag.php | 2 +- app/Models/UserAttachment.php | 9 ++- app/Models/UserDetailz.php | 3 +- app/Models/WeightMeasure.php | 3 +- .../ConsultantRequestStarted.php | 2 +- app/Rules/MinWords.php | 8 +- app/Services/FeedService.php | 77 +++++++++++-------- config/rich-text-laravel.php | 2 +- config/state-machine.php | 2 +- database/factories/ProductGroupFactory.php | 1 + database/factories/UserFactory.php | 2 +- ...reate_product_nutritional_values_table.php | 14 +--- 35 files changed, 221 insertions(+), 182 deletions(-) diff --git a/app/Actions/Fortify/UpdateUserProfileInformation.php b/app/Actions/Fortify/UpdateUserProfileInformation.php index 47e8e62..d9c3d13 100644 --- a/app/Actions/Fortify/UpdateUserProfileInformation.php +++ b/app/Actions/Fortify/UpdateUserProfileInformation.php @@ -7,13 +7,14 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; +use Illuminate\Http\UploadedFile; class UpdateUserProfileInformation implements UpdatesUserProfileInformation { /** * Validate and update the given user's profile information. * - * @param array $input + * @param array $input */ public function update(User $user, array $input): void { diff --git a/app/Console/Commands/UpdateSlugs.php b/app/Console/Commands/UpdateSlugs.php index d02a4ac..3871634 100644 --- a/app/Console/Commands/UpdateSlugs.php +++ b/app/Console/Commands/UpdateSlugs.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use App\Models\Recipe; use Illuminate\Console\Command; +use Illuminate\Support\Str; class UpdateSlugs extends Command { @@ -24,7 +25,7 @@ class UpdateSlugs extends Command /** * Execute the console command. */ - public function handle() + public function handle(): void { Recipe::where('slug', '') ->get() diff --git a/app/Events/ChatMessageUpdated.php b/app/Events/ChatMessageUpdated.php index 61a859b..3838763 100644 --- a/app/Events/ChatMessageUpdated.php +++ b/app/Events/ChatMessageUpdated.php @@ -12,7 +12,7 @@ class ChatMessageUpdated implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; - public $message; + public array $message; /** * Create a new event instance. diff --git a/app/Livewire/Chat/LastUsers.php b/app/Livewire/Chat/LastUsers.php index 3330329..9902383 100644 --- a/app/Livewire/Chat/LastUsers.php +++ b/app/Livewire/Chat/LastUsers.php @@ -3,23 +3,25 @@ namespace App\Livewire\Chat; use Livewire\Component; +use Illuminate\View\View; +use Illuminate\Support\Collection; class LastUsers extends Component { - public $lastChatUsers; + public Collection $lastChatUsers; - public $activeUserId; + public int|null $activeUserId = null; - public $curUserId; + public int $curUserId; - public $chanId; + public string $chanId; - public function render() + public function render(): View { return view('livewire.chat.last-users'); } - public function switchTo($id) + public function switchTo(int $id): void { $this->activeUserId = $id; $this->dispatch('updateRecipientId', id: $id)->to('chat.message-window'); diff --git a/app/Livewire/Chat/MessageWindow.php b/app/Livewire/Chat/MessageWindow.php index 29b5d26..7e3adfd 100644 --- a/app/Livewire/Chat/MessageWindow.php +++ b/app/Livewire/Chat/MessageWindow.php @@ -6,24 +6,26 @@ use App\Events\ChatMessageUpdated; use App\Models\Chat; use App\Models\User; use Livewire\Component; +use Illuminate\View\View; +use Illuminate\Support\Collection; class MessageWindow extends Component { - public $messages = []; + public array|Collection $messages = []; - public $curMessage = ''; + public string $curMessage = ''; - public $curUserId; + public int $curUserId; - public $recipientUserId; + public int|null $recipientUserId = null; - public $recipientUser; + public User|null $recipientUser = null; - public $chanId; + public string $chanId; - public $curUser; + public User $curUser; - public function getListeners() + public function getListeners(): array { return [ 'echo-private:direct-chat.'.$this->chanId.',ChatMessageUpdated' => 'notifyNewMessage', @@ -33,7 +35,7 @@ class MessageWindow extends Component ]; } - public function notifyNewMessage($e): void + public function notifyNewMessage(array $e): void { $message = $e['message']; @@ -41,11 +43,11 @@ class MessageWindow extends Component ->prepend($message); } - public function updateRecipientId($id = null) + public function updateRecipientId(int $id = null): void { } - public function whisperTypeing() + public function whisperTypeing(): void { $this->dispatch( 'typing', @@ -58,7 +60,7 @@ class MessageWindow extends Component } // FIXME - public function mount($recipientUserId) + public function mount(int $recipientUserId = null): void { $this->recipientUserId = $recipientUserId; $this->recipientUser = User::find($recipientUserId); @@ -74,12 +76,12 @@ class MessageWindow extends Component } } - public function render() + public function render(): View { return view('livewire.chat.message-window'); } - public function sendChatMessage() + public function sendChatMessage(): void { $chatMessage = [ 'data' => $this->curMessage, diff --git a/app/Livewire/Chat/Tracker.php b/app/Livewire/Chat/Tracker.php index e5274f9..0f82582 100644 --- a/app/Livewire/Chat/Tracker.php +++ b/app/Livewire/Chat/Tracker.php @@ -3,23 +3,26 @@ namespace App\Livewire\Chat; use Livewire\Component; +use Illuminate\View\View; class Tracker extends Component { - public $showNewMessageNotifycation = false; + public int|bool $showNewMessageNotifycation = false; - public $myMessages = []; + public array $myMessages = []; - // Special Syntax: ['echo:{channel},{event}' => '{method}'] - protected $listeners = ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; + protected function getListeners(): array + { + return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; + } - public function notifyNewMessage($payload): void + public function notifyNewMessage(string $payload): void { $this->myMessages[] = $payload; $this->showNewMessageNotifycation = true; } - public function render() + public function render(): View { return view('livewire.chat.tracker'); } diff --git a/app/Livewire/Consultant/ListConsultants.php b/app/Livewire/Consultant/ListConsultants.php index f4d9be6..b41bae6 100644 --- a/app/Livewire/Consultant/ListConsultants.php +++ b/app/Livewire/Consultant/ListConsultants.php @@ -4,10 +4,11 @@ namespace App\Livewire\Consultant; use App\Models\ConsultantEducation; use Livewire\Component; +use Illuminate\View\View; class ListConsultants extends Component { - public function render() + public function render(): View { return view( 'livewire.consultant.list-consultants', diff --git a/app/Livewire/Counter.php b/app/Livewire/Counter.php index 4ea663a..86d0f66 100644 --- a/app/Livewire/Counter.php +++ b/app/Livewire/Counter.php @@ -3,22 +3,23 @@ namespace App\Livewire; use Livewire\Component; +use Illuminate\View\View; class Counter extends Component { - public $count = 0; + public int $count = 0; - public function inc() + public function inc(): void { $this->count++; } - public function dec() + public function dec(): void { $this->count--; } - public function render() + public function render(): View { return view('livewire.counter'); } diff --git a/app/Livewire/Diary/ConsultantCommentsEdit.php b/app/Livewire/Diary/ConsultantCommentsEdit.php index 5cfaea8..eb5ddd9 100644 --- a/app/Livewire/Diary/ConsultantCommentsEdit.php +++ b/app/Livewire/Diary/ConsultantCommentsEdit.php @@ -3,36 +3,39 @@ namespace App\Livewire\Diary; use App\Models\ConsultantDiaryComment; +use App\Models\Diary; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Collection; +use Illuminate\View\View; use Livewire\Component; class ConsultantCommentsEdit extends Component { - public $daysCount; + public int $daysCount; - public $diary; + public Diary $diary; - public $curMeals; + public array|Collection $curMeals = []; - public $typeNames; + public array $typeNames; - public $comments = []; + public array $comments = []; - public $retireComment = ''; + public string $retireComment = ''; - public $breakfastComment = ''; + public string $breakfastComment = ''; - public $dinnerComment = ''; + public string $dinnerComment = ''; - public $supperComment = ''; + public string $supperComment = ''; - public $lunchComment = ''; + public string $lunchComment = ''; - public $snacksComment = ''; + public string $snacksComment = ''; - public $totalComment = ''; + public string $totalComment = ''; - public function mount() + public function mount(): void { $this->comments = (new ConsultantDiaryComment())->where( 'user_id', @@ -43,7 +46,7 @@ class ConsultantCommentsEdit extends Component )->pluck('comment', 'comment_type')->toArray(); } - public function render() + public function render(): View { $commentTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks', 'wakeup_time', 'total']; @@ -55,7 +58,7 @@ class ConsultantCommentsEdit extends Component ); } - public function save() + public function save(): void { foreach ($this->comments as $key => $comment) { $updateComment = ConsultantDiaryComment::updateOrCreate( diff --git a/app/Livewire/Diary/MealPhotos.php b/app/Livewire/Diary/MealPhotos.php index 8c8f039..5799b27 100644 --- a/app/Livewire/Diary/MealPhotos.php +++ b/app/Livewire/Diary/MealPhotos.php @@ -7,6 +7,7 @@ use App\Models\UserAttachment; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\View\View; class MealPhotos extends Component { @@ -14,9 +15,9 @@ class MealPhotos extends Component public Meal $meal; - public $tmpMealPhotos = []; + public array $tmpMealPhotos = []; - public function render() + public function render(): View { return view( 'livewire.diary.meal-photos', @@ -26,7 +27,7 @@ class MealPhotos extends Component ); } - public function updatedTmpMealPhotos($values) + public function updatedTmpMealPhotos(array $values): void { /* dd($values); */ $newPhotos = collect($values)->take(3); diff --git a/app/Livewire/Feed/Index.php b/app/Livewire/Feed/Index.php index ee3d22f..01cf91a 100644 --- a/app/Livewire/Feed/Index.php +++ b/app/Livewire/Feed/Index.php @@ -3,12 +3,13 @@ namespace App\Livewire\Feed; use Livewire\Component; +use Illuminate\View\View; class Index extends Component { - public $posts; + public array $posts; - public function render() + public function render(): View { return view('livewire.feed.index'); } diff --git a/app/Livewire/Forms/ProfileEditDetailzForm.php b/app/Livewire/Forms/ProfileEditDetailzForm.php index 43c36a1..4a1b3aa 100644 --- a/app/Livewire/Forms/ProfileEditDetailzForm.php +++ b/app/Livewire/Forms/ProfileEditDetailzForm.php @@ -11,75 +11,75 @@ class ProfileEditDetailzForm extends Form public ?UserDetailz $userDetailz; #[Rule('required|string|min:3')] - public $first_name; + public string $first_name; #[Rule('required|string|min:3')] - public $last_name; + public string $last_name; #[Rule('required|email')] - public $email; + public string $email; #[Rule('required|in:male,female')] - public $gender; + public string $gender; #[Rule('required|date')] - public $birthdate; + public string $birthdate; #[Rule('required|string|min:3')] - public $country; + public string $country; #[Rule('required|string|min:3')] - public $city; + public string $city; #[Rule('required|string|min:3')] - public $lang; + public string $lang; #[Rule('required|integer|min:35')] - public $weight; + public int $weight; #[Rule('required|integer|min:35')] - public $height; + public int $height; #[Rule('required|integer|min:20')] - public $chest_circumference; + public int $chest_circumference; #[Rule('required|integer|min:20')] - public $waist_circumference; + public int $waist_circumference; #[Rule('required|integer|min:20')] - public $hip_circumference; + public int $hip_circumference; #[Rule('required|integer|min:20')] - public $blood_pressure_up; + public int $blood_pressure_up; #[Rule('required|integer|min:20')] - public $blood_pressure_down; + public int $blood_pressure_down; #[Rule('required|boolean')] - public $has_hypo; + public int|bool $has_hypo; #[Rule('required|boolean')] - public $has_hyper; + public int|bool $has_hyper; #[Rule('nullable')] - public $about_alergy = 'nullable'; + public string $about_alergy = 'nullable'; #[Rule('nullable')] - public $about_taking_pils = 'nullable'; + public string $about_taking_pils = 'nullable'; #[Rule('nullable')] - public $about_sport_hobbies = 'nullable'; + public string $about_sport_hobbies = 'nullable'; #[Rule('nullable')] - public $favorite_foods = 'nullable'; + public string $favorite_foods = 'nullable'; #[Rule('nullable')] - public $unfavorite_foods = 'nullable'; + public string $unfavorite_foods = 'nullable'; #[Rule('nullable')] - public $additional_info = 'nullable'; + public string $additional_info = 'nullable'; - public function setDetailz(UserDetailz $detailz) + public function setDetailz(UserDetailz $detailz): void { $this->userDetailz = $detailz; $this->first_name = $detailz->first_name; @@ -107,7 +107,7 @@ class ProfileEditDetailzForm extends Form $this->additional_info = $detailz->additional_info; } - public function update() + public function update(): void { $this->userDetailz->update( $this->except(['userDetailz', 'email']) diff --git a/app/Livewire/MealForm.php b/app/Livewire/MealForm.php index a3e060b..2ee4efa 100644 --- a/app/Livewire/MealForm.php +++ b/app/Livewire/MealForm.php @@ -6,44 +6,48 @@ use App\Models\Diary; use App\Models\Meal; use App\Models\Portion; use Livewire\Component; +use Illuminate\View\View; class MealForm extends Component { - public $time; + public string $time; - public $type = 0; + public int $type = 0; - public $satiety = 3; + public int $satiety = 3; - public $mood = 3; + public int $mood = 3; - public $product_name; + public string $product_name; - public $portions; + public array $portions; - public $quantity; + public string $quantity; - public $pcs; + public string $pcs; - public $unit; + public string $unit; - public $diaryId; + public int $diaryId; public Diary $diary; public Meal $meal; - public $portion; + public string $portion; - protected $rules = [ + protected array $rules = [ 'product_name' => 'required|min:3', 'quantity' => 'required', 'portion' => 'required|min:1', ]; - protected $listeners = ['food-intake-updated' => '$refresh']; + protected function getListeners(): array + { + return ['food-intake-updated' => '$refresh']; + } - public function mount() + public function mount(): void { $this->diary = Diary::find($this->diaryId); $curMeal = $this->diary->meals->where('type', 0)->first(); @@ -65,7 +69,7 @@ class MealForm extends Component $this->portions = $curPortions; } - public function updatingType($value) + public function updatingType(int $value): void { $curMeal = $this->diary->meals->where('type', $value)->first(); $this->satiety = $curMeal->satiety ?? 3; @@ -73,7 +77,7 @@ class MealForm extends Component $this->time = $curMeal->time ?? now()->setTimezone('3')->format('H:i'); } - public function render() + public function render(): View { $types = [0, 1, 2, 3, 4]; $typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы']; @@ -99,7 +103,7 @@ class MealForm extends Component $this->type = $type; } - public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion) + public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion): void { $this->addPortionIfItFilled(); @@ -142,7 +146,7 @@ class MealForm extends Component $this->dispatch('food-intake-updated')->self(); } - public function addPortion() + public function addPortion(): void { $this->validate(); @@ -159,7 +163,7 @@ class MealForm extends Component $this->reset(['product_name', 'quantity', 'portion']); } - public function editPortion($key, $item) + public function editPortion(int $key, array $item): void { $filed = [ 'product_name' => $item['product_name'], @@ -170,7 +174,7 @@ class MealForm extends Component $this->fill($filed); } - public function delPortion($key, $item) + public function delPortion(int $key, array $item): void { if (isset($item['id'])) { Portion::find($item['id'])->delete(); @@ -186,7 +190,7 @@ class MealForm extends Component $this->portions = array_values($filtered); } - private function addPortionIfItFilled() + private function addPortionIfItFilled(): void { if (mb_strlen($this->product_name) && $this->quantity && mb_strlen($this->portion)) { $this->addPortion(); diff --git a/app/Livewire/PortionShow.php b/app/Livewire/PortionShow.php index 5753b6a..32ac12e 100644 --- a/app/Livewire/PortionShow.php +++ b/app/Livewire/PortionShow.php @@ -3,10 +3,11 @@ namespace App\Livewire; use Livewire\Component; +use Illuminate\View\View; class PortionShow extends Component { - public function render() + public function render(): View { return view('livewire.portion-show'); } diff --git a/app/Livewire/Profile/EditDetailzForm.php b/app/Livewire/Profile/EditDetailzForm.php index 6135773..abe0829 100644 --- a/app/Livewire/Profile/EditDetailzForm.php +++ b/app/Livewire/Profile/EditDetailzForm.php @@ -18,9 +18,9 @@ class EditDetailzForm extends Component public string $currentPassword; - public string $newPassword; + public string $newPassword = ''; - public string $newPasswordConfirm; + public string $newPasswordConfirm = ''; public array $validatedData = []; diff --git a/app/Livewire/TagsComponent.php b/app/Livewire/TagsComponent.php index 32e76f9..1f004ab 100644 --- a/app/Livewire/TagsComponent.php +++ b/app/Livewire/TagsComponent.php @@ -7,20 +7,23 @@ use App\Models\Tag; use Illuminate\View\View; use Livewire\Attributes\On; use Livewire\Component; +use Illuminate\Database\Eloquent\Model; +use App\Models\Recipe; +use App\Models\BlogPost; class TagsComponent extends Component { public string $tags; - public $parentComponent; + public Recipe|BlogPost $parentComponent; // protected $listeners = ['tagAdded', 'tagRemoved']; - public function mount($parentComponent = null): void + public function mount(Recipe|BlogPost $parentComponent = null): void { - // $curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : []; + $curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : []; /* $allTags = Tag::all(); */ - $curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : []; + // $curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : []; $this->tags = json_encode($curTags); } diff --git a/app/Models/BlogPost.php b/app/Models/BlogPost.php index 0957e9a..c79a4be 100644 --- a/app/Models/BlogPost.php +++ b/app/Models/BlogPost.php @@ -121,7 +121,7 @@ class BlogPost extends Model implements Viewable return $query->setEagerLoads([]); } - public function scopeContainsTag(Builder $query, string $tagString): Builder + public function scopeContainsTag(Builder $query, string $tagString): MorphToMany { $tagId = Str::of($tagString)->split('/-/')->first(); diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 5af0100..1d07c11 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; /** * App\Models\Chat @@ -36,7 +37,7 @@ class Chat extends Model protected $casts = ['created_at' => 'datetime:Y-m-d H:i:s']; - public function scopeWithLastUserMessage(mixed $query, int $userId) + public function scopeWithLastUserMessage(Builder $query, int $userId): Model|null { return $query ->where('from_user_id', $userId) @@ -45,7 +46,7 @@ class Chat extends Model ->first(); } - public function scopeWithLastTenMessages(mixed $query, int $userId, int $recipientId) + public function scopeWithLastTenMessages(Builder $query, int $userId, int $recipientId): Builder { return $query ->where('from_user_id', $userId) @@ -58,7 +59,7 @@ class Chat extends Model ->limit(20); } - public function scopeWithLastMessage(mixed $query, int $userId, int $recipientId) + public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): Model|null { return $query ->where('from_user_id', $userId) diff --git a/app/Models/CircumferenceMeasure.php b/app/Models/CircumferenceMeasure.php index 9441d2c..5a22243 100644 --- a/app/Models/CircumferenceMeasure.php +++ b/app/Models/CircumferenceMeasure.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\CircumferenceMeasure @@ -37,7 +38,7 @@ class CircumferenceMeasure extends Model protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/ConsultantEducation.php b/app/Models/ConsultantEducation.php index 293b8be..b2efdef 100644 --- a/app/Models/ConsultantEducation.php +++ b/app/Models/ConsultantEducation.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\ConsultantEducation @@ -45,7 +46,7 @@ class ConsultantEducation extends Model protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/Diary.php b/app/Models/Diary.php index 0152ddb..196e058 100644 --- a/app/Models/Diary.php +++ b/app/Models/Diary.php @@ -5,6 +5,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Builder; /** * App\Models\Diary @@ -49,26 +52,26 @@ class Diary extends Model // protected $casts = ['date' => 'datetime:d-m-Y']; // protected $dateFormat = 'd-m-Y'; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class)->withDefault([ 'name' => 'Guest Author', ]); } - public function meals() + public function meals():HasMany { return $this->hasMany(Meal::class); } - public function scopeUserToDayItem($query, $userId) + public function scopeUserToDayItem(Builder $query, int $userId): Builder { return $query ->where('user_id', $userId) ->where('date', now()->format('Y-m-d')); } - public function consultant_comments() + public function consultant_comments(): HasMany { return $this->hasMany(ConsultantDiaryComment::class); } diff --git a/app/Models/Meal.php b/app/Models/Meal.php index 0f39031..bb60b59 100644 --- a/app/Models/Meal.php +++ b/app/Models/Meal.php @@ -4,6 +4,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; /** * App\Models\Meal @@ -46,24 +49,24 @@ class Meal extends Model protected $fillable = ['*']; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class)->withDefault([ 'name' => 'Guest Author', ]); } - public function diary() + public function diary(): BelongsTo { return $this->belongsTo(Diary::class); } - public function portions() + public function portions(): HasMany { return $this->hasMany(Portion::class); } - public function photos() + public function photos(): BelongsToMany { return $this->belongsToMany(UserAttachment::class); } diff --git a/app/Models/Portion.php b/app/Models/Portion.php index a4ec877..e8e63b1 100644 --- a/app/Models/Portion.php +++ b/app/Models/Portion.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\Portion @@ -37,7 +38,7 @@ class Portion extends Model protected $fillable = ['*']; - public function user() + public function user(): BelongsTo { return $this->belongsTo(Meal::class); } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 752fd58..179918e 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -38,7 +38,7 @@ class Tag extends Model protected $guarded = []; - public function blogPosts() + public function blogPosts(): MorphToMany { return $this->morphedByMany(BlogPost::class, 'taggable', 'taggables'); } diff --git a/app/Models/UserAttachment.php b/app/Models/UserAttachment.php index f45d4be..a982c73 100644 --- a/app/Models/UserAttachment.php +++ b/app/Models/UserAttachment.php @@ -4,6 +4,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; /** * App\Models\UserAttachment @@ -44,17 +47,17 @@ class UserAttachment extends Model protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function scopeCerts($query) + public function scopeCerts(Builder $query): Builder { return $query->where('user_attachments.group', 'user_certs'); } - public function meals() + public function meals(): BelongsToMany { return $this->belongsToMany(Meal::class); } diff --git a/app/Models/UserDetailz.php b/app/Models/UserDetailz.php index 31a1b65..d8eb549 100644 --- a/app/Models/UserDetailz.php +++ b/app/Models/UserDetailz.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\UserDetailz @@ -80,7 +81,7 @@ class UserDetailz extends Model protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/WeightMeasure.php b/app/Models/WeightMeasure.php index 9555659..0890418 100644 --- a/app/Models/WeightMeasure.php +++ b/app/Models/WeightMeasure.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * App\Models\WeightMeasure @@ -33,7 +34,7 @@ class WeightMeasure extends Model protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Notifications/ConsultantRequestStarted.php b/app/Notifications/ConsultantRequestStarted.php index ff31650..48f796d 100644 --- a/app/Notifications/ConsultantRequestStarted.php +++ b/app/Notifications/ConsultantRequestStarted.php @@ -12,7 +12,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue { use Queueable; - private ConsultantEducation $education; + public ConsultantEducation $education; /** * Create a new notification instance. diff --git a/app/Rules/MinWords.php b/app/Rules/MinWords.php index 929a924..c04582d 100644 --- a/app/Rules/MinWords.php +++ b/app/Rules/MinWords.php @@ -6,21 +6,21 @@ use Illuminate\Contracts\Validation\Rule; class MinWords implements Rule { - protected $minWords; + protected int $minWords; - public function __construct($minWords) + public function __construct(int $minWords) { $this->minWords = $minWords; } - public function passes($attribute, $value) + public function passes(mixed $attribute, mixed $value): bool|int { $wordCount = count(preg_split('/\W+/u', $value, -1, PREG_SPLIT_NO_EMPTY)); return $wordCount >= $this->minWords; } - public function message() + public function message(): string { return "The :attribute must have at least {$this->minWords} words."; } diff --git a/app/Services/FeedService.php b/app/Services/FeedService.php index 11ee3e9..5163223 100644 --- a/app/Services/FeedService.php +++ b/app/Services/FeedService.php @@ -7,52 +7,56 @@ use App\Models\Recipe; use App\Models\User; use Carbon\Carbon; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Collection; class FeedService { - public static function showActualFeed() + public static function showActualFeed(): Collection { $dateMax = Recipe::max('created_at'); $dateMin = Carbon::parse($dateMax)->subDays(10); $sql = <<<'EOF' - SELECT - p.id, - p.title, - ( - (p.likes_count + p.comments_count) / - ((UNIX_TIMESTAMP(GREATEST(p.created_at, - COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at), - COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at) - )) - UNIX_TIMESTAMP(p.created_at))/60 + 1 - ) ^ 1.8 - ) AS popularity - FROM - (SELECT - `blog_posts`.id, - blog_posts.title, - blog_posts.created_at, - COUNT(blog_post_comments.id) AS comments_count, - COUNT(blog_post_likes.id) AS likes_count - FROM - `blog_posts` - LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id - LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id - GROUP BY blog_posts.id) p - ORDER BY popularity DESC; -EOF; + SELECT + p.id, + p.title, + ( + (p.likes_count + p.comments_count) / + ((UNIX_TIMESTAMP(GREATEST(p.created_at, + COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at), + COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at) + )) - UNIX_TIMESTAMP(p.created_at))/60 + 1 + ) ^ 1.8 + ) AS popularity + FROM + (SELECT + `blog_posts`.id, + blog_posts.title, + blog_posts.created_at, + COUNT(blog_post_comments.id) AS comments_count, + COUNT(blog_post_likes.id) AS likes_count + FROM + `blog_posts` + LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id + LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id + GROUP BY blog_posts.id) p + ORDER BY popularity DESC; + EOF; $hotBlogPosts = collect( - DB::select(DB::raw($sql)) - )->map(fn ($post) => BlogPost::find($post->id)) - ->take(16)->chunk(4); + DB::select($sql) + ) + ->map(fn($post) => BlogPost::find($post->id)) + ->take(16) + ->chunk(4); $newbiesBlogPosts = User::orderBy('created_at', 'desc') ->withCount('author_of_blog_post') ->get() - ->filter(fn ($u) => $u->author_of_blog_post_count > 0)->take(4) + ->filter(fn($u) => $u->author_of_blog_post_count > 0) + ->take(4) ->pluck('id') - ->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get()) + ->map(fn($id) => User::find($id)->author_of_blog_post()->limit(2)->get()) ->flatten() ->random(); @@ -62,9 +66,14 @@ EOF; ->limit(2) ->get(); - $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first()); - $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first()); + $firstCollection = collect([$hotBlogPosts->first(), $newbiesBlogPosts->first()]); + $secondCollection = collect([$hotBlogPosts->skip(1)->first(), $newbiesBlogPosts->skip(1)->first()]); - return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id); + return $firstCollection->concat($secondCollection)->filter(fn($el) => !is_null($el) && $el->id); + + // $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first()); + // $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first()); + + // return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id); } } diff --git a/config/rich-text-laravel.php b/config/rich-text-laravel.php index 3c1f439..4d85ec1 100644 --- a/config/rich-text-laravel.php +++ b/config/rich-text-laravel.php @@ -11,7 +11,7 @@ return [ | using this Eloquent Model. You can override this if you really need to. | */ - 'model' => \Tonysm\RichTextLaravel\Models\RichText::class, + // 'model' => \Tonysm\RichTextLaravel\Models\RichText::class, /* |-------------------------------------------------------------------------- diff --git a/config/state-machine.php b/config/state-machine.php index 8bbf7c2..c18dbb5 100644 --- a/config/state-machine.php +++ b/config/state-machine.php @@ -3,7 +3,7 @@ return [ 'article' => [ // class of your domain object - 'class' => App\Article::class, + // 'class' => App\Article::class, // name of the graph (default is "default") 'graph' => 'article', diff --git a/database/factories/ProductGroupFactory.php b/database/factories/ProductGroupFactory.php index b8a05f5..5802f3f 100644 --- a/database/factories/ProductGroupFactory.php +++ b/database/factories/ProductGroupFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; use FakerRestaurant\Provider\en_US\Restaurant; +use Faker\Generator; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductGroup> diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 563d0f4..af6289e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,11 +2,11 @@ namespace Database\Factories; -use App\Models\Team; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use Laravel\Jetstream\Features; +use Laravel\Jetstream\Team; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> diff --git a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php index 0a4e630..6f74520 100644 --- a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php +++ b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php @@ -6,12 +6,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - * - * @return void - */ - public function up() + public function up(): void { Schema::create('product_nutritional_values', function (Blueprint $table) { $table->id(); @@ -33,12 +28,7 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() + public function down(): void { Schema::dropIfExists('product_nutritional_values'); }