diff --git a/app/Actions/Fortify/UpdateUserProfileInformation.php b/app/Actions/Fortify/UpdateUserProfileInformation.php index 47e8e62..383d625 100644 --- a/app/Actions/Fortify/UpdateUserProfileInformation.php +++ b/app/Actions/Fortify/UpdateUserProfileInformation.php @@ -23,9 +23,9 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation 'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'], ])->validateWithBag('updateProfileInformation'); - if (isset($input['photo'])) { + /*if (isset($input['photo'])) { $user->updateProfilePhoto($input['photo']); - } + }*/ if ($input['email'] !== $user->email && $user instanceof MustVerifyEmail) { diff --git a/app/Console/Commands/UpdateSlugs.php b/app/Console/Commands/UpdateSlugs.php index d02a4ac..3626159 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,13 +25,13 @@ class UpdateSlugs extends Command /** * Execute the console command. */ - public function handle() + public function handle(): void { Recipe::where('slug', '') ->get() ->each( - function ($model) { - $newName = $model->title . ' 2612'; + function (Recipe $model) { + $newName = $model->title.' 2612'; $oldName = Str::replaceLast(' 2612', '', $newName); $model->title = $newName; 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/Events/DietSelected.php b/app/Events/DietSelected.php index 92e1c13..6450383 100644 --- a/app/Events/DietSelected.php +++ b/app/Events/DietSelected.php @@ -12,8 +12,14 @@ class DietSelected { use Dispatchable, InteractsWithSockets, SerializesModels; + /** + * @var Diet + */ public $diet; + /** + * @var User + */ public $user; /** diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index ec14f35..5a9866c 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -5,26 +5,30 @@ namespace App\Http\Controllers; use App\Models\Diary; use Carbon\Carbon; use Carbon\CarbonPeriod; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; -use Illuminate\View\View; use Mcamara\LaravelLocalization\Facades\LaravelLocalization; class CalendarController extends Controller { - public $weekStartsAt; + public string|int|null $weekStartsAt; - public $weekEndsAt; + public string|int|null $weekEndsAt; - public $startsAt; + public Carbon $startsAt; - public $endsAt; + public Carbon $endsAt; - public $gridStartsAt; + public string|int|null $gridStartsAt; - public $gridEndsAt; + public string|int|null $gridEndsAt; - public function __construct($initialYear = null, $initialMonth = null, $weekStartsAt = null) - { + public function __construct( + string|int|null $initialYear = null, + string|int|null $initialMonth = null, + string|int|null $weekStartsAt = null + ) { $this->weekStartsAt = $weekStartsAt ?? Carbon::MONDAY; $this->weekEndsAt = $this->weekStartsAt === Carbon::MONDAY ? Carbon::SUNDAY @@ -38,13 +42,13 @@ class CalendarController extends Controller $this->calculateGridStartsEnds(); } - public function calculateGridStartsEnds() + public function calculateGridStartsEnds(): void { $this->gridStartsAt = $this->startsAt->clone()->startOfWeek($this->weekStartsAt); $this->gridEndsAt = $this->endsAt->clone()->endOfWeek($this->weekEndsAt); } - public function index(): View + public function index(): View|ViewFactory { $curUser = Auth::user(); $fullGridPeriod = CarbonPeriod::create( @@ -52,8 +56,9 @@ class CalendarController extends Controller '1 day', $this->gridEndsAt ); + $filledDays = Diary::where('user_id', $curUser->id) - ->whereMonth('date', now()->month) + ->whereMonth('date', (string) now()->month) ->get() ->keyBy('date'); diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index c95971e..05e3dc4 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -3,61 +3,15 @@ namespace App\Http\Controllers; use App\Events\ChatMessageUpdated; +use App\Messages\ChatMessage; use App\Models\Chat; use App\Models\User; -use Illuminate\View\View; - -class ChatMessage -{ - public $id; - - public $payload; - - public function __construct($id, $payload) - { - $this->id = $id; - $this->payload = $payload; - } - - public function someRandomFillFunction() - { - $users1 = User::all()->pluck('id'); - $users2 = User::all()->pluck('id'); - $faker = Faker\Factory::create(); - - $users1->each( - function ($user1, $key) use ($faker, $users2) { - $users2->each( - function ($user2) use ($faker, $user1) { - if ($user1 === $user2) { - return; - } - $data1 = [ - 'from_user_id' => $user2, - 'to_user_id' => $user1, - 'data' => $faker->text(), - ]; - - $data2 = [ - 'from_user_id' => $user1, - 'to_user_id' => $user2, - 'data' => $faker->text(), - ]; - - $newMessage = (new Chat())->forceFill($data1); - $newMessage->save(); - $newMessage = (new Chat())->forceFill($data2); - $newMessage->save(); - } - ); - } - ); - } -} +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class ChatController extends Controller { - public function index(): View + public function index(): View|ViewFactory { // $_ = "from_user_id to_user_id"; $curUserId = Auth()->user()->id; @@ -91,17 +45,19 @@ class ChatController extends Controller ); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + /* + * public function create(): void { - ChatMessageUpdated::dispatch(new ChatMessage(time(), 'some text '.md5(time()))); + ChatMessageUpdated::dispatch( + new ChatMessage( + time(), + 'some text '.md5(' '.time()) + ) + ); } + */ - public function show(int $lastChatUser): View + public function show(int $lastChatUser): View|ViewFactory { $lastChatUser = User::find($lastChatUser); // $_ = "from_user_id to_user_id"; @@ -129,7 +85,7 @@ class ChatController extends Controller ); } - private function makeChanName($from, $to) + private function makeChanName(int $from, int $to): string { return (int) $from < (int) $to ? $from.'_'.$to diff --git a/app/Http/Controllers/DiaryController.php b/app/Http/Controllers/DiaryController.php index 6b79fb1..4a0a62c 100644 --- a/app/Http/Controllers/DiaryController.php +++ b/app/Http/Controllers/DiaryController.php @@ -32,7 +32,7 @@ class DiaryController extends Controller return view('diary.show', ['curDiary' => $diary, 'daysCount' => $daysCount]); } - public function edit($id): View + public function edit(int $id): View { $curDiary = Diary::find($id); $daysCount = Diary::where('user_id', auth()->id())->count(); @@ -47,7 +47,7 @@ class DiaryController extends Controller ); } - public function update(Request $request, $id): RedirectResponse + public function update(Request $request, int $id): RedirectResponse { /* dd($request, $id, $request->input()); */ $curDiary = Diary::find($id); @@ -79,7 +79,7 @@ class DiaryController extends Controller $curDiary->wakeup = '06:30'; $curDiary->retire = '22:30'; $curDiary->user_id = $curUserId; - $curDiary->closed = false; + $curDiary->closed = (int)false; $curDiary->comment = ''; $curDiary->save(); diff --git a/app/Http/Controllers/FinanceController.php b/app/Http/Controllers/FinanceController.php index b9373f9..829928d 100644 --- a/app/Http/Controllers/FinanceController.php +++ b/app/Http/Controllers/FinanceController.php @@ -2,71 +2,6 @@ namespace App\Http\Controllers; -use App\Models\Finance; -use Illuminate\Http\Request; - class FinanceController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Finance $finance) - { - } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Finance $finance) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Finance $finance) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(Finance $finance) - { - } } diff --git a/app/Http/Controllers/RegistrationStartController.php b/app/Http/Controllers/RegistrationStartController.php index 97f49b4..7f6629d 100644 --- a/app/Http/Controllers/RegistrationStartController.php +++ b/app/Http/Controllers/RegistrationStartController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers; +use Illuminate\Http\RedirectResponse; + class RegistrationStartController extends Controller { - public function start() + public function start(): RedirectResponse { session()->flush(); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 6124dd0..1e9e328 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -3,72 +3,14 @@ namespace App\Http\Controllers; use App\Models\User; -use App\Models\UserDetailz; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class UserController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(User $user) - { - /* return view('user.show', ['user' => $user]); */ - } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(UserDetailz $userDetailz) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, UserDetailz $userDetailz) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(UserDetailz $userDetailz) + public function show(User $user): View|ViewFactory { + return view('user.show', ['user' => $user]); } } diff --git a/app/Listeners/ProcessDietSelectedNotification.php b/app/Listeners/ProcessDietSelectedNotification.php index daf5418..84c839a 100644 --- a/app/Listeners/ProcessDietSelectedNotification.php +++ b/app/Listeners/ProcessDietSelectedNotification.php @@ -12,6 +12,9 @@ class ProcessDietSelectedNotification implements ShouldQueue { use InteractsWithQueue; + /** + * @var bool + */ public $afterCommit = true; /** diff --git a/app/Livewire/Chat/LastUsers.php b/app/Livewire/Chat/LastUsers.php index 3330329..e282ad3 100644 --- a/app/Livewire/Chat/LastUsers.php +++ b/app/Livewire/Chat/LastUsers.php @@ -2,27 +2,32 @@ namespace App\Livewire\Chat; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class LastUsers extends Component { + /** + * @var mixed + */ public $lastChatUsers; - public $activeUserId; + public int $activeUserId; - public $curUserId; + public int $curUserId; - public $chanId; + public string $chanId; - public function render() + public function render(): View|ViewFactory { 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'); - redirect()->route('chat.show', $id); + $this->redirectRoute('chat.show', $id); } } diff --git a/app/Livewire/Chat/MessageWindow.php b/app/Livewire/Chat/MessageWindow.php index 29b5d26..da03138 100644 --- a/app/Livewire/Chat/MessageWindow.php +++ b/app/Livewire/Chat/MessageWindow.php @@ -5,25 +5,28 @@ namespace App\Livewire\Chat; use App\Events\ChatMessageUpdated; use App\Models\Chat; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Livewire\Component; class MessageWindow extends Component { - public $messages = []; + public Collection $messages; - public $curMessage = ''; + public string $curMessage = ''; - public $curUserId; + public int $curUserId; - public $recipientUserId; + public int $recipientUserId; - public $recipientUser; + public User $recipientUser; - 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 +36,7 @@ class MessageWindow extends Component ]; } - public function notifyNewMessage($e): void + public function notifyNewMessage(array $e): void { $message = $e['message']; @@ -41,11 +44,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 +61,7 @@ class MessageWindow extends Component } // FIXME - public function mount($recipientUserId) + public function mount(?int $recipientUserId): void { $this->recipientUserId = $recipientUserId; $this->recipientUser = User::find($recipientUserId); @@ -68,18 +71,18 @@ class MessageWindow extends Component // ? $recipientUserId . "_" . $this->curUserId // : $this->curUserId . "_" . $recipientUserId; if (is_null($recipientUserId)) { - $this->messages = []; + $this->messages = collect([]); } else { $this->messages = (new Chat())->withLastTenMessages($this->curUserId, $recipientUserId)->get(); } } - public function render() + public function render(): View|ViewFactory { 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..9e98f0f 100644 --- a/app/Livewire/Chat/Tracker.php +++ b/app/Livewire/Chat/Tracker.php @@ -3,23 +3,32 @@ namespace App\Livewire\Chat; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; + class Tracker extends Component { - public $showNewMessageNotifycation = false; + public bool $showNewMessageNotifycation = false; - public $myMessages = []; + public array $myMessages = []; // Special Syntax: ['echo:{channel},{event}' => '{method}'] + /** + * some Listeners + * + * @var array + * + * */ protected $listeners = ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; - public function notifyNewMessage($payload): void + public function notifyNewMessage(mixed $payload): void { $this->myMessages[] = $payload; $this->showNewMessageNotifycation = true; } - public function render() + public function render(): View|ViewFactory { return view('livewire.chat.tracker'); } diff --git a/app/Livewire/Consultant/ListConsultants.php b/app/Livewire/Consultant/ListConsultants.php index f4d9be6..ef10c29 100644 --- a/app/Livewire/Consultant/ListConsultants.php +++ b/app/Livewire/Consultant/ListConsultants.php @@ -3,11 +3,13 @@ namespace App\Livewire\Consultant; use App\Models\ConsultantEducation; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class ListConsultants extends Component { - public function render() + public function render(): View|ViewFactory { return view( 'livewire.consultant.list-consultants', diff --git a/app/Livewire/Consultant/RegistrationForm.php b/app/Livewire/Consultant/RegistrationForm.php index 26b7dff..40c9d44 100644 --- a/app/Livewire/Consultant/RegistrationForm.php +++ b/app/Livewire/Consultant/RegistrationForm.php @@ -10,6 +10,9 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; class RegistrationForm extends Component { @@ -27,14 +30,15 @@ class RegistrationForm extends Component public string $telegramLink = ''; - public bool $hasMedicalEducation = false; + public int $hasMedicalEducation = 0; - public $certPhotos = []; + public Collection $certPhotos; - public $tmpCertPhotos = []; + public array $tmpCertPhotos = []; public string $legalType = 'selfemployed'; + /** @phpstan-ignore-next-line */ protected $rules = [ 'medicalEducations.*.title' => 'required|string|min:6', 'medicalEducations.*.date' => 'required|date', @@ -46,7 +50,7 @@ class RegistrationForm extends Component 'tmpCertPhotos.*' => 'image|max:4024', ]; - public function mount() + public function mount(): void { $this->user = Auth::user(); $consultant_request = $this->user->consultant_request; @@ -61,17 +65,17 @@ class RegistrationForm extends Component $photos = $this->user->attachments()->certs()->get(); - if ($photos) { + if (count($photos) > 0) { $this->certPhotos = collect($photos); } } - public function render() + public function render(): View|ViewFactory { return view('livewire.consultant.registration-form'); } - public function addEducation() + public function addEducation(): void { $this->validate(); $medicalEducations = $this->medicalEducations; @@ -91,7 +95,7 @@ class RegistrationForm extends Component $this->medicalEducations = $medicalEducations; } - public function remove($index) + public function remove(int $index): void { $filteredEducations = array_filter( $this->medicalEducations, @@ -104,7 +108,7 @@ class RegistrationForm extends Component $this->medicalEducations = array_values($filteredEducations); } - public function save() + public function save(): void { $data = [ 'user_id' => $this->user->id, @@ -158,7 +162,7 @@ class RegistrationForm extends Component $this->user->notify(new ConsultantRequestStarted($consultantEducation)); } - public function deleteImg($id) + public function deleteImg(int $id): void { $file = UserAttachment::find($id); $fileSpecs = json_decode($file->specs, true); diff --git a/app/Livewire/Counter.php b/app/Livewire/Counter.php index 4ea663a..6a553e7 100644 --- a/app/Livewire/Counter.php +++ b/app/Livewire/Counter.php @@ -2,23 +2,28 @@ namespace App\Livewire; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Counter extends Component { + /** + * @var int + */ public $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|ViewFactory { return view('livewire.counter'); } diff --git a/app/Livewire/Diary/ConsultantCommentsEdit.php b/app/Livewire/Diary/ConsultantCommentsEdit.php index 5cfaea8..3458e02 100644 --- a/app/Livewire/Diary/ConsultantCommentsEdit.php +++ b/app/Livewire/Diary/ConsultantCommentsEdit.php @@ -5,34 +5,38 @@ namespace App\Livewire\Diary; use App\Models\ConsultantDiaryComment; use Illuminate\Support\Facades\Auth; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use App\Models\Diary; +use Illuminate\Support\Collection; class ConsultantCommentsEdit extends Component { - public $daysCount; + public int $daysCount; - public $diary; + public Diary $diary; - public $curMeals; + public Collection $curMeals; - public $typeNames; + public Collection $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 +47,7 @@ class ConsultantCommentsEdit extends Component )->pluck('comment', 'comment_type')->toArray(); } - public function render() + public function render(): ViewFactory|View { $commentTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks', 'wakeup_time', 'total']; @@ -55,7 +59,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..dc62677 100644 --- a/app/Livewire/Diary/MealPhotos.php +++ b/app/Livewire/Diary/MealPhotos.php @@ -7,6 +7,8 @@ use App\Models\UserAttachment; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class MealPhotos extends Component { @@ -14,9 +16,9 @@ class MealPhotos extends Component public Meal $meal; - public $tmpMealPhotos = []; + public array $tmpMealPhotos = []; - public function render() + public function render():View|ViewFactory { return view( 'livewire.diary.meal-photos', @@ -26,7 +28,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/Diet/Comment/Create.php b/app/Livewire/Diet/Comment/Create.php index 8d12ba9..663f0f8 100644 --- a/app/Livewire/Diet/Comment/Create.php +++ b/app/Livewire/Diet/Comment/Create.php @@ -6,6 +6,8 @@ use App\Models\Diet; use App\Models\DietComment; use App\Models\User; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Create extends Component { @@ -13,23 +15,23 @@ class Create extends Component public User $user; - public $body = ''; + public string $body = ''; - public $grade = 0; + public int $grade = 0; - public $isChecked = true; + public bool $isChecked = true; - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.comment.create'); } - public function toggle() + public function toggle(): void { $this->isChecked ? false : true; } - public function save() + public function save(): void { $this->toggle(); $comment = new DietComment(); diff --git a/app/Livewire/Diet/Comment/Show.php b/app/Livewire/Diet/Comment/Show.php index efde860..c56046a 100644 --- a/app/Livewire/Diet/Comment/Show.php +++ b/app/Livewire/Diet/Comment/Show.php @@ -3,15 +3,20 @@ namespace App\Livewire\Diet\Comment; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Show extends Component { public Diet $diet; + /** + * @var array + */ protected $listeners = ['commentAdded' => '$refresh']; - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.comment.show'); } diff --git a/app/Livewire/Diet/Comment/Upvote.php b/app/Livewire/Diet/Comment/Upvote.php index f314d97..cf96547 100644 --- a/app/Livewire/Diet/Comment/Upvote.php +++ b/app/Livewire/Diet/Comment/Upvote.php @@ -4,17 +4,19 @@ namespace App\Livewire\Diet\Comment; use App\Models\DietComment; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Upvote extends Component { public DietComment $comment; - public function mount(DietComment $comment) + public function mount(DietComment $comment): void { $this->comment = $comment; } - public function render() + public function render(): View|ViewFactory { $upvotes = $this->comment->upvotes()->forDietCommentsUpVote($this->comment)->count(); $downvotes = $this->comment->upvotes()->forDietCommentsDownVote($this->comment)->count(); @@ -30,7 +32,7 @@ class Upvote extends Component ); } - public function upvote() + public function upvote(): void { if ($this->comment->isUpVoted()) { $this->comment->removeUpVote(); @@ -49,7 +51,7 @@ class Upvote extends Component ]); } - public function downvote() + public function downvote(): void { if ($this->comment->isDownVoted()) { $this->comment->removeDownVote(); diff --git a/app/Livewire/Diet/Create.php b/app/Livewire/Diet/Create.php index 4ff25be..98f07f3 100644 --- a/app/Livewire/Diet/Create.php +++ b/app/Livewire/Diet/Create.php @@ -6,70 +6,74 @@ use App\Models\Diet; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Create extends Component { use WithFileUploads; - public $name = ''; + public string $name = ''; - public $image; + public string $image; - public $duration = '7'; + public int $duration = 7; - public $state = 'draft'; + public string $state = 'draft'; - public $type = []; + public array $type = []; - public $details = ''; + public string $details = ''; - public $days = []; + public array $days = []; - public $copyedDay; + public int $copyedDay; - public $copyedDayData; + public array $copyedDayData; + /** @phpstan-ignore-next-line */ protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste']; - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.create'); } - public function dayUpdated($dayIndex, $data) + public function dayUpdated(int $dayIndex, array $data): void { $this->days[$dayIndex] = $data; } - public function showPreview() + public function showPreview(): void { $this->state = 'draft'; $this->publish(); } - public function addToDrafts() + public function addToDrafts(): void { $this->state = 'draft'; $this->publish(); } - public function makeCopy($day) + public function makeCopy(int $day):void { $this->copyedDay = $day; } - public function makePaste($copyToDay) + public function makePaste(int $copyToDay): void { $data = $this->days[$this->copyedDay]; $this->dispatch('takePaste', day: $copyToDay, data: $data)->to('diet.day-edit'); } - public function publish() + public function publish(): void { $this->validate(); $diet = new Diet(); $diet->name = $this->name; + /** @phpstan-ignore-next-line */ $diet->image = $this->image->store('diets', 'public'); $diet->duration = $this->duration; $diet->state = $this->state; @@ -81,10 +85,12 @@ class Create extends Component $user = Auth::user(); $user->author_of_diets()->attach($diet->id); - return redirect()->route('diet.show', $diet->id); + // return redirect()->route('diet.show', $diet->id); + + $this->redirectRoute('diet.show', $diet->id); } - protected function rules() + protected function rules(): array { return [ 'name' => 'required|min:3', diff --git a/app/Livewire/Diet/DayEdit.php b/app/Livewire/Diet/DayEdit.php index 977337d..bd8f927 100644 --- a/app/Livewire/Diet/DayEdit.php +++ b/app/Livewire/Diet/DayEdit.php @@ -3,37 +3,41 @@ namespace App\Livewire\Diet; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class DayEdit extends Component { - public $day; + public int $day; - public $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks']; + public array $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks']; - public $activeType = 'breakfast'; + public string $activeType = 'breakfast'; - public $portions = []; + public array $portions = []; - public $name = ''; + public string $name = ''; - public $quantity = 0; + public int $quantity = 0; - public $portion = 'gram'; + public string $portion = 'gram'; + /** @phpstan-ignore-next-line */ protected $listeners = ['takePaste']; + /** @phpstan-ignore-next-line */ protected $rules = [ 'name' => 'required|min:3', 'quantity' => 'required|numeric|min:1', 'portion' => 'required|min:3', ]; - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.day-edit'); } - public function addPortion($type) + public function addPortion(string $type): void { $this->validate(); $newData = [ @@ -49,7 +53,7 @@ class DayEdit extends Component $this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions); } - public function delete($uniq, $type) + public function delete(string $uniq, string $type): void { $newPortions = collect($this->portions[$type]) ->filter( @@ -61,7 +65,7 @@ class DayEdit extends Component $this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions); } - public function edit($uniq, $type) + public function edit(string $uniq, string $type): void { $elemKey = collect($this->portions[$type]) ->search(function ($item) use ($uniq) { @@ -80,7 +84,7 @@ class DayEdit extends Component } } - public function takePaste($day, $data) + public function takePaste(int $day, array $data): void { if (intval($day) === intval($this->day)) { foreach ($data as $type => $props) { diff --git a/app/Livewire/Diet/Edit.php b/app/Livewire/Diet/Edit.php index 46df9b2..9bb591f 100644 --- a/app/Livewire/Diet/Edit.php +++ b/app/Livewire/Diet/Edit.php @@ -3,33 +3,38 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Edit extends Component { public Diet $diet; - public $name = ''; + public string $name = ''; - public $image; + public string $image; - public $duration = '7'; + public int $duration = 7; - public $state = 'draft'; + public string $state = 'draft'; - public $type = []; + public array $type = []; - public $details = ''; + public string $details = ''; - public $days = []; + public array $days = []; - public $copyedDay; + public int $copyedDay; - public $copyedDayData; + public array $copyedDayData; + /** + * @var array + */ protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste']; - public function mount(Diet $diet) + public function mount(Diet $diet): void { $this->name = $diet->name; $this->image = $diet->image; @@ -40,35 +45,35 @@ class Edit extends Component $this->days = json_decode($diet->daily_schedule, true); } - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.edit'); } - public function dayUpdated($dayIndex, $data) + public function dayUpdated(int $dayIndex, array $data): void { $this->days[$dayIndex] = $data; } - public function showPreview() + public function showPreview(): void { $this->state = 'draft'; $this->publish(); } - public function addToDrafts() + public function addToDrafts(): void { $this->state = 'draft'; $this->publish(); } - public function makeCopy($day) + public function makeCopy(int $day): void { /* dd($day); */ $this->copyedDay = $day; } - public function makePaste($copyToDay) + public function makePaste(int $copyToDay): void { $data = $this->days[$this->copyedDay]; $this->dispatch( @@ -78,7 +83,7 @@ class Edit extends Component )->to('diet.day-edit'); } - public function publish() + public function publish(): void { $this->validate(); @@ -96,10 +101,12 @@ class Edit extends Component /* $user = Auth::user(); */ /* $user->author_of_diets()->attach($diet->id); */ - return redirect()->route('diet.show', $diet->id); + // return redirect()->route('diet.show', $diet->id); + + $this->redirectRoute('diet.show', $diet->id); } - protected function rules() + protected function rules(): array { return [ 'name' => 'required|min:3', diff --git a/app/Livewire/Diet/Like.php b/app/Livewire/Diet/Like.php index 499fe4d..f559e9b 100644 --- a/app/Livewire/Diet/Like.php +++ b/app/Livewire/Diet/Like.php @@ -4,19 +4,21 @@ namespace App\Livewire\Diet; use App\Models\Diet; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Like extends Component { public Diet $diet; - public $isIconOnly = false; + public bool $isIconOnly = false; - public function mount(Diet $diet) + public function mount(Diet $diet): void { $this->diet = $diet; } - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.like'); } diff --git a/app/Livewire/Diet/StartButton.php b/app/Livewire/Diet/StartButton.php index dd807f5..3ba442d 100644 --- a/app/Livewire/Diet/StartButton.php +++ b/app/Livewire/Diet/StartButton.php @@ -6,6 +6,8 @@ use App\Events\DietSelected; use App\Models\Diet; use App\Models\User; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class StartButton extends Component { @@ -13,19 +15,19 @@ class StartButton extends Component public User $user; - public $chosenDietState; + public string $chosenDietState; - public function mount() + public function mount(): void { $this->chosenDietState = data_get($this->user->chosen_diet, 'last_state', 'oops'); } - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.start-button'); } - public function start() + public function start(): void { DietSelected::dispatch( $this->diet, @@ -33,7 +35,7 @@ class StartButton extends Component ); } - public function getLastState() + public function getLastState(): void { $this->chosenDietState = data_get($this->user->chosen_diet, 'last_state', 'oops'); } diff --git a/app/Livewire/Feed/Index.php b/app/Livewire/Feed/Index.php index ee3d22f..8d7c7c8 100644 --- a/app/Livewire/Feed/Index.php +++ b/app/Livewire/Feed/Index.php @@ -2,13 +2,15 @@ namespace App\Livewire\Feed; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Index extends Component { - public $posts; + public mixed $posts; - public function render() + public function render(): View|ViewFactory { return view('livewire.feed.index'); } diff --git a/app/Livewire/Forms/ProfileEditDetailzForm.php b/app/Livewire/Forms/ProfileEditDetailzForm.php index 43c36a1..5b4b11d 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 $has_hypo; #[Rule('required|boolean')] - public $has_hyper; + public int $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..fae21f3 100644 --- a/app/Livewire/MealForm.php +++ b/app/Livewire/MealForm.php @@ -5,45 +5,50 @@ namespace App\Livewire; use App\Models\Diary; use App\Models\Meal; use App\Models\Portion; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; 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 int $quantity; - public $pcs; + public array $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', ]; + /** + * @var array + */ protected $listeners = ['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 +70,7 @@ class MealForm extends Component $this->portions = $curPortions; } - public function updatingType($value) + public function updatingType(string $value): void { $curMeal = $this->diary->meals->where('type', $value)->first(); $this->satiety = $curMeal->satiety ?? 3; @@ -73,7 +78,7 @@ class MealForm extends Component $this->time = $curMeal->time ?? now()->setTimezone('3')->format('H:i'); } - public function render() + public function render(): View|ViewFactory { $types = [0, 1, 2, 3, 4]; $typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы']; @@ -99,7 +104,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 +147,7 @@ class MealForm extends Component $this->dispatch('food-intake-updated')->self(); } - public function addPortion() + public function addPortion(): void { $this->validate(); @@ -159,7 +164,7 @@ class MealForm extends Component $this->reset(['product_name', 'quantity', 'portion']); } - public function editPortion($key, $item) + public function editPortion(string $key, array $item): void { $filed = [ 'product_name' => $item['product_name'], @@ -170,7 +175,7 @@ class MealForm extends Component $this->fill($filed); } - public function delPortion($key, $item) + public function delPortion(string $key, array $item): void { if (isset($item['id'])) { Portion::find($item['id'])->delete(); @@ -186,7 +191,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..1cb3110 100644 --- a/app/Livewire/PortionShow.php +++ b/app/Livewire/PortionShow.php @@ -2,11 +2,13 @@ namespace App\Livewire; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class PortionShow extends Component { - public function render() + public function render(): View|ViewFactory { return view('livewire.portion-show'); } diff --git a/app/Livewire/ProductNutritional/Create.php b/app/Livewire/ProductNutritional/Create.php index c34d157..708047f 100644 --- a/app/Livewire/ProductNutritional/Create.php +++ b/app/Livewire/ProductNutritional/Create.php @@ -6,51 +6,54 @@ use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Create extends Component { use WithFileUploads; - public $name; + public string $name; - public $product_group; + public int $product_group; - public $image; + public string|null $image; - public $description; + public string $description; - public $formulations; + public string $formulations; - public $energy_on_100gr; + public int $energy_on_100gr; - public $proteins_on_100gr; + public float $proteins_on_100gr; - public $fats_on_100gr; + public float $fats_on_100gr; - public $carbohydrates_on_100gr; + public float $carbohydrates_on_100gr; - public $portion_mass_gr; + public int $portion_mass_gr; - public $energy_on_portion; + public float $energy_on_portion; - public $proteins_on_portion; + public float $proteins_on_portion; - public $fats_on_portion; + public float $fats_on_portion; - public $carbohydrates_on_portion; + public float $carbohydrates_on_portion; - public $curProductNutritionalValue; + public ProductNutritionalValue $curProductNutritionalValue; - public function render() + public function render(): View|ViewFactory { return view('livewire.product-nutritional.create', ['productGroups' => ProductGroup::all()]); } - public function save() + public function save(): void { $productNutritionalVal = ProductNutritionalValue::create([ 'name' => $this->name, 'product_group_id' => $this->product_group, + /** @phpstan-ignore-next-line */ 'image' => is_null($this->image) ? '' : $this->image->store('product_nutritional', 'public'), 'description' => $this->description ?? '', 'formulations' => $this->formulations ?? '', @@ -66,11 +69,10 @@ class Create extends Component ]); $this->curProductNutritionalValue = $productNutritionalVal; - - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); } - public function recalulateVals($mass) + public function recalulateVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -89,7 +91,7 @@ class Create extends Component } } - public function recalulatePortionVals($mass) + public function recalulatePortionVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -107,7 +109,7 @@ class Create extends Component } } - public function updated($name, $value) + public function updated(string $name, string|int|null $value): void { if ($name === 'portion_mass_gr') { $this->recalulatePortionVals((int) $this->portion_mass_gr); @@ -121,7 +123,7 @@ class Create extends Component } } - public function delete() + public function delete(): void { $this->reset(); $this->curProductNutritionalValue->delete(); diff --git a/app/Livewire/ProductNutritional/Edit.php b/app/Livewire/ProductNutritional/Edit.php index 239b8bb..7892bee 100644 --- a/app/Livewire/ProductNutritional/Edit.php +++ b/app/Livewire/ProductNutritional/Edit.php @@ -6,42 +6,44 @@ use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class Edit extends Component { use WithFileUploads; - public $name; + public string $name; - public $product_group; + public int $product_group; - public $image; + public string|null $image; - public $description; + public string $description; - public $formulations; + public string $formulations; - public $energy_on_100gr; + public int $energy_on_100gr; - public $proteins_on_100gr; + public float $proteins_on_100gr; - public $fats_on_100gr; + public float $fats_on_100gr; - public $carbohydrates_on_100gr; + public float $carbohydrates_on_100gr; - public $portion_mass_gr; + public int $portion_mass_gr; - public $energy_on_portion; + public float $energy_on_portion; - public $proteins_on_portion; + public float $proteins_on_portion; - public $fats_on_portion; + public float $fats_on_portion; - public $carbohydrates_on_portion; + public float $carbohydrates_on_portion; - public $product; + public ProductNutritionalValue $product; - public function mount(ProductNutritionalValue $product) + public function mount(ProductNutritionalValue $product): void { $this->name = $product->name; $this->product_group = $product->product_group->id; @@ -57,17 +59,19 @@ class Edit extends Component $this->proteins_on_portion = $product->proteins_on_portion; $this->fats_on_portion = $product->fats_on_portion; $this->carbohydrates_on_portion = $product->carbohydrates_on_portion; + $this->product = $product; } - public function render() + public function render(): View|ViewFactory { return view('livewire.product-nutritional.edit', ['productGroups' => ProductGroup::all()]); } - public function save() + public function save(): void { if (! is_string($this->image)) { - $this->product->image = $this->image->store('recipe', 'public'); + /** @phpstan-ignore-next-line */ + $this->product->image = $this->image->store('product_nutritional', 'public'); } $this->product->fill([ @@ -88,10 +92,11 @@ class Edit extends Component $this->product->save(); - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); + } - public function recalulateVals($mass) + public function recalulateVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -110,7 +115,7 @@ class Edit extends Component } } - public function recalulatePortionVals($mass) + public function recalulatePortionVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -128,7 +133,7 @@ class Edit extends Component } } - public function updated($name, $value) + public function updated(string $name, string|int|null $value): void { if ($name === 'portion_mass_gr') { $this->recalulatePortionVals((int) $this->portion_mass_gr); @@ -142,10 +147,10 @@ class Edit extends Component } } - public function delete() + public function delete(): void { $this->product->delete(); - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); } } diff --git a/app/Livewire/ProductNutritional/Index.php b/app/Livewire/ProductNutritional/Index.php index c2ce366..c69676b 100644 --- a/app/Livewire/ProductNutritional/Index.php +++ b/app/Livewire/ProductNutritional/Index.php @@ -3,11 +3,13 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductNutritionalValue; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Index extends Component { - public function render() + public function render(): View|ViewFactory { return view('livewire.product-nutritional.index', ['products' => ProductNutritionalValue::all()]); } diff --git a/app/Livewire/Profile/CircumferenceChart.php b/app/Livewire/Profile/CircumferenceChart.php index 4ac2f1b..1384edf 100644 --- a/app/Livewire/Profile/CircumferenceChart.php +++ b/app/Livewire/Profile/CircumferenceChart.php @@ -4,21 +4,28 @@ namespace App\Livewire\Profile; use App\Models\User; use Asantibanez\LivewireCharts\Models\LineChartModel; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class CircumferenceChart extends Component { public User $user; + /** + * event listeners + * + * @var array + * */ protected $listeners = ['circumference-chart-updated' => '$refresh']; - public function render() + public function render(): View|ViewFactory { $lastOneMisure = $this ->user ->circumference_measures() - ->get() - ->last(); + ->orderBy('updated_at', 'desc') + ->first(); $lastFourMisures = $this ->user diff --git a/app/Livewire/Profile/DescriptionForm.php b/app/Livewire/Profile/DescriptionForm.php index c33962a..c715bb2 100644 --- a/app/Livewire/Profile/DescriptionForm.php +++ b/app/Livewire/Profile/DescriptionForm.php @@ -2,22 +2,25 @@ namespace App\Livewire\Profile; +use App\Models\User; use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class DescriptionForm extends Component { - public $description = ''; + public string $description = ''; - public $user; + public User $user; - public function mount() + public function mount(): void { $this->initDetailzIfNeeded(); $this->description = $this->user->detailz->additional_info ?? ''; } - public function updatedDescription($value) + public function updatedDescription(mixed $value): void { $userDetailz = $this->user->detailz; @@ -25,12 +28,12 @@ class DescriptionForm extends Component $userDetailz->save(); } - public function render() + public function render(): View|ViewFactory { return view('livewire.profile.description-form'); } - private function initDetailzIfNeeded() + private function initDetailzIfNeeded(): void { $curUserDetailez = UserDetailz::firstOrNew( ['user_id' => $this->user->id], @@ -44,7 +47,7 @@ class DescriptionForm extends Component ] ); - if (is_null($curUserDetailez->id)) { + if (! $curUserDetailez->id) { $curUserDetailez->save(); } } diff --git a/app/Livewire/Profile/EditDetailzForm.php b/app/Livewire/Profile/EditDetailzForm.php index 5cdf7ec..2009d67 100644 --- a/app/Livewire/Profile/EditDetailzForm.php +++ b/app/Livewire/Profile/EditDetailzForm.php @@ -8,6 +8,8 @@ use App\Models\UserDetailz; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Livewire\Component; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class EditDetailzForm extends Component { @@ -25,13 +27,13 @@ class EditDetailzForm extends Component public ProfileEditDetailzForm $detailzForm; - public function mount(User $user) + public function mount(User $user): void { $this->detailz = $user->detailz; $this->detailzForm->setDetailz($user->detailz); } - public function updatePassword() + public function updatePassword(): void { $validatedData = Validator::make( ['currentPassword' => $this->currentPassword, 'newPassword' => $this->newPassword, 'newPasswordConfirm' => $this->newPasswordConfirm], @@ -54,12 +56,12 @@ class EditDetailzForm extends Component /* dd($this->currentPassword, $this->newPassword, $this->newPasswordConfirm, $validatedData); */ } - public function refineDetailz() + public function refineDetailz(): void { $this->detailzForm->update(); } - public function render() + public function render(): View|ViewFactory { return view('livewire.profile.edit-detailz-form'); } diff --git a/app/Livewire/Profile/PhotoForm.php b/app/Livewire/Profile/PhotoForm.php index d1297cb..6ef6c9b 100644 --- a/app/Livewire/Profile/PhotoForm.php +++ b/app/Livewire/Profile/PhotoForm.php @@ -7,6 +7,8 @@ use Illuminate\Support\Facades\DB; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; use Livewire\Component; use Livewire\WithFileUploads; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class PhotoForm extends Component { @@ -26,8 +28,13 @@ class PhotoForm extends Component */ public $photo; - public $isOnline = false; + public bool $isOnline = false; + /** + * User model + * + * @var \App\Models\User + */ public $user; /** @@ -70,7 +77,7 @@ class PhotoForm extends Component $this->dispatch('saved'); } - public function updatedPhoto($newPhoto) + public function updatedPhoto(mixed $newPhoto): void { Auth::user()->updateProfilePhoto($newPhoto); @@ -99,7 +106,7 @@ class PhotoForm extends Component return $this->user; } - public function render() + public function render(): View|ViewFactory { return view('livewire.profile.photo-form'); } diff --git a/app/Livewire/Profile/ShowDetailz.php b/app/Livewire/Profile/ShowDetailz.php index d31c4a3..86f39e6 100644 --- a/app/Livewire/Profile/ShowDetailz.php +++ b/app/Livewire/Profile/ShowDetailz.php @@ -4,41 +4,46 @@ namespace App\Livewire\Profile; use Livewire\Component; use Masmerise\Toaster\Toaster; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use App\Models\User; +use App\Models\UserDetailz; class ShowDetailz extends Component { - public $user; + public User $user; - public $userDetailzAttributes; + public array $userDetailzAttributes; - public $regFormKeys; + public array $regFormKeys; - public $userDetailz; + public UserDetailz $userDetailz; - public $publicity; + public int $publicity; - public $is_bedtime_fillable; + public int $is_bedtime_fillable; - public $is_mood_fillable; + public int $is_mood_fillable; - public function mount() + public function mount(): void { $this->is_mood_fillable = $this->user->detailz->is_mood_fillable; $this->is_bedtime_fillable = $this->user->detailz->is_bedtime_fillable; $this->publicity = $this->user->is_public_profile; } - public function render() + public function render(): View|ViewFactory { return view('livewire.profile.show-detailz'); } - public function editAction() + public function editAction(): void { - return redirect()->route('user_detailz.edit', $this->userDetailz->id); + //return redirect()->route('user_detailz.edit', $this->userDetailz->id); + $this->redirectRoute('user_detailz.edit', $this->userDetailz->id); } - public function updated($name, $value): void + public function updated(string $name, mixed $value): void { if ($name === 'is_bedtime_fillable') { $this->user->detailz->update(['is_bedtime_fillable' => $value]); diff --git a/app/Livewire/Profile/WeightChart.php b/app/Livewire/Profile/WeightChart.php index 0cb20e5..0a4ad64 100644 --- a/app/Livewire/Profile/WeightChart.php +++ b/app/Livewire/Profile/WeightChart.php @@ -4,15 +4,20 @@ namespace App\Livewire\Profile; use App\Models\User; use Asantibanez\LivewireCharts\Models\AreaChartModel; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class WeightChart extends Component { public User $user; + /** + * @var array + * */ protected $listeners = ['weight-chart-updated' => '$refresh']; - public function render() + public function render(): View|ViewFactory { $areaChartModel = (new AreaChartModel()) diff --git a/app/Livewire/Registration/Step1.php b/app/Livewire/Registration/Step1.php index 686f38b..cd3d6f1 100644 --- a/app/Livewire/Registration/Step1.php +++ b/app/Livewire/Registration/Step1.php @@ -14,78 +14,81 @@ use Illuminate\Validation\Rules\Password; // use Illuminate\Contracts\Auth\StatefulGuard; // use App\Models\User; // use App\Models\UserDetailz; +use Illuminate\Contracts\View\View; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Http\RedirectResponse; use Livewire\Component; // use \Mcamara\LaravelLocalization\Facades\LaravelLocalization; class Step1 extends Component { - public $step; + public string $step; - public $first_name; + public string $first_name; - public $last_name; + public string $last_name; - public $email; + public string $email; - public $password; + public string $password; - public $password_confirmation; + public string $password_confirmation; - public $birthdate; + public string $birthdate; - public $gender = 'male'; + public string $gender = 'male'; - public $country = 'ru'; + public string $country = 'ru'; - public $city = 'msk'; + public string $city = 'msk'; - public $lang = 'ru'; + public string $lang = 'ru'; - public $weight; + public int $weight; - public $height; + public int $height; - public $chest_circumference; + public int $chest_circumference; - public $waist_circumference; + public int $waist_circumference; - public $hip_circumference; + public int $hip_circumference; - public $blood_pressure_up; + public int $blood_pressure_up; - public $blood_pressure_down; + public int $blood_pressure_down; - public $has_hypo = 0; + public int $has_hypo = 0; - public $has_hyper = 0; + public int $has_hyper = 0; - public $about_alergy; + public string $about_alergy; - public $about_taking_pils; + public string $about_taking_pils; - public $about_sport_hobbies; + public string $about_sport_hobbies; - public $favorite_foods; + public string $favorite_foods; - public $unfavorite_foods; + public string $unfavorite_foods; - public $additional_info; + public string $additional_info; - public function mount($step) + public function mount(string $step): void { $this->step = $step; collect(session()->get('registrationdata', [])) ->each(fn ($item, $key) => $this->{$key} = $item); } - public function render() + public function render(): View|ViewFactory { return view('livewire.registration.'.$this->step, ['step' => $this->step]) ->extends('layouts.register'); } - public function nextStep() + public function nextStep(): RedirectResponse { $validatedData = Validator::make( $this->getValidateData($this->step), @@ -106,7 +109,7 @@ class Step1 extends Component ); } - public function skipStep() + public function skipStep(): RedirectResponse { $validatedData = $this->getValidateData($this->step); $registrationdata = session()->get('registrationdata', []); @@ -123,9 +126,9 @@ class Step1 extends Component ); } - public function goBack() + public function goBack(): RedirectResponse { - $nextStep = 'step'.(int) Str::replaceFirst('step', '', $this->step) - 1; + $nextStep = 'step'. (((int) Str::replaceFirst('step', '', $this->step)) - 1); return redirect() ->route( @@ -136,7 +139,7 @@ class Step1 extends Component ); } - public function finishRegistretion() + public function finishRegistretion(): RedirectResponse { $validatedData = Validator::make( $this->getValidateData($this->step), @@ -157,7 +160,7 @@ class Step1 extends Component return redirect()->route('profile.show', $user->id); } - private function getValidateRules($key) + private function getValidateRules(string $key): array { $rules = [ 'step1' => [ @@ -199,7 +202,7 @@ class Step1 extends Component return $rules[$key]; } - private function getValidateData($key) + private function getValidateData(string $key): array { $data = [ 'step1' => [ @@ -242,8 +245,8 @@ class Step1 extends Component return $data[$key]; } - private function getNextStep() + private function getNextStep(): string { - return 'step'.(int) Str::replaceFirst('step', '', $this->step) + 1; + return 'step'.((int) Str::replaceFirst('step', '', $this->step) + 1); } } diff --git a/app/Livewire/TagsComponent.php b/app/Livewire/TagsComponent.php index 012b94d..2fb5c44 100644 --- a/app/Livewire/TagsComponent.php +++ b/app/Livewire/TagsComponent.php @@ -4,18 +4,20 @@ namespace App\Livewire; // use App\Models\BlogPost; use App\Models\Tag; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Attributes\On; use Livewire\Component; class TagsComponent extends Component { - public $tags; + public mixed $tags; - public $parentComponent; + public mixed $parentComponent; // protected $listeners = ['tagAdded', 'tagRemoved']; - public function mount($parentComponent = null) + public function mount(mixed $parentComponent = null): void { /* $allTags = Tag::all(); */ $curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : []; @@ -44,7 +46,7 @@ class TagsComponent extends Component $this->dispatch('parentComponentTagRemoved', tag: $tag); } - public function render() + public function render(): View|ViewFactory { return view('livewire.tags-component'); } diff --git a/app/Livewire/User/AddCircumference.php b/app/Livewire/User/AddCircumference.php index 4101b56..d1d7802 100644 --- a/app/Livewire/User/AddCircumference.php +++ b/app/Livewire/User/AddCircumference.php @@ -8,28 +8,30 @@ use App\Models\CircumferenceMeasure; use App\Models\User; use Illuminate\Support\Facades\Auth; use LivewireUI\Modal\ModalComponent; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class AddCircumference extends ModalComponent { public User $user; - public $chest_circumference = 0; + public int $chest_circumference = 0; - public $waist_circumference = 0; + public int $waist_circumference = 0; - public $hip_circumference = 0; + public int $hip_circumference = 0; - public function mount() + public function mount(): void { $this->user = Auth::user(); } - public function render() + public function render(): View|ViewFactory { return view('livewire.user.add-circumference'); } - public function add() + public function add(): void { $newMeasure = CircumferenceMeasure::create([ 'user_id' => $this->user->id, diff --git a/app/Livewire/User/AddWeight.php b/app/Livewire/User/AddWeight.php index ef4043d..5b92afc 100644 --- a/app/Livewire/User/AddWeight.php +++ b/app/Livewire/User/AddWeight.php @@ -6,24 +6,26 @@ use App\Models\User; use App\Models\WeightMeasure; use Illuminate\Support\Facades\Auth; use LivewireUI\Modal\ModalComponent; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class AddWeight extends ModalComponent { public User $user; - public $weight = 0; + public int $weight = 0; - public function mount() + public function mount(): void { $this->user = Auth::user(); } - public function render() + public function render(): View|ViewFactory { return view('livewire.user.add-weight'); } - public function add() + public function add(): void { $newMeasure = WeightMeasure::create([ 'user_id' => $this->user->id, diff --git a/app/Messages/ChatMessage.php b/app/Messages/ChatMessage.php new file mode 100644 index 0000000..4e2aa4b --- /dev/null +++ b/app/Messages/ChatMessage.php @@ -0,0 +1,56 @@ +id = $id; + $this->payload = $payload; + } + + public function someRandomFillFunction(): void + { + + $users1 = User::all()->pluck('id'); + $users2 = User::all()->pluck('id'); + $faker = FakerFactory::create(); + + $users1->each( + function ($user1) use ($faker, $users2) { + $users2->each( + function ($user2) use ($faker, $user1) { + if ($user1 === $user2) { + return; + } + $data1 = [ + 'from_user_id' => $user2, + 'to_user_id' => $user1, + 'data' => $faker->text(), + ]; + + $data2 = [ + 'from_user_id' => $user1, + 'to_user_id' => $user2, + 'data' => $faker->text(), + ]; + + $newMessage = (new Chat())->forceFill($data1); + $newMessage->save(); + $newMessage = (new Chat())->forceFill($data2); + $newMessage->save(); + } + ); + } + ); + } +} diff --git a/app/Models/BlogPost.php b/app/Models/BlogPost.php index 0957e9a..9d98fee 100644 --- a/app/Models/BlogPost.php +++ b/app/Models/BlogPost.php @@ -23,7 +23,6 @@ use Illuminate\Support\Str; * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property string $title - * * @property-read \App\Models\User $author * @property-read \Illuminate\Database\Eloquent\Collection $comments * @property-read int|null $comments_count @@ -121,7 +120,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..94503e4 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\Query\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(mixed $query, int $userId): Builder { return $query ->where('from_user_id', $userId) @@ -45,12 +46,12 @@ 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) ->where('to_user_id', $recipientId) - ->orWhere(function ($query) use ($userId, $recipientId) { + ->orWhere(function (Builder $query) use ($userId, $recipientId) { return $query->where('from_user_id', $recipientId) ->where('to_user_id', $userId); }) @@ -58,12 +59,12 @@ class Chat extends Model ->limit(20); } - public function scopeWithLastMessage(mixed $query, int $userId, int $recipientId) + public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): null|object { return $query ->where('from_user_id', $userId) ->where('to_user_id', $recipientId) - ->orWhere(function ($query) use ($userId, $recipientId) { + ->orWhere(function (Builder $query) use ($userId, $recipientId) { return $query->where('from_user_id', $recipientId) ->where('to_user_id', $userId); }) diff --git a/app/Models/ChosenDiet.php b/app/Models/ChosenDiet.php index 8de788f..0dc8e03 100644 --- a/app/Models/ChosenDiet.php +++ b/app/Models/ChosenDiet.php @@ -5,6 +5,8 @@ namespace App\Models; use Iben\Statable\Statable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; /** * App\Models\ChosenDiet @@ -46,27 +48,27 @@ class ChosenDiet extends Model 'start_date', ]; - public function getActorId() + public function getActorId(): int { return $this->user_id; } - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } - public function diet() + public function diet(): BelongsTo { return $this->belongsTo(Diet::class); } - protected function getGraph() + protected function getGraph(): string { return 'chosen_diet'; } - protected function saveBeforeTransition() + protected function saveBeforeTransition(): bool { return true; } diff --git a/app/Models/CircumferenceMeasure.php b/app/Models/CircumferenceMeasure.php index 9441d2c..883ffb7 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 @@ -15,7 +16,6 @@ use Illuminate\Database\Eloquent\Model; * @property int $hip_circumference * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \App\Models\User|null $user * * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure newModelQuery() @@ -37,7 +37,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..84732b5 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 @@ -19,7 +20,6 @@ use Illuminate\Database\Eloquent\Model; * @property string $request_state * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \App\Models\User|null $user * * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation newModelQuery() @@ -45,7 +45,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 68a07dd..8ba5a30 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\Query\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/Diet.php b/app/Models/Diet.php index a72fa4e..6b37d68 100644 --- a/app/Models/Diet.php +++ b/app/Models/Diet.php @@ -9,6 +9,12 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Support\Str; +use Spatie\Sluggable\HasSlug; +use Spatie\Sluggable\SlugOptions; /** * App\Models\Diet @@ -70,14 +76,21 @@ class Diet extends Model implements Viewable 'choses', ]; - private $allowedDietTypes = [ + private array $allowedDietTypes = [ 'alko', 'corb', 'meat', 'veg', ]; - public function author() + // protected $casts = [ + // 'type' => 'array', + // 'packet1_options' => 'array', + // 'packet2_options' => 'array', + // 'packet3_options' => 'array', + // ]; + + public function author(): BelongsToMany { return $this ->belongsToMany(User::class, 'diet_author', 'diet_id', 'user_id'); @@ -90,7 +103,7 @@ class Diet extends Model implements Viewable );*/ } - public function comments() + public function comments(): HasMany { return $this->hasMany(DietComment::class); } @@ -103,7 +116,7 @@ class Diet extends Model implements Viewable public function isLiked(): bool { if (auth()->user()) { - return auth()->user()->diet_likes()->forDiet($this)->count(); + return auth()->user()->diet_likes()->forDiet($this)->count() > 0; } return false; @@ -136,32 +149,32 @@ class Diet extends Model implements Viewable ); } - public function choses() + public function choses(): HasMany { return $this->hasMany(ChosenDiet::class); } - public function scopeDurationMin(Builder $query, $days): Builder + public function scopeDurationMin(Builder $query, int $days): Builder { return $query->where('duration', '>=', $days); } - public function scopeDurationMax(Builder $query, $days): Builder + public function scopeDurationMax(Builder $query, int $days): Builder { return $query->where('duration', '<=', $days); } - public function scopeInvolvedMin(Builder $query, $number): Builder + public function scopeInvolvedMin(Builder $query, int $number): Builder { return $query->having('choses_count', '>=', $number); } - public function scopeInvolvedMax(Builder $query, $number): Builder + public function scopeInvolvedMax(Builder $query, int $number): Builder { return $query->having('choses_count', '<=', $number); } - public function scopeContainsType(Builder $query, $types): Builder + public function scopeContainsType(Builder $query, array $types): Builder { $i = 0; @@ -177,7 +190,7 @@ class Diet extends Model implements Viewable return $query; } - private function unserializeOptionsArr($str) + private function unserializeOptionsArr(string $str): array { if (preg_match('/^".*"$/', $str)) { return json_decode(stripslashes(mb_substr($str, 1, -1)), true); diff --git a/app/Models/DietComment.php b/app/Models/DietComment.php index defb14d..61efb1f 100644 --- a/app/Models/DietComment.php +++ b/app/Models/DietComment.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; use Illuminate\Database\Eloquent\Relations\HasMany; /** @@ -39,12 +40,12 @@ class DietComment extends Model { use HasFactory; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function diet() + public function diet(): BelongsTo { return $this->belongsTo(Diet::class, 'diet_id'); } @@ -61,7 +62,7 @@ class DietComment extends Model ->user() ->diet_comment_upvotes() ->forDietCommentsUpVote($this) - ->count(); + ->count() > 0; } return false; @@ -74,7 +75,7 @@ class DietComment extends Model ->user() ->diet_comment_upvotes() ->forDietCommentsDownVote($this) - ->count(); + ->count() > 0; } return false; diff --git a/app/Models/DietCommentUpvote.php b/app/Models/DietCommentUpvote.php index e2ec669..78322d0 100644 --- a/app/Models/DietCommentUpvote.php +++ b/app/Models/DietCommentUpvote.php @@ -4,6 +4,8 @@ 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; /** * App\Models\DietCommentUpvote @@ -42,22 +44,22 @@ class DietCommentUpvote extends Model 'type', ]; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function diet_comment() + public function diet_comment(): BelongsTo { return $this->belongsTo(DietComment::class, 'comment_id'); } - public function scopeForDietCommentsUpVote($query, DietComment $comment) + public function scopeForDietCommentsUpVote(Builder $query, DietComment $comment): Builder { return $query->where('comment_id', $comment->id)->where('type', 'upvote'); } - public function scopeForDietCommentsDownVote($query, DietComment $comment) + public function scopeForDietCommentsDownVote(Builder $query, DietComment $comment): Builder { return $query->where('comment_id', $comment->id)->where('type', 'downvote'); } diff --git a/app/Models/DietLike.php b/app/Models/DietLike.php index ec15270..c39176e 100644 --- a/app/Models/DietLike.php +++ b/app/Models/DietLike.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Query\Builder; /** * App\Models\DietLike @@ -34,7 +35,7 @@ class DietLike extends Model 'user_id', ]; - public function scopeForDiet($query, Diet $diet) + public function scopeForDiet(Builder $query, Diet $diet): Builder { return $query->where('diet_id', $diet->id); } 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/ProductGroup.php b/app/Models/ProductGroup.php index fd36c41..81e7070 100644 --- a/app/Models/ProductGroup.php +++ b/app/Models/ProductGroup.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; /** * App\Models\ProductGroup @@ -34,7 +35,7 @@ class ProductGroup extends Model protected $fillable = ['name']; - public function product_nutritional_value() + public function product_nutritional_value(): HasMany { return $this->hasMany(ProductNutritionalValue::class); } diff --git a/app/Models/ProductNutritionalValue.php b/app/Models/ProductNutritionalValue.php index 5a5138b..358d394 100644 --- a/app/Models/ProductNutritionalValue.php +++ b/app/Models/ProductNutritionalValue.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\ProductNutritionalValue @@ -57,7 +58,7 @@ class ProductNutritionalValue extends Model protected $guarded = []; - public function product_group() + public function product_group(): BelongsTo { return $this->belongsTo(ProductGroup::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/User.php b/app/Models/User.php index 031e78e..e8a553e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -90,6 +90,7 @@ use Laravel\Sanctum\HasApiTokens; * @property-read int|null $views_count * @property-read \Illuminate\Database\Eloquent\Collection $weight_measures * @property-read int|null $weight_measures_count + * @property-read string $consultant_state * * @method static \Database\Factories\UserFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() diff --git a/app/Models/UserAttachment.php b/app/Models/UserAttachment.php index f45d4be..80abe5f 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\Relations\BelongsToMany; +use Illuminate\Database\Query\Builder; /** * 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..af9f2f5 100644 --- a/app/Notifications/ConsultantRequestStarted.php +++ b/app/Notifications/ConsultantRequestStarted.php @@ -39,7 +39,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue public function toMail(object $notifiable): MailMessage { return (new MailMessage()) - ->subject('[Eatvio] New Consultant request') + ->subject('[Eatvio] New Consultant ['.$this->education->user_id.'] request') ->line('User: '.$notifiable->name.' send Consultant request') ->action('Notification Action', route('profile.show', $notifiable)) ->line('Thank you for using our application!'); diff --git a/app/Notifications/DietStarted.php b/app/Notifications/DietStarted.php index 7a46d24..49048af 100644 --- a/app/Notifications/DietStarted.php +++ b/app/Notifications/DietStarted.php @@ -2,6 +2,7 @@ namespace App\Notifications; +use App\Models\ChosenDiet; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -11,14 +12,14 @@ class DietStarted extends Notification implements ShouldQueue { use Queueable; - public $chosenDiet; + public ChosenDiet $chosenDiet; /** * Create a new notification instance. * * @return void */ - public function __construct($chosenDiet) + public function __construct(ChosenDiet $chosenDiet) { $this->afterCommit(); $this->chosenDiet = $chosenDiet; @@ -28,7 +29,6 @@ class DietStarted extends Notification implements ShouldQueue * Get the notification's delivery channels. * * @param mixed $notifiable - * * @return array */ public function via($notifiable) @@ -40,13 +40,12 @@ class DietStarted extends Notification implements ShouldQueue * Get the mail representation of the notification. * * @param mixed $notifiable - * * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage()) - ->line('you are successful started diet named: '.$this->chosenDiet->diet->name) + ->line('you are successful started diet named: '.($this->chosenDiet->diet->name ?? 'NoName')) ->action('Notification Action', route('diet.show', $this->chosenDiet->diet)) ->line('Thank you for using our application!'); } @@ -55,7 +54,6 @@ class DietStarted extends Notification implements ShouldQueue * Get the array representation of the notification. * * @param mixed $notifiable - * * @return array */ public function toArray($notifiable) diff --git a/app/Rules/MinWords.php b/app/Rules/MinWords.php index 929a924..26c76a2 100644 --- a/app/Rules/MinWords.php +++ b/app/Rules/MinWords.php @@ -6,9 +6,9 @@ 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; } @@ -20,7 +20,7 @@ class MinWords implements Rule 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..d87a87d 100644 --- a/app/Services/FeedService.php +++ b/app/Services/FeedService.php @@ -6,11 +6,12 @@ use App\Models\BlogPost; use App\Models\Recipe; use App\Models\User; use Carbon\Carbon; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; class FeedService { - public static function showActualFeed() + public static function showActualFeed(): Collection { $dateMax = Recipe::max('created_at'); $dateMin = Carbon::parse($dateMax)->subDays(10); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3cc4503..748bef3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,11 @@ parameters: excludePaths: - vendor/* + - database/* + - tests/* - app/Http/Controllers/Auth/* + - config/* + - routes/* ignoreErrors: - '/Parameter #1 \$value of function collect expects/' - '/PHPDoc type array of property App\\Models\\User::\$hidden is not covariant with PHPDoc type/'