From 4ff3daecabfe3a42a88ac4796c8bb7c894ffedb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 28 Oct 2026 08:53:34 +0100 Subject: [PATCH] refactor(Auth): improve reset URL handling and validation refactor(Helpers): update parameter types and remove ignores refactor(Models): streamline order assignment logic refactor(Enums): clarify unused constant warnings refactor(Services): encapsulate cutoff week offset logic --- app/Http/Controllers/Fo/Auth/AuthController.php | 8 +++++--- app/Lib/Helpers/ExceptionsHelper.php | 5 ++--- app/Lib/Helpers/StringEncoder.php | 8 ++++---- app/Lib/Helpers/ToolboxHelper.php | 15 +++++++-------- app/Models/Product.php | 7 +++++-- app/Models/Slide.php | 9 +++++---- app/Models/Tag.php | 6 +++--- .../MissingOrderReminderNotification.php | 6 +++--- app/Providers/MoneyServiceProvider.php | 8 ++++---- app/Providers/RouteServiceProvider.php | 1 - app/Services/DataTableService.php | 2 +- domain/Enums/DiscountType.php | 2 +- domain/Enums/EmployeeSite.php | 2 +- domain/Enums/OrderStatus.php | 2 +- domain/Enums/PriceShowingMode.php | 2 +- domain/Enums/ProductBrand.php | 2 +- domain/Enums/RepeatFrequency.php | 2 +- domain/Enums/SellUnit.php | 2 +- domain/Enums/StaticPageSlug.php | 2 +- domain/Enums/StatsCustomerType.php | 2 +- domain/Enums/StatsShopType.php | 2 +- domain/Enums/TaxRate.php | 2 +- domain/Enums/Units/InvoicingUnit.php | 2 +- domain/Enums/Units/OrderUnit.php | 2 +- domain/Services/PickupSchedulingService.php | 10 +++++++--- 25 files changed, 59 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/Fo/Auth/AuthController.php b/app/Http/Controllers/Fo/Auth/AuthController.php index eaf271c9..c8c71152 100644 --- a/app/Http/Controllers/Fo/Auth/AuthController.php +++ b/app/Http/Controllers/Fo/Auth/AuthController.php @@ -16,8 +16,6 @@ abstract class AuthController extends Controller { public function __construct() { - - // @phpstan-ignore assign.propertyType ResetPassword::$createUrlCallback = $this->createResetUrl(...); VerifyEmail::$createUrlCallback = $this->createValidationUrl(...); } @@ -50,8 +48,12 @@ abstract class AuthController extends Controller ); } - public function createResetUrl(Customer $notifiable, string $token): string + public function createResetUrl(mixed $notifiable, string $token): string { + if (! is_object($notifiable) || ! ($notifiable instanceof Customer)) { + throw new \InvalidArgumentException('Invalid notifiable provided.'); + } + return url( URL::temporarySignedRoute( 'fo.auth.reset-password', diff --git a/app/Lib/Helpers/ExceptionsHelper.php b/app/Lib/Helpers/ExceptionsHelper.php index cdc33885..5f129afe 100644 --- a/app/Lib/Helpers/ExceptionsHelper.php +++ b/app/Lib/Helpers/ExceptionsHelper.php @@ -70,8 +70,8 @@ class ExceptionsHelper * * @template T of mixed * - * @param array $params - * @return array + * @param array $params + * @return array */ private static function getAnonymizedSentryParams(array $params): array { @@ -89,7 +89,6 @@ class ExceptionsHelper }; } - // @phpstan-ignore return.type return $params; } diff --git a/app/Lib/Helpers/StringEncoder.php b/app/Lib/Helpers/StringEncoder.php index c127588f..34e22a5e 100644 --- a/app/Lib/Helpers/StringEncoder.php +++ b/app/Lib/Helpers/StringEncoder.php @@ -277,10 +277,10 @@ final class StringEncoder foreach ($bytes as $byte) { $parts[] = match (true) { - // @phpstan-ignore argument.type - $byte <= 0x7F => chr($byte), - isset($overrides[$byte]) => $overrides[$byte], - default => self::encodeLatin1ByteAsUtf8($byte), + // @phpstan-ignore argument.type (ASCII range check) + $byte <= 0x7F => chr($byte), + isset($overrides[$byte]) => $overrides[$byte], + default => self::encodeLatin1ByteAsUtf8($byte), }; } diff --git a/app/Lib/Helpers/ToolboxHelper.php b/app/Lib/Helpers/ToolboxHelper.php index c73a4e33..bc7200cb 100644 --- a/app/Lib/Helpers/ToolboxHelper.php +++ b/app/Lib/Helpers/ToolboxHelper.php @@ -179,16 +179,15 @@ class ToolboxHelper extends ToolboxHelperCore */ public static function getOriginal(Model $model, string $attribute): mixed { - if ( - \in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model)) && // @phpstan-ignore-next-line - $model->isTranslatableAttribute($attribute) - ) { - // @phpstan-ignore-next-line + + // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) + if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model)) && $model->isTranslatableAttribute($attribute)) { + // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) return $model->getTranslation( $attribute, - // @phpstan-ignore-next-line + // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) $model->getLocale(), - // @phpstan-ignore-next-line + // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) $model->useFallbackLocale() ); } @@ -216,7 +215,7 @@ class ToolboxHelper extends ToolboxHelperCore throw_unless(preg_match($localeRegex, $currentLocale), \InvalidArgumentException::class, 'Invalid locale identifier.'); /** @var array $locales */ - $locales = config('app.locales', []); + $locales = Config::array('app.locales', []); $locales = Collection::make($locales) ->filter(fn (string $locale) => (bool) preg_match($localeRegex, $locale)) ->mapWithKeys(fn (string $locale) => [$locale => $locale]); diff --git a/app/Models/Product.php b/app/Models/Product.php index edbd0d5b..1921efa3 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -147,8 +147,11 @@ class Product extends Model implements ModelWithOrder, ModelWithStar, ModelWithS $model->slug = Str::slug($model->name); $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); $model->picture_large = FileStorageHelper::storeFile($model, $model->picture_large, true); - // @phpstan-ignore cast.int - $model->order ??= (int) self::query()->max('order'); + + if ($model->order === null) { + $max = self::query()->max('order'); + $model->order = is_scalar($max) ? intval($max) + 1 : 1; + } } private static function assertNameIsUnique(?string $name, ?string $id = null): void diff --git a/app/Models/Slide.php b/app/Models/Slide.php index b4f72901..bef0dd62 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -96,9 +96,10 @@ class Slide extends Model implements ModelWithOrder, ModelWithStatus private static function manageFields(self $model): void { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); - if (is_null($model->order)) { - // @phpstan-ignore argument.type - $model->order = intval(self::query()->max('order')); + + if ($model->order === null) { + $max = self::query()->max('order'); + $model->order = is_scalar($max) ? intval($max) + 1 : 1; } } @@ -110,7 +111,7 @@ class Slide extends Model implements ModelWithOrder, ModelWithStatus if ($actualStatus !== $model->status) { resolve(Session::class)->flash('bo.info', \trans( 'The publication status is updated according to the scheduled dates. ' - . 'To change the publication status, please edit or remove the corresponding dates.' + . 'To change the publication status, please edit or remove the corresponding dates.' )); } } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 09a5dde2..fb01be54 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -76,9 +76,9 @@ class Tag extends Model implements ModelWithOrder, ModelWithStatus self::assertLabelIsUnique($model->label, $model->id); $model->slug = Str::slug($model->label); - if (is_null($model->order)) { - // @phpstan-ignore argument.type - $model->order = intval(self::query()->max('order')); + if ($model->order === null) { + $max = self::query()->max('order'); + $model->order = is_scalar($max) ? intval($max) + 1 : 1; } } diff --git a/app/Notifications/MissingOrderReminderNotification.php b/app/Notifications/MissingOrderReminderNotification.php index c7215da9..71e5e929 100644 --- a/app/Notifications/MissingOrderReminderNotification.php +++ b/app/Notifications/MissingOrderReminderNotification.php @@ -16,6 +16,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; +use Illuminate\Support\Facades\Config; class MissingOrderReminderNotification extends Notification implements ShouldQueue { @@ -30,7 +31,7 @@ class MissingOrderReminderNotification extends Notification implements ShouldQue public function __construct( private readonly CarbonInterface $pickupDay ) { - $appUrl = config()->string('app.url'); + $appUrl = Config::string('app.url'); $appHost = parse_url($appUrl, \PHP_URL_HOST); if (empty($appHost)) { @@ -39,8 +40,7 @@ class MissingOrderReminderNotification extends Notification implements ShouldQue $this->appUrl = $appUrl; $this->appHost = $appHost; - $this->appName = config() - ->string('app.name', 'La Boutique de Cocotte'); + $this->appName = Config::string('app.name', 'La Boutique de Cocotte'); } /** diff --git a/app/Providers/MoneyServiceProvider.php b/app/Providers/MoneyServiceProvider.php index bdd105c6..474938ff 100644 --- a/app/Providers/MoneyServiceProvider.php +++ b/app/Providers/MoneyServiceProvider.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Providers; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Config; use Illuminate\Support\ServiceProvider; use Money\Currencies\ISOCurrencies; use Money\Currency; @@ -29,8 +30,8 @@ class MoneyServiceProvider extends ServiceProvider $this->app->singleton( Currency::class, fn () => new Currency( - // @phpstan-ignore argument.type - config( + // @phpstan-ignore argument.type (Should throw if not provided) + Config::string( 'app.currency', 'EUR' ) @@ -40,8 +41,7 @@ class MoneyServiceProvider extends ServiceProvider $this->app->singleton( \NumberFormatter::class, fn () => new \NumberFormatter( - // @phpstan-ignore argument.type - config('app.locale', 'fr_FR'), + Config::string('app.locale', 'fr_FR'), \NumberFormatter::CURRENCY ) ); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 84fc93da..30c4b819 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -109,7 +109,6 @@ class RouteServiceProvider extends ServiceProvider fn (string $value) => $this->resolvePublishedProductWithPricing($value) ); - // * CSP Route $this->cspReportRoute(); } diff --git a/app/Services/DataTableService.php b/app/Services/DataTableService.php index 296de906..bca2b26a 100644 --- a/app/Services/DataTableService.php +++ b/app/Services/DataTableService.php @@ -196,7 +196,7 @@ class DataTableService return array_values(array_filter( $cast::cases(), fn ($item): bool => str_contains( - // @phpstan-ignore method.notFound + // @phpstan-ignore method.notFound (PhpStan cannot detect the label() method on BaseEnum cases) mb_strtolower((string) $item->label()), $searchLower ) diff --git a/domain/Enums/DiscountType.php b/domain/Enums/DiscountType.php index 843154ed..17cd7aee 100644 --- a/domain/Enums/DiscountType.php +++ b/domain/Enums/DiscountType.php @@ -17,7 +17,7 @@ enum DiscountType: int /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::AMOUNT->name => 'Montant', diff --git a/domain/Enums/EmployeeSite.php b/domain/Enums/EmployeeSite.php index 35f65298..ea39bade 100644 --- a/domain/Enums/EmployeeSite.php +++ b/domain/Enums/EmployeeSite.php @@ -30,7 +30,7 @@ enum EmployeeSite: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::slhp->name => 'SLHP', diff --git a/domain/Enums/OrderStatus.php b/domain/Enums/OrderStatus.php index e3be27e3..5bd641a1 100644 --- a/domain/Enums/OrderStatus.php +++ b/domain/Enums/OrderStatus.php @@ -18,7 +18,7 @@ enum OrderStatus: int /** * Optional labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::WAITING->name => 'En attente', diff --git a/domain/Enums/PriceShowingMode.php b/domain/Enums/PriceShowingMode.php index 583c645f..5f8bfbc1 100644 --- a/domain/Enums/PriceShowingMode.php +++ b/domain/Enums/PriceShowingMode.php @@ -17,7 +17,7 @@ enum PriceShowingMode: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::authenticated->name => 'Client Connecté', diff --git a/domain/Enums/ProductBrand.php b/domain/Enums/ProductBrand.php index 6a68d323..92b6b0fc 100644 --- a/domain/Enums/ProductBrand.php +++ b/domain/Enums/ProductBrand.php @@ -27,7 +27,7 @@ enum ProductBrand: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::none->name => 'Sans marque', diff --git a/domain/Enums/RepeatFrequency.php b/domain/Enums/RepeatFrequency.php index a1547d63..af1729ee 100644 --- a/domain/Enums/RepeatFrequency.php +++ b/domain/Enums/RepeatFrequency.php @@ -18,7 +18,7 @@ enum RepeatFrequency: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::WEEKLY->name => 'Toutes les semaines', diff --git a/domain/Enums/SellUnit.php b/domain/Enums/SellUnit.php index 827eda7a..c5d95b3c 100644 --- a/domain/Enums/SellUnit.php +++ b/domain/Enums/SellUnit.php @@ -18,7 +18,7 @@ enum SellUnit: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::PCE->name => 'Pièce', diff --git a/domain/Enums/StaticPageSlug.php b/domain/Enums/StaticPageSlug.php index 936a0b42..87cfb14d 100644 --- a/domain/Enums/StaticPageSlug.php +++ b/domain/Enums/StaticPageSlug.php @@ -20,7 +20,7 @@ enum StaticPageSlug: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::CONTACT->name => 'contact', diff --git a/domain/Enums/StatsCustomerType.php b/domain/Enums/StatsCustomerType.php index 373624aa..2aa2ec93 100644 --- a/domain/Enums/StatsCustomerType.php +++ b/domain/Enums/StatsCustomerType.php @@ -18,7 +18,7 @@ enum StatsCustomerType: int /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::nbSalarie->name => 'Nombre de salariés', diff --git a/domain/Enums/StatsShopType.php b/domain/Enums/StatsShopType.php index 5c77148a..bbe65ce1 100644 --- a/domain/Enums/StatsShopType.php +++ b/domain/Enums/StatsShopType.php @@ -28,7 +28,7 @@ enum StatsShopType: int /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::nbActiveClients->name => 'Nombre de clients actifs', diff --git a/domain/Enums/TaxRate.php b/domain/Enums/TaxRate.php index 618e7315..917c674b 100644 --- a/domain/Enums/TaxRate.php +++ b/domain/Enums/TaxRate.php @@ -19,7 +19,7 @@ enum TaxRate: int /** * Optional labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::TVA_20->name => 'TVA 20%', diff --git a/domain/Enums/Units/InvoicingUnit.php b/domain/Enums/Units/InvoicingUnit.php index 0eec73bd..5086e247 100644 --- a/domain/Enums/Units/InvoicingUnit.php +++ b/domain/Enums/Units/InvoicingUnit.php @@ -18,7 +18,7 @@ enum InvoicingUnit: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::PCE->name => 'Pièce', diff --git a/domain/Enums/Units/OrderUnit.php b/domain/Enums/Units/OrderUnit.php index b88da35b..bf5584ee 100644 --- a/domain/Enums/Units/OrderUnit.php +++ b/domain/Enums/Units/OrderUnit.php @@ -18,7 +18,7 @@ enum OrderUnit: string /** * Optionnal labels definition * - * @phpstan-ignore-next-line + * @phpstan-ignore-next-line classConstant.unused (Base enum usage) */ private const LABELS = [ self::PCE->name => 'Pièce', diff --git a/domain/Services/PickupSchedulingService.php b/domain/Services/PickupSchedulingService.php index 9a465633..4a316bed 100644 --- a/domain/Services/PickupSchedulingService.php +++ b/domain/Services/PickupSchedulingService.php @@ -195,12 +195,16 @@ class PickupSchedulingService ->addDays(self::CUTOFF_DAY->value - 1) ->addHours(self::CUTOFF_HOUR); - // @phpstan-ignore notIdentical.alwaysFalse - return self::CUTOFF_WEEK_OFFSET !== 0 - ? $deadline->addWeeks(self::CUTOFF_WEEK_OFFSET) + return $this->getCutoffWeekOffset() !== 0 + ? $deadline->addWeeks($this->getCutoffWeekOffset()) : $deadline; } + private function getCutoffWeekOffset(): int + { + return self::CUTOFF_WEEK_OFFSET; + } + protected function isBefore(CarbonInterface $date): bool { return $this->getNow()->lessThanOrEqualTo($date);