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
This commit is contained in:
Jérémy Munsch 2026-10-28 08:53:34 +01:00
parent 1899fd1f0e
commit 4ff3daecab
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91
25 changed files with 59 additions and 52 deletions

View file

@ -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',

View file

@ -70,8 +70,8 @@ class ExceptionsHelper
*
* @template T of mixed
*
* @param array<T> $params
* @return array<T>
* @param array<array-key, T> $params
* @return array<string|T>
*/
private static function getAnonymizedSentryParams(array $params): array
{
@ -89,7 +89,6 @@ class ExceptionsHelper
};
}
// @phpstan-ignore return.type
return $params;
}

View file

@ -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),
};
}

View file

@ -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<string,string> $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]);

View file

@ -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

View file

@ -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.'
));
}
}

View file

@ -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;
}
}

View file

@ -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');
}
/**

View file

@ -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
)
);

View file

@ -109,7 +109,6 @@ class RouteServiceProvider extends ServiceProvider
fn (string $value) => $this->resolvePublishedProductWithPricing($value)
);
// * CSP Route
$this->cspReportRoute();
}

View file

@ -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
)

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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é',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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%',

View file

@ -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',

View file

@ -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',

View file

@ -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);