From b65ad8c19ee5afa222534b7bb55e6532832dc5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 26 Jun 2023 14:38:26 +0200 Subject: [PATCH] Correction typages --- app/Exceptions/Handler.php | 3 +-- app/Models/BrandStat.php | 7 +++---- app/Models/Customer.php | 28 ++++++++++++++-------------- app/Models/CustomerInfo.php | 19 ++++++++++--------- app/Models/CustomerLogin.php | 12 ++++++------ app/Models/Service.php | 6 +++--- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 28bd6b9..e564f20 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -16,7 +16,6 @@ use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; -use Throwable; class Handler extends ExceptionHandler { @@ -56,7 +55,7 @@ class Handler extends ExceptionHandler * @param \Throwable $e * @return \Symfony\Component\HttpFoundation\Response */ - public function render($request, Throwable $e) + public function render($request, \Throwable $e) { if (Helper::isRequestForApiV2($request) and $request->isJson()) { return $this->handleApiV2Exception($request, $e); diff --git a/app/Models/BrandStat.php b/app/Models/BrandStat.php index ee3db76..fcd4c93 100644 --- a/app/Models/BrandStat.php +++ b/app/Models/BrandStat.php @@ -3,7 +3,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Carbon; class BrandStat extends Model { @@ -41,9 +40,9 @@ class BrandStat extends Model */ protected static function booted() { - static::creating(function (BrandStat $stat) { - if (!$stat->created_at) { - $stat->created_at = Carbon::now(); + static::creating(function (self $model) { + if (!$model->created_at) { + $model->created_at = now(); } }); } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index d765e80..7a9d002 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -60,7 +60,7 @@ class Customer extends Model /** * Customer Brand belongsToMany relation * - * @return \Illuminate\Database\Eloquent\Relations\belongsToMany + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function brands() { @@ -98,10 +98,10 @@ class Customer extends Model } } } - $query = CustomerInfo::whereHas('brand', function (Builder $query) use ($brand) { - $query->where('id', $brand->id); - })->whereHas('customer', function (Builder $query) { - $query->where('id', $this->id); + $query = CustomerInfo::query()->whereHas('brand', function (Builder $q) use ($brand) { + $q->where('id', $brand->id); + })->whereHas('customer', function (Builder $q) { + $q->where('id', $this->id); }); if ($firstOrNewOrFail === self::FIRST_OR_NEW) { return $query->firstOrNew(); @@ -131,10 +131,10 @@ class Customer extends Model } } } - $query = CustomerLogin::whereHas('brand', function (Builder $query) use ($brand) { - $query->where('id', $brand->id); - })->whereHas('customer', function (Builder $query) use ($brand) { - $query->where('id', $this->id); + $query = CustomerLogin::query()->whereHas('brand', function (Builder $q) use ($brand) { + $q->where('id', $brand->id); + })->whereHas('customer', function (Builder $q) { + $q->where('id', $this->id); }); if ($firstOrNewOrFail === self::FIRST_OR_NEW) { return $query->firstOrNew(); @@ -201,11 +201,11 @@ class Customer extends Model */ public function getAnswers(Service $service): Collection { - return Answer::whereHas('customers', function ($q) { - $q->whereId($this->id); - })->whereHas('question', function ($q) use ($service) { - $q->whereHas('brand', function ($q) use ($service) { - $q->whereId($service->brand->id); + return Answer::query()->whereHas('customers', function (Builder $q) { + $q->where('id', $this->id); + })->whereHas('question', function (Builder $q) use ($service) { + $q->whereHas('brand', function (Builder $q) use ($service) { + $q->where('id', $service->brand->id); }); })->get(); } diff --git a/app/Models/CustomerInfo.php b/app/Models/CustomerInfo.php index f1d06ac..241050d 100644 --- a/app/Models/CustomerInfo.php +++ b/app/Models/CustomerInfo.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\Country; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -56,14 +57,14 @@ class CustomerInfo extends Model */ protected static function booted() { - static::creating(function (CustomerInfo $customerInfo) { - $customerInfo->hashcode = Str::uuid(); + static::creating(function (self $model) { + $model->hashcode = Str::uuid(); }); - static::deleting(function (CustomerInfo $customerInfo) { - CustomerOptInHistory::whereHas('customer', function ($q) use ($customerInfo) { - $q->whereId($customerInfo->customer->id); - })->whereHas('brand', function ($q) use ($customerInfo) { - $q->whereId($customerInfo->brand->id); + static::deleting(function (self $model) { + CustomerOptInHistory::query()->whereHas('customer', function (Builder $q) use ($model) { + $q->where('id', $model->customer->id); + })->whereHas('brand', function (Builder $q) use ($model) { + $q->where('id', $model->brand->id); })->delete(); }); } @@ -111,9 +112,9 @@ class CustomerInfo extends Model */ public static function getFromEmail(Brand $brand, string $email) { - return CustomerInfo::whereHas('brand', function ($q) use ($brand) { + return CustomerInfo::query()->whereHas('brand', function (Builder $q) use ($brand) { $q->where('id', $brand->id); - })->whereHas('customer', function ($q) use ($email) { + })->whereHas('customer', function (Builder $q) use ($email) { $q->where('email', $email); }); } diff --git a/app/Models/CustomerLogin.php b/app/Models/CustomerLogin.php index 9e504c9..04822b6 100644 --- a/app/Models/CustomerLogin.php +++ b/app/Models/CustomerLogin.php @@ -44,14 +44,14 @@ class CustomerLogin extends Model */ protected static function booted() { - static::creating(function ($customerLogin) { - if (Hash::needsRehash($customerLogin->password)) { - $customerLogin->password = Hash::make(trim($customerLogin->password)); + static::creating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make(trim($model->password)); } }); - static::updating(function ($customerLogin) { - if (Hash::needsRehash($customerLogin->password)) { - $customerLogin->password = Hash::make(trim($customerLogin->password)); + static::updating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make(trim($model->password)); } }); } diff --git a/app/Models/Service.php b/app/Models/Service.php index 26cd040..bf6dbb7 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -68,9 +68,9 @@ class Service extends Model */ protected static function booted() { - static::creating(function (self $service) { - $service->generateBearerToken(); - $service->generateBearerPassword(); + static::creating(function (self $model) { + $model->generateBearerToken(); + $model->generateBearerPassword(); }); static::created(function () { // * Flush Eloquent cache.