From 769a6f73fc0ed64aba748602b501c90659282f9a Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 12 Feb 2026 17:14:08 +0100 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=9A=A8=20resolve=20last=20phps?= =?UTF-8?q?tan=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Casts/LocalDateTime.php | 8 +- app/Enums/Contact/ContactFormType.php | 53 +++---- app/Enums/DynamicFieldTypes.php | 1 + app/Enums/OrdersEnum.php | 10 +- app/Helpers/DynamicPageHelper.php | 8 +- app/Helpers/RouteHelper.php | 14 +- .../Back/DocumentCategoryController.php | 10 +- .../Controllers/Back/DocumentController.php | 10 +- .../Back/DocumentTagController.php | 10 +- .../Controllers/Back/InputsController.php | 2 +- .../Back/NewsCategoryController.php | 10 +- .../Controllers/Back/NewsTagController.php | 10 +- .../Controllers/Front/ContactController.php | 19 ++- app/Http/Controllers/Front/HomeController.php | 7 +- .../Controllers/Front/PostsController.php | 144 +++++++++--------- .../StoreDocumentCategoryRequest.php | 2 +- .../UpdateDocumentCategoryRequest.php | 2 +- .../StoreDocumentTagRequest.php | 2 +- .../UpdateDocumentTagRequest.php | 2 +- .../StoreDocumentRequest.php | 2 +- .../UpdateDocumentRequest.php | 2 +- .../StoreNewsCategoryRequest.php | 2 +- .../UpdateNewsCategoryRequest.php | 2 +- .../StoreNewsTagRequest.php | 2 +- .../UpdateNewsTagRequest.php | 2 +- .../PageConfigs/StorePageConfigRequest.php | 2 +- app/Models/Company.php | 4 +- app/Models/CompanyActivity.php | 2 +- app/Models/CompanySector.php | 2 +- app/Models/ContactCount.php | 2 +- app/Models/Document.php | 54 +++++-- app/Models/DocumentCategory.php | 24 ++- app/Models/DocumentTag.php | 56 ++++--- app/Models/DynamicPage.php | 4 +- app/Models/MailContactData.php | 2 +- app/Models/News.php | 58 ++++--- app/Models/NewsCategory.php | 27 ++-- app/Models/NewsTag.php | 55 ++++--- app/Models/PageConfig.php | 36 +---- .../DynamicPageRouteServiceProvider.php | 1 + app/Traits/Models/HasCache.php | 12 +- app/Traits/Models/HasUwilImages.php | 8 +- .../Api/HasLaravelFailedValidation.php | 2 +- app/Traits/Requests/HasInertiaPicture.php | 4 +- .../Front/News/NewsNextEventComponent.php | 10 +- .../Front/Pages/KnowUs/OurImplantations.php | 6 +- 46 files changed, 400 insertions(+), 307 deletions(-) rename app/Http/Requests/Back/{DocumentCategory => DocumentCategories}/StoreDocumentCategoryRequest.php (93%) rename app/Http/Requests/Back/{DocumentCategory => DocumentCategories}/UpdateDocumentCategoryRequest.php (87%) rename app/Http/Requests/Back/{DocumentTag => DocumentTags}/StoreDocumentTagRequest.php (94%) rename app/Http/Requests/Back/{DocumentTag => DocumentTags}/UpdateDocumentTagRequest.php (87%) rename app/Http/Requests/Back/{Document => Documents}/StoreDocumentRequest.php (97%) rename app/Http/Requests/Back/{Document => Documents}/UpdateDocumentRequest.php (88%) rename app/Http/Requests/Back/{NewsCategory => NewsCategories}/StoreNewsCategoryRequest.php (95%) rename app/Http/Requests/Back/{NewsCategory => NewsCategories}/UpdateNewsCategoryRequest.php (87%) rename app/Http/Requests/Back/{NewsTag => NewsTags}/StoreNewsTagRequest.php (96%) rename app/Http/Requests/Back/{NewsTag => NewsTags}/UpdateNewsTagRequest.php (88%) diff --git a/app/Casts/LocalDateTime.php b/app/Casts/LocalDateTime.php index d025efae..4c5954b1 100644 --- a/app/Casts/LocalDateTime.php +++ b/app/Casts/LocalDateTime.php @@ -13,12 +13,12 @@ class LocalDateTime implements CastsAttributes * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key - * @param string|integer|null $value + * @param mixed $value * @param array $attributes * @return \Carbon\Carbon|null * @phpcs:disable */ - public function get(Model $model, string $key, string|int|null $value, array $attributes): ?\Carbon\Carbon + public function get(Model $model, string $key, mixed $value, array $attributes): ?\Carbon\Carbon { // phpcs:enable return $value @@ -31,12 +31,12 @@ class LocalDateTime implements CastsAttributes * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key - * @param string|integer|null $value + * @param mixed $value * @param array $attributes * @return \Carbon\Carbon|null * @phpcs:disable */ - public function set(Model $model, string $key, string|int|null $value, array $attributes): ?\Carbon\Carbon + public function set(Model $model, string $key, mixed $value, array $attributes): ?\Carbon\Carbon { // phpcs:enable return $value diff --git a/app/Enums/Contact/ContactFormType.php b/app/Enums/Contact/ContactFormType.php index 40fe725f..2be58a98 100644 --- a/app/Enums/Contact/ContactFormType.php +++ b/app/Enums/Contact/ContactFormType.php @@ -41,8 +41,6 @@ enum ContactFormType: int /** * Optionnal SUBTYPES definition. - * - * @phpstan-ignore-next-line */ private const SUBTYPES = [ self::professional->name => [ @@ -61,9 +59,9 @@ enum ContactFormType: int ]; /** - * Get Class + * Get sub type status. * - * @return string|null + * @return boolean */ public function isSubtype(): bool { @@ -77,8 +75,6 @@ enum ContactFormType: int /** * Optionnal TOPLEVELS definition. - * - * @phpstan-ignore-next-line */ private const TOPLEVELS = [ self::professional->name => true, @@ -94,43 +90,44 @@ enum ContactFormType: int ]; /** - * Get Class + * Get top level status. * - * @return string|null + * @return boolean */ - public function topLevel(): ?string + public function topLevel(): bool { return !empty(self::TOPLEVELS[$this->name]) ? self::TOPLEVELS[$this->name] : false; } /** - * Get the data-target + * Get the data-target. * - * @return string + * @return string|null */ - public function dataTarget(): string + public function dataTarget(): ?string { return match ($this) { self::professional => 'askPro', + default => null, }; } /** - * Get the subtitle + * Get the subtitle. * * @return string */ public function subtitle(): string { - return match (true) { - $this === self::restauration => __('enums.contactFormType.' . $this->name . '.subtitle'), + return match ($this) { + self::restauration => __('enums.contactFormType.' . $this->name . '.subtitle'), default => __('enums.contactFormType.' . $this->name . '.label'), }; } /** - * Get the slug for each type + * Get the slug for each type. * * @param string|null $locale * @return string|null @@ -154,7 +151,7 @@ enum ContactFormType: int } /** - * Check if current lang slug match in specific lang slug + * Check if current lang slug match in specific lang slug. * * @param string $slug * @param string $locale @@ -176,13 +173,13 @@ enum ContactFormType: int } /** - * Get the route + * Get the route. * * @return string|null */ public function route(): ?string { - $commonRoutes = [ + return match ($this) { self::collaborator, self::breeder, self::export, @@ -190,19 +187,15 @@ enum ContactFormType: int self::commitments, self::product, self::info, - self::restauration - ]; - return match (true) { - in_array($this, $commonRoutes, true) => route('front.contact.show', ['slug' => $this->slug()]), - $this === self::professional => null, - $this === self::press => - RouteHelper::routeNameChecker('front.dynamic-pages.espace-presse') . '#page-press-form', - default => null, + self::restauration => route('front.contact.show', ['slug' => $this->slug()]), + self::professional => null, + self::press => RouteHelper::routeNameChecker('front.dynamic-pages.espace-presse') + . '#page-press-form', }; } /** - * Get the route for the contact form type + * Get the route for the contact form type. * * @return array */ @@ -217,7 +210,7 @@ enum ContactFormType: int } /** - * Get the slug for each type + * Get the slug for each type. * * @return array */ @@ -245,7 +238,7 @@ enum ContactFormType: int } /** - * Get the slug for each type + * Get the slug for each type. * * @return array * @phpcs:disable Generic.Metrics.CyclomaticComplexity diff --git a/app/Enums/DynamicFieldTypes.php b/app/Enums/DynamicFieldTypes.php index c65d40bb..bd6e6c40 100644 --- a/app/Enums/DynamicFieldTypes.php +++ b/app/Enums/DynamicFieldTypes.php @@ -95,6 +95,7 @@ enum DynamicFieldTypes: int * Is array definition. * * @return array + * @phpstan-ignore-next-line */ private const ISARRAY = [ self::string->name => false, diff --git a/app/Enums/OrdersEnum.php b/app/Enums/OrdersEnum.php index 70e1618d..e750acec 100644 --- a/app/Enums/OrdersEnum.php +++ b/app/Enums/OrdersEnum.php @@ -21,18 +21,18 @@ enum OrdersEnum: int self::desc->name => 'enums.orders.desc', ]; - /** - * Get the orders to display using the app locale + * Get the orders to display using the app locale. * * @return boolean */ public function ordersWithLocal(): bool { $locale = config('app.locale'); - return match (true) { - $this === self::asc => true, - $this === self::desc => true, + return match ($this) { + self::asc, + /** @phpstan-ignore-next-line */ + self::desc => true, default => $locale === "fr" ? true : false, }; } diff --git a/app/Helpers/DynamicPageHelper.php b/app/Helpers/DynamicPageHelper.php index 66de6249..3a1da19b 100644 --- a/app/Helpers/DynamicPageHelper.php +++ b/app/Helpers/DynamicPageHelper.php @@ -6,9 +6,9 @@ use App\Enums\DynamicFieldTypes; use App\Enums\DynamicPages\PageStatusEnum; use App\Models\DynamicPage; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; use Uwil\LaravelCommon\Helpers\FileHelper; use Uwil\LaravelCommon\Helpers\ToolboxHelper; @@ -181,9 +181,9 @@ class DynamicPageHelper /** * Get all segments url for dynamic pages. * - * @param \App\Models\DynamicPage $page - * @param \Illuminate\Support\Collection $pages - * @param string $locale + * @param \App\Models\DynamicPage $page + * @param \Illuminate\Database\Eloquent\Collection $pages + * @param string $locale * @return array|null */ public static function getAllDynamicPageSegments(DynamicPage $page, Collection $pages, string $locale): ?array diff --git a/app/Helpers/RouteHelper.php b/app/Helpers/RouteHelper.php index 52f08da9..a984b899 100644 --- a/app/Helpers/RouteHelper.php +++ b/app/Helpers/RouteHelper.php @@ -88,9 +88,9 @@ class RouteHelper extends Controller * * @param \Illuminate\Routing\Route $route * @param string $localeCode - * @return string|false|null + * @return string|null */ - private static function getContactShowLocalizedUrl(Route $route, string $localeCode) + private static function getContactShowLocalizedUrl(Route $route, string $localeCode): ?string { $contactPage = $route->parameter('contactPage'); @@ -123,6 +123,8 @@ class RouteHelper extends Controller } return $localizedUrl; } //end if + + return null; } /** @@ -137,10 +139,10 @@ class RouteHelper extends Controller /** @var \App\Models\DynamicPage|null $dynamicPage */ $dynamicPage = $route->parameter('dynamicPage'); if ($dynamicPage instanceof DynamicPage) { - $path = $dynamicPage->getLocalizedPath($localeCode); - if ($path) { - return LaravelLocalization::getLocalizedURL($localeCode, "/{$path}", [], false); - } + $path = $dynamicPage->getLocalizedPath($localeCode); + $defPath = $path ?? ""; + return LaravelLocalization::getLocalizedURL($localeCode, "/{$defPath}", [], false); } + return null; } } diff --git a/app/Http/Controllers/Back/DocumentCategoryController.php b/app/Http/Controllers/Back/DocumentCategoryController.php index d4a15662..f889bb2f 100644 --- a/app/Http/Controllers/Back/DocumentCategoryController.php +++ b/app/Http/Controllers/Back/DocumentCategoryController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers\Back; -use App\Http\Requests\Back\DocumentCategory\StoreDocumentCategoryRequest; -use App\Http\Requests\Back\DocumentCategory\UpdateDocumentCategoryRequest; +use App\Http\Requests\Back\DocumentCategories\StoreDocumentCategoryRequest; +use App\Http\Requests\Back\DocumentCategories\UpdateDocumentCategoryRequest; use App\Models\DocumentCategory; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -99,7 +99,7 @@ class DocumentCategoryController extends Controller /** * Store a newly created resource. * - * @param \App\Http\Requests\Back\News\StoreDocumentCategoryRequest $request + * @param \App\Http\Requests\Back\DocumentCategories\StoreDocumentCategoryRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(StoreDocumentCategoryRequest $request): \Illuminate\Http\RedirectResponse @@ -131,8 +131,8 @@ class DocumentCategoryController extends Controller /** * Update the specified resource. * - * @param \App\Http\Requests\Back\News\UpdateDocumentCategoryRequest $request - * @param \App\Models\DocumentCategory $document_category + * @param \App\Http\Requests\Back\DocumentCategories\UpdateDocumentCategoryRequest $request + * @param \App\Models\DocumentCategory $document_category * @return \Illuminate\Http\RedirectResponse */ public function update( diff --git a/app/Http/Controllers/Back/DocumentController.php b/app/Http/Controllers/Back/DocumentController.php index 88908b5e..e70b3f68 100644 --- a/app/Http/Controllers/Back/DocumentController.php +++ b/app/Http/Controllers/Back/DocumentController.php @@ -5,8 +5,8 @@ namespace App\Http\Controllers\Back; use App\Enums\Document\DocumentStatusEnum; use App\Enums\YearsEnum; use App\Helpers\DocumentHelper; -use App\Http\Requests\Back\Document\StoreDocumentRequest; -use App\Http\Requests\Back\Document\UpdateDocumentRequest; +use App\Http\Requests\Back\Documents\StoreDocumentRequest; +use App\Http\Requests\Back\Documents\UpdateDocumentRequest; use App\Models\Document; use App\Models\DocumentCategory; use App\Models\DocumentTag; @@ -108,7 +108,7 @@ class DocumentController extends Controller /** * Store a newly created resource. * - * @param \App\Http\Requests\Back\Document\StoreDocumentRequest $request + * @param \App\Http\Requests\Back\Documents\StoreDocumentRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(StoreDocumentRequest $request): \Illuminate\Http\RedirectResponse @@ -144,8 +144,8 @@ class DocumentController extends Controller /** * Update the specified resource. * - * @param \App\Http\Requests\Back\Document\UpdateDocumentRequest $request - * @param \App\Models\Document $document + * @param \App\Http\Requests\Back\Documents\UpdateDocumentRequest $request + * @param \App\Models\Document $document * @return \Illuminate\Http\RedirectResponse */ public function update(UpdateDocumentRequest $request, Document $document): \Illuminate\Http\RedirectResponse diff --git a/app/Http/Controllers/Back/DocumentTagController.php b/app/Http/Controllers/Back/DocumentTagController.php index 283e0240..997a1681 100644 --- a/app/Http/Controllers/Back/DocumentTagController.php +++ b/app/Http/Controllers/Back/DocumentTagController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers\Back; -use App\Http\Requests\Back\DocumentTag\StoreDocumentTagRequest; -use App\Http\Requests\Back\DocumentTag\UpdateDocumentTagRequest; +use App\Http\Requests\Back\DocumentTags\StoreDocumentTagRequest; +use App\Http\Requests\Back\DocumentTags\UpdateDocumentTagRequest; use App\Models\DocumentTag; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -99,7 +99,7 @@ class DocumentTagController extends Controller /** * Store a newly created resource. * - * @param \App\Http\Requests\Back\News\StoreDocumentTagRequest $request + * @param \App\Http\Requests\Back\DocumentTags\StoreDocumentTagRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(StoreDocumentTagRequest $request): \Illuminate\Http\RedirectResponse @@ -131,8 +131,8 @@ class DocumentTagController extends Controller /** * Update the specified resource. * - * @param \App\Http\Requests\Back\News\UpdateDocumentTagRequest $request - * @param \App\Models\DocumentTag $document_tag + * @param \App\Http\Requests\Back\DocumentTags\UpdateDocumentTagRequest $request + * @param \App\Models\DocumentTag $document_tag * @return \Illuminate\Http\RedirectResponse */ public function update( diff --git a/app/Http/Controllers/Back/InputsController.php b/app/Http/Controllers/Back/InputsController.php index ab5d429b..bee37888 100644 --- a/app/Http/Controllers/Back/InputsController.php +++ b/app/Http/Controllers/Back/InputsController.php @@ -119,7 +119,7 @@ class InputsController extends Controller $url = (method_exists($modelClass, 'getAccessModel')) ? $modelClass::getAccessModel($validated['selectedEntry']) - : static::getAccessModel($validated['selectedEntry'], $validated['modelName']); + : self::getAccessModel($validated['selectedEntry'], $validated['modelName']); $token = Crypt::encryptString(json_encode([ 'modelName' => $validated['modelName'], diff --git a/app/Http/Controllers/Back/NewsCategoryController.php b/app/Http/Controllers/Back/NewsCategoryController.php index d7a3f44f..94706934 100644 --- a/app/Http/Controllers/Back/NewsCategoryController.php +++ b/app/Http/Controllers/Back/NewsCategoryController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers\Back; use App\Enums\News\NewsStatusEnum; -use App\Http\Requests\Back\NewsCategory\StoreNewsCategoryRequest; -use App\Http\Requests\Back\NewsCategory\UpdateNewsCategoryRequest; +use App\Http\Requests\Back\NewsCategories\StoreNewsCategoryRequest; +use App\Http\Requests\Back\NewsCategories\UpdateNewsCategoryRequest; use App\Models\NewsCategory; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -102,7 +102,7 @@ class NewsCategoryController extends Controller /** * Store a newly created resource. * - * @param \App\Http\Requests\Back\NewsCategory\StoreNewsCategoryRequest $request + * @param \App\Http\Requests\Back\NewsCategories\StoreNewsCategoryRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(StoreNewsCategoryRequest $request): \Illuminate\Http\RedirectResponse @@ -134,8 +134,8 @@ class NewsCategoryController extends Controller /** * Update the specified resource. * - * @param \App\Http\Requests\Back\News\UpdateNewsCategoryRequest $request - * @param \App\Models\NewsCategory $news_category + * @param \App\Http\Requests\Back\NewsCategories\UpdateNewsCategoryRequest $request + * @param \App\Models\NewsCategory $news_category * @return \Illuminate\Http\RedirectResponse */ public function update( diff --git a/app/Http/Controllers/Back/NewsTagController.php b/app/Http/Controllers/Back/NewsTagController.php index 1d852c26..03277188 100644 --- a/app/Http/Controllers/Back/NewsTagController.php +++ b/app/Http/Controllers/Back/NewsTagController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers\Back; use App\Enums\News\NewsStatusEnum; -use App\Http\Requests\Back\NewsTag\StoreNewsTagRequest; -use App\Http\Requests\Back\NewsTag\UpdateNewsTagRequest; +use App\Http\Requests\Back\NewsTags\StoreNewsTagRequest; +use App\Http\Requests\Back\NewsTags\UpdateNewsTagRequest; use App\Models\NewsTag; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -102,7 +102,7 @@ class NewsTagController extends Controller /** * Store a newly created resource. * - * @param \App\Http\Requests\Back\NewsTag\StoreNewsTagRequest $request + * @param \App\Http\Requests\Back\NewsTags\StoreNewsTagRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(StoreNewsTagRequest $request): \Illuminate\Http\RedirectResponse @@ -134,8 +134,8 @@ class NewsTagController extends Controller /** * Update the specified resource. * - * @param \App\Http\Requests\Back\News\UpdateNewsTagRequest $request - * @param \App\Models\NewsTag $news_tag + * @param \App\Http\Requests\Back\NewsTags\UpdateNewsTagRequest $request + * @param \App\Models\NewsTag $news_tag * @return \Illuminate\Http\RedirectResponse */ public function update(UpdateNewsTagRequest $request, NewsTag $news_tag): \Illuminate\Http\RedirectResponse diff --git a/app/Http/Controllers/Front/ContactController.php b/app/Http/Controllers/Front/ContactController.php index 69622479..427bd3b2 100644 --- a/app/Http/Controllers/Front/ContactController.php +++ b/app/Http/Controllers/Front/ContactController.php @@ -8,6 +8,7 @@ use App\Http\Requests\Front\Contact\ContactRequest; use App\Jobs\Mails\SendContactMail; use App\Models\ContactCount; use App\Models\MailContactData; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\HtmlString; use LDC\LDCCRM\Enums\ApiError; @@ -32,9 +33,9 @@ class ContactController * Show contact show page. * * @param string $slug - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\View */ - public function show(string $slug): \Illuminate\Contracts\View\View + public function show(string $slug): \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\View { $enumType = collect(ContactFormType::all())->first(function ($enum) use ($slug) { return $enum->slug() === $slug; @@ -53,12 +54,16 @@ class ContactController */ public function send(ContactRequest $request): \Illuminate\Http\RedirectResponse { - $data = $request->validated(); - $messageContact = new MailContactData($data); + $validatedData = $request->validated(); + $messageContact = new MailContactData($validatedData); $contactMessage = ""; $hasContactError = false; $newsletterMessage = null; $hasNewsletterError = false; + + /** @var boolean $isNewsletter */ + $isNewsletter = $validatedData['newsletter']; + try { dispatch(new SendContactMail($messageContact)) ->onConnection('database') @@ -70,7 +75,7 @@ class ContactController $hasContactError = true; $contactMessage = trans('Une erreur est survenue lors de l\'envoi du message de contact.'); } - if (!empty($data['newsletter']) && $data['newsletter']) { + if ($isNewsletter) { try { SingleOptin::setStatus($request->email, true); $newsletterMessage = trans("Votre inscription à la newsletter a été prise en compte"); @@ -90,8 +95,8 @@ class ContactController } } ContactCount::updateOrInsert( - ['type' => $data['enumType']], - ['submissions' => \DB::raw('submissions + 1')] + ['type' => $validatedData['enumType']], + ['submissions' => DB::raw('submissions + 1')] ); $contactMessage = trans('Votre message a bien été envoyé.'); diff --git a/app/Http/Controllers/Front/HomeController.php b/app/Http/Controllers/Front/HomeController.php index e3e08844..05c17fd2 100644 --- a/app/Http/Controllers/Front/HomeController.php +++ b/app/Http/Controllers/Front/HomeController.php @@ -68,13 +68,14 @@ class HomeController extends Controller /** * Call the CRM to add a single optin * - * @param \App\Http\Requests\Fo\SingleOptinRequest $request + * @param \App\Http\Requests\Front\SingleOptinRequest $request * @return string|array|null|\Illuminate\Contracts\Translation\Translator * @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException. * @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException. */ - public function addOptIn(SingleOptinRequest $request) - { + public function addOptIn( + SingleOptinRequest $request, + ): string|array|null|\Illuminate\Contracts\Translation\Translator { try { SingleOptin::setStatus($request->email, true); return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200); diff --git a/app/Http/Controllers/Front/PostsController.php b/app/Http/Controllers/Front/PostsController.php index 64637619..00b63f3c 100644 --- a/app/Http/Controllers/Front/PostsController.php +++ b/app/Http/Controllers/Front/PostsController.php @@ -2,16 +2,17 @@ namespace App\Http\Controllers\Front; -use Carbon\Carbon; +use App\Enums\OrdersEnum; +use App\Enums\YearsEnum; +use App\Http\Requests\Front\PostsRequest; +use App\Models\Document; +use App\Models\DocumentTag; use App\Models\News; use App\Models\NewsTag; -use App\Enums\YearsEnum; -use App\Models\Document; -use App\Enums\OrdersEnum; -use App\Models\DocumentTag; -use Illuminate\Support\Str; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; -use App\Http\Requests\Front\PostsRequest; +use Illuminate\Support\Str; use Uwil\LaravelCommon\Controllers\Controller; use Uwil\LaravelCommon\Helpers\CollectionHelper; @@ -26,12 +27,14 @@ class PostsController extends Controller /** * Extract unique years from date field in a collection. * - * @param \Illuminate\Support\Collection $model - * @param string $field + * @param EloquentCollection $model + * @param string $field * @return \Illuminate\Support\Collection */ - private function getUniqueYearsFromCollection(Collection $model, string $field): \Illuminate\Support\Collection - { + private function getUniqueYearsFromCollection( + EloquentCollection $model, + string $field, + ): \Illuminate\Support\Collection { return $model->pluck($field) ->map(fn($date) => Carbon::parse($date)->year) ->unique() @@ -55,27 +58,30 @@ class PostsController extends Controller } /** - * Build the common filters configuration for front-end listing pages + * Build the common filters configuration for front-end listing pages. + * If the type is "documents" the "order" filter is included. * - * If the type is "documents" the "order" filter is included - * - * @param string $type - * @param string $category - * @param \Illuminate\Database\Eloquent\Collection $publishedTags - * @param \Illuminate\Database\Eloquent\Collection $model + * @param string $type + * @param string $category + * @param EloquentCollection $publishedTags + * @param EloquentCollection $model * @return array */ - private function getFilters(string $type, string $category, Collection $publishedTags, Collection $model): array - { + private function getFilters( + string $type, + string $category, + EloquentCollection $publishedTags, + EloquentCollection $model, + ): array { $filters = []; - $tags = collect($publishedTags) - ->map(fn($tag) => [ - 'title' => $tag->name, - 'tag' => $tag->slug, - 'category' => $category, - ]) - ->values(); + /** @phpstan-ignore-next-line */ + $tags = $publishedTags->map(fn(DocumentTag|NewsTag $tag) => [ + 'title' => $tag->name, + 'tag' => $tag->slug, + 'category' => $category, + ]) + ->values(); $enumYears = collect(YearsEnum::toArray()) ->map(fn($year) => YearsEnum::make((int) $year->value)) @@ -140,18 +146,19 @@ class PostsController extends Controller */ public function ajaxLoadNews(PostsRequest $request): \Illuminate\Http\JsonResponse { - $data = $request->validated(); + $validatedData = $request->validated(); $perPage = 9; $selectedFilters = []; - $category = $data['category']; - app()->setLocale($data['locale']); + /** @var string $slugCategory */ + $slugCategory = $validatedData['category']; - $publishedNewsTags = NewsTag::getTagsByCategoryInCurrentLocale($category); + app()->setLocale($validatedData['locale']); - $newsModel = News::getPublishedNewsByCategoryInCurrentLocale($category); + $publishedNewsTags = NewsTag::getTagsByCategoryInCurrentLocale($slugCategory); + $newsModel = News::getPublishedNewsByCategoryInCurrentLocale($slugCategory); - $requestedTags = collect($data['filters']['tags'] ?? '') + $requestedTags = collect($validatedData['filters']['tags'] ?? '') ->filter() ->unique() ->values(); @@ -162,13 +169,13 @@ class PostsController extends Controller 'title' => $tag->name, 'tag' => $tag->slug, 'color' => $tag->color, - 'category' => $category, + 'category' => $slugCategory, ]) ->values(); if ($selectedTags->isNotEmpty()) { - $newsModel = $newsModel->filter(function ($news) use ($selectedTags) { - return $news->tags->contains( + $newsModel = $newsModel->filter(function ($newsModel) use ($selectedTags) { + return $newsModel->tags->contains( fn ($tag) => $selectedTags->contains('id', $tag->id) ); }); @@ -176,14 +183,14 @@ class PostsController extends Controller $selectedFilters['tags'] = $selectedTags; } - $selectedYears = collect($data['filters']['years'] ?? '') + $selectedYears = collect($validatedData['filters']['years'] ?? '') ->map(fn (string $label) => YearsEnum::makeFromLabel(Str::replace('-', '/', $label))) ->filter() ->map(fn($year) => [ 'title' => $year->label(), 'tag' => Str::replace('/', '-', $year->label()), 'value' => explode('/', $year->label())[1], - 'category' => $category, + 'category' => $slugCategory, ]) ->values(); @@ -197,7 +204,7 @@ class PostsController extends Controller $newsModel = $newsModel->sortByDesc('published_at'); - $filters = $this->getFilters('news', $category, $publishedNewsTags, $newsModel); + $filters = $this->getFilters('news', $slugCategory, $publishedNewsTags, $newsModel); // Custom pagination. $newsModel = CollectionHelper::paginate($newsModel, $perPage); @@ -227,36 +234,36 @@ class PostsController extends Controller */ public function ajaxLoadDocuments(PostsRequest $request): \Illuminate\Http\JsonResponse { - $data = $request->validated(); + $validatedData = $request->validated(); $perPage = 3; $selectedFilters = []; - $category = $data['category']; - app()->setLocale($data['locale']); + /** @var string $slugCategory */ + $slugCategory = $validatedData['category']; - $publishedDocumentsTags = DocumentTag::getTagsByCategoryInCurrentLocale($category); + app()->setLocale($validatedData['locale']); - $documentsModel = Document::getPublishedDocumentsByCategoryInCurrentLocale($category); + $documentTagModels = DocumentTag::getTagsByCategoryInCurrentLocale($slugCategory); + $documentModels = Document::getPublishedDocumentsByCategoryInCurrentLocale($slugCategory); - $requestedTags = collect($data['filters']['tags'] ?? '') + $requestedTags = collect($validatedData['filters']['tags'] ?? '') ->filter() ->unique() ->values(); - - $selectedTags = $publishedDocumentsTags + $selectedTags = $documentTagModels ->filter(fn ($tag) => $requestedTags->contains($tag->slug ?? null)) ->map(fn ($tag) => [ 'id' => $tag->id, 'title' => $tag->name, 'tag' => $tag->slug, 'color' => $tag->color, - 'category' => $category, + 'category' => $slugCategory, ]) ->values(); if ($selectedTags->isNotEmpty()) { - $documentsModel = $documentsModel->filter(function ($documents) use ($selectedTags) { - return $documents->tags->contains( + $documentModels = $documentModels->filter(function ($documentModel) use ($selectedTags) { + return $documentModel->tags->contains( fn ($tag) => $selectedTags->contains('id', $tag->id) ); }); @@ -264,64 +271,65 @@ class PostsController extends Controller $selectedFilters['tags'] = $selectedTags; } - $selectedYears = collect($data['filters']['years'] ?? '') + $selectedYears = collect($validatedData['filters']['years'] ?? '') ->map(fn (string $label) => YearsEnum::makeFromLabel(Str::replace('-', '/', $label))) ->filter() ->map(fn($year) => [ 'title' => $year->label(), 'tag' => Str::replace('/', '-', $year->label()), 'value' => $year->value, - 'category' => $category, + 'category' => $slugCategory, ]) ->values(); if ($selectedYears->isNotEmpty()) { - $documentsModel = $documentsModel->filter(function ($documents) use ($selectedYears) { - return $selectedYears->contains('value', $documents->exercice); + $documentModels = $documentModels->filter(function ($documentModel) use ($selectedYears) { + return $selectedYears->contains('value', $documentModel->exercice); }); $selectedFilters['years'] = $selectedYears; } - $selectedOrder = collect($data['filters']['order'] ?? '') + $selectedOrder = collect($validatedData['filters']['order'] ?? '') ->map(fn (string $label) => OrdersEnum::makeFromLabel($label)) ->filter() ->map(fn($order) => [ 'title' => trans($order->label()), 'tag' => $order->name(), - 'category' => $category, + 'category' => $slugCategory, ]) ->values(); if ($selectedOrder->isNotEmpty()) { - $documentsModel = $selectedOrder->map->tag->first() === 'desc' - ? $documentsModel->sortByDesc('published_at') - : $documentsModel->sortBy('published_at'); + $firstTag = $selectedOrder->map(fn($order) => $order['tag'])->first(); + $documentModels = $firstTag === 'desc' + ? $documentModels->sortByDesc('published_at') + : $documentModels->sortBy('published_at'); $selectedFilters['order'] = $selectedOrder->all(); } else { - $documentsModel = $documentsModel->sortByDesc('published_at'); + $documentModels = $documentModels->sortByDesc('published_at'); } - $filters = $this->getFilters('documents', $category, $publishedDocumentsTags, $documentsModel); + $filters = $this->getFilters('documents', $slugCategory, $documentTagModels, $documentModels); // Custom pagination. - $documentsModel = CollectionHelper::paginate($documentsModel, $perPage); + $documentModels = CollectionHelper::paginate($documentModels, $perPage); return response()->json([ 'pagination' => [ - 'total' => $documentsModel->total(), - 'nbItems' => count($documentsModel->items()), - 'currentPage' => $documentsModel->currentPage(), - 'lastPage' => $documentsModel->lastPage(), - 'hasMore' => $documentsModel->currentPage() < $documentsModel->lastPage(), + 'total' => $documentModels->total(), + 'nbItems' => count($documentModels->items()), + 'currentPage' => $documentModels->currentPage(), + 'lastPage' => $documentModels->lastPage(), + 'hasMore' => $documentModels->currentPage() < $documentModels->lastPage(), ], 'filters' => view('components.front.posts.filters-dropdowns', ['filters' => $filters])->render(), 'selectedFilters' => view('components.front.posts.selected-filters', [ 'selectedFilters' => $selectedFilters, ])->render(), 'news' => view('components.front.posts.documents', [ - 'documentsList' => $documentsModel->items(), + 'documentsList' => $documentModels->items(), ])->render() ]); } diff --git a/app/Http/Requests/Back/DocumentCategory/StoreDocumentCategoryRequest.php b/app/Http/Requests/Back/DocumentCategories/StoreDocumentCategoryRequest.php similarity index 93% rename from app/Http/Requests/Back/DocumentCategory/StoreDocumentCategoryRequest.php rename to app/Http/Requests/Back/DocumentCategories/StoreDocumentCategoryRequest.php index 51b71635..c1a961e8 100644 --- a/app/Http/Requests/Back/DocumentCategory/StoreDocumentCategoryRequest.php +++ b/app/Http/Requests/Back/DocumentCategories/StoreDocumentCategoryRequest.php @@ -1,6 +1,6 @@ input(), $parentPath, []); $keysAtLevel = collect($levelItems)->pluck('key')->filter()->toArray(); diff --git a/app/Models/Company.php b/app/Models/Company.php index 585d807b..3bd4360c 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -39,7 +39,7 @@ class Company extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', @@ -67,7 +67,7 @@ class Company extends Model /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'companyActivity', diff --git a/app/Models/CompanyActivity.php b/app/Models/CompanyActivity.php index 0f8b11ef..573023d8 100644 --- a/app/Models/CompanyActivity.php +++ b/app/Models/CompanyActivity.php @@ -33,7 +33,7 @@ class CompanyActivity extends Model implements TranslatableModel /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', diff --git a/app/Models/CompanySector.php b/app/Models/CompanySector.php index 7468af8f..bd5df3d0 100644 --- a/app/Models/CompanySector.php +++ b/app/Models/CompanySector.php @@ -32,7 +32,7 @@ class CompanySector extends Model implements TranslatableModel /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', diff --git a/app/Models/ContactCount.php b/app/Models/ContactCount.php index 95371c91..ed1bb15f 100644 --- a/app/Models/ContactCount.php +++ b/app/Models/ContactCount.php @@ -10,7 +10,7 @@ class ContactCount extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'type', diff --git a/app/Models/Document.php b/app/Models/Document.php index 1c2f1fe2..9d885364 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -18,6 +18,32 @@ use Illuminate\Support\Facades\App; use Laravel\Scout\Searchable; use Uwil\LaravelActivityLogs\Traits\ActivityLog; +/** + * @property integer $id + * Id of the document. + * @property string $name + * Name of the document. + * @property string $path + * Path of the document. + * @property boolean $is_issuu + * Issu status of the document. + * @property string $issuu_path + * Issu path of the document. + * @property string $exercice + * Exercice of the document. + * @property \App\Enums\Document\DocumentStatusEnum $status + * Status of the document. + * @property-read \Carbon\Carbon $created_at + * Created date of the document. + * @property-read \Carbon\Carbon $updated_at + * Updated date of the document. + * @property-read \Illuminate\Support\Carbon $deleted_at + * Deleted date of the document. + * @property \Illuminate\Database\Eloquent\Collection $categories + * Associated document categories of the document. + * @property \Illuminate\Database\Eloquent\Collection $tags + * Associated document tags of the document. + */ class Document extends Model implements TranslatableModel { use ActivityLog; @@ -81,7 +107,7 @@ class Document extends Model implements TranslatableModel /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'categories', @@ -324,24 +350,24 @@ class Document extends Model implements TranslatableModel /** * Get all published news by category. * - * @param string $category - * - * @return \Illuminate\Database\Eloquent\Collection + * @param string $slugCategory + * @return \Illuminate\Database\Eloquent\Collection */ - public static function getPublishedDocumentsByCategoryInCurrentLocale(string $category) - { + public static function getPublishedDocumentsByCategoryInCurrentLocale( + string $slugCategory, + ): \Illuminate\Database\Eloquent\Collection { $locale = App::getLocale(); return Document::getModelsCached() ->where('status', DocumentStatusEnum::published) - ->filter(function ($document) use ($category, $locale) { + ->filter(function ($document) use ($slugCategory, $locale) { $hasPath = !empty($document->getTranslation('path', $locale, false)); $hasIssuuPath = $document->is_issuu === true && !empty($document->getTranslation('issuu_path', $locale, false)); return ($hasPath || $hasIssuuPath) && $document->categories->contains( - fn($cat) => $cat->slug === $category + fn($documentCategoryModel) => $documentCategoryModel->slug === $slugCategory ); }); } @@ -349,11 +375,11 @@ class Document extends Model implements TranslatableModel // * RELATIONSHIPS /** - * Relation to Tag + * Relation to Tag. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphedByMany( DocumentTag::class, @@ -365,11 +391,11 @@ class Document extends Model implements TranslatableModel } /** - * Relation to Category + * Relation to Category. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function categories(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphedByMany( DocumentCategory::class, diff --git a/app/Models/DocumentCategory.php b/app/Models/DocumentCategory.php index 172d7427..d75a28a7 100644 --- a/app/Models/DocumentCategory.php +++ b/app/Models/DocumentCategory.php @@ -10,6 +10,22 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Uwil\LaravelActivityLogs\Traits\ActivityLog; +/** + * @property integer $id + * Id of the category. + * @property string $name + * Name of the category. + * @property string $slug + * Slug of the category. + * @property-read \Carbon\Carbon $created_at + * Created date of the category. + * @property-read \Carbon\Carbon $updated_at + * Updated date of the category. + * @property-read \Illuminate\Support\Carbon $deleted_at + * Deleted date of the category. + * @property \Illuminate\Database\Eloquent\Collection $documents + * Associated documents of the category. + */ class DocumentCategory extends Model implements TranslatableModel { use ActivityLog; @@ -38,12 +54,14 @@ class DocumentCategory extends Model implements TranslatableModel 'slug' ]; + // * RELATIONSHIPS + /** - * Relation to Document + * Associated documents of the category. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function documents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function documents(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany( Document::class, diff --git a/app/Models/DocumentTag.php b/app/Models/DocumentTag.php index e1a36685..758ad084 100644 --- a/app/Models/DocumentTag.php +++ b/app/Models/DocumentTag.php @@ -11,6 +11,24 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\App; use Uwil\LaravelActivityLogs\Traits\ActivityLog; +/** + * @property integer $id + * Id of the tag. + * @property string $name + * Name of the tag. + * @property string $slug + * Slug of the tag. + * @property string $color + * Color of the tag. + * @property-read \Carbon\Carbon $created_at + * Created date of the tag. + * @property-read \Carbon\Carbon $updated_at + * Updated date of the tag. + * @property-read \Illuminate\Support\Carbon $deleted_at + * Deleted date of the tag. + * @property \Illuminate\Database\Eloquent\Collection $documents + * Associated documents of the tag. + */ class DocumentTag extends Model implements TranslatableModel { use ActivityLog; @@ -43,34 +61,20 @@ class DocumentTag extends Model implements TranslatableModel /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'documents', ]; - /** - * Relation to Document - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function documents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany - { - return $this->morphToMany( - Document::class, - 'documentable', - 'documentables', - 'documentable_id', - 'document_id' - ); - } + // * METHODS /** * Get all Tags by category. * * @param string $slugCategory * - * @return \Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public static function getTagsByCategoryInCurrentLocale( string $slugCategory, @@ -92,4 +96,22 @@ class DocumentTag extends Model implements TranslatableModel })->isNotEmpty(); }); } + + // * RELATIONSHIPS + + /** + * Associated documents of the tag. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function documents(): \Illuminate\Database\Eloquent\Relations\MorphToMany + { + return $this->morphToMany( + Document::class, + 'documentable', + 'documentables', + 'documentable_id', + 'document_id' + ); + } } diff --git a/app/Models/DynamicPage.php b/app/Models/DynamicPage.php index 4efa7114..0cc38702 100644 --- a/app/Models/DynamicPage.php +++ b/app/Models/DynamicPage.php @@ -86,7 +86,7 @@ class DynamicPage extends Model implements TranslatableModel /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'config', @@ -327,7 +327,7 @@ class DynamicPage extends Model implements TranslatableModel /** * Get fields that we want to keep in the current locale. * - * @return array. + * @return array */ public static function searchTransFields(): array { diff --git a/app/Models/MailContactData.php b/app/Models/MailContactData.php index b9a267d3..4802274d 100644 --- a/app/Models/MailContactData.php +++ b/app/Models/MailContactData.php @@ -44,7 +44,7 @@ class MailContactData extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'enumType', diff --git a/app/Models/News.php b/app/Models/News.php index 3b0b7bae..429e6f3c 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -21,21 +21,40 @@ use Mcamara\LaravelLocalization\Interfaces\LocalizedUrlRoutable; use Uwil\LaravelActivityLogs\Traits\ActivityLog; /** - * @property string $seo_title SEO title of the news. - * @property string $seo_description SEO description of the news. - * @property string $title Title of the news. - * @property string $slug Slug of the news. - * @property string $picture Main img of the news. - * @property string $picture_alt Alt text for the picture. - * @property string $picture_title Title for the picture. - * @property string $content Content of the news. - * @property boolean $inverted Are image and content inverted in front - * @property string $vimeo_id Optionnal vimeo_id - * @property boolean $has_show_picture Show the picture in the show page - * @property \App\Enums\News\NewsStatusEnum $status Status of the news. - * @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created. - * @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated. - * @property-read \Illuminate\Support\Carbon $deleted_at Date on which the news was updated. + * @property string $seo_title + * SEO title of the news. + * @property string $seo_description + * SEO description of the news. + * @property string $title + * Title of the news. + * @property string $slug + * Slug of the news. + * @property string $picture + * Main img of the news. + * @property string $picture_alt + * Alt text for the picture. + * @property string $picture_title + * Title for the picture. + * @property string $content + * Content of the news. + * @property boolean $inverted + * Are image and content inverted in front + * @property string $vimeo_id + * Optionnal vimeo_id + * @property boolean $has_show_picture + * Show the picture in the show page + * @property \App\Enums\News\NewsStatusEnum $status + * Status of the news. + * @property-read \Illuminate\Support\Carbon $created_at + * Date on which the news was created. + * @property-read \Illuminate\Support\Carbon $updated_at + * Date on which the news was updated. + * @property-read \Illuminate\Support\Carbon $deleted_at + * Date on which the news was updated. + * @property \Illuminate\Database\Eloquent\Collection $categories + * Associated news categories of the news. + * @property \Illuminate\Database\Eloquent\Collection $tags + * Associated news tags of the news. */ class News extends Model implements TranslatableModel, LocalizedUrlRoutable { @@ -145,7 +164,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'categories', @@ -332,9 +351,9 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable * Get the url to access a specific resource. * * @param integer $id Id field of the target model. - * @return string + * @return string|null */ - public static function getAccessModel(int $id): string + public static function getAccessModel(int $id): ?string { $targetModel = self::getModelsCached()->firstWhere('id', $id); if (!$targetModel) { @@ -432,8 +451,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable * Get all published news by category. * * @param string $category - * - * @return \Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public static function getPublishedNewsByCategoryInCurrentLocale(string $category) { diff --git a/app/Models/NewsCategory.php b/app/Models/NewsCategory.php index 8b59b438..395ad563 100644 --- a/app/Models/NewsCategory.php +++ b/app/Models/NewsCategory.php @@ -8,16 +8,21 @@ use App\Traits\Models\HasCache; use App\Traits\Models\HasTranslations; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Str; use Uwil\LaravelActivityLogs\Traits\ActivityLog; /** - * @property int $news_id News focused. - * @property string $name Name of the category. - * @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created. - * @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated. + * @property int $id + * Id of the news. + * @property string $name + * Name of the category. + * @property-read \Illuminate\Support\Carbon $created_at + * Date on which the category was created. + * @property-read \Illuminate\Support\Carbon $updated_at + * Date on which the category was updated. + * @property \Illuminate\Database\Eloquent\Collection $news + * Associated news of the category. */ class NewsCategory extends Model implements TranslatableModel { @@ -30,7 +35,7 @@ class NewsCategory extends Model implements TranslatableModel /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', @@ -63,6 +68,8 @@ class NewsCategory extends Model implements TranslatableModel }); } + // * METHODS + /** * Manage model fields. * @@ -80,12 +87,14 @@ class NewsCategory extends Model implements TranslatableModel TranslationHelper::validateFallbackTranslations($model); } + // * RELATIONSHIPS + /** - * The relation with News + * Associated news of the category. * - * @return BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function news(): BelongsToMany + public function news(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany( News::class, diff --git a/app/Models/NewsTag.php b/app/Models/NewsTag.php index 7ad6a39f..04b7435d 100644 --- a/app/Models/NewsTag.php +++ b/app/Models/NewsTag.php @@ -12,11 +12,18 @@ use Uwil\LaravelActivityLogs\Traits\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; /** - * @property int $news_id News focused. - * @property string $name Name of the tag. - * @property string $color Color of the tag - * @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created. - * @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated. + * @property int $news_id + * News focused. + * @property string $name + * Name of the tag. + * @property string $color + * Color of the tag + * @property-read \Illuminate\Support\Carbon $created_at + * Date on which the tag was created. + * @property-read \Illuminate\Support\Carbon $updated_at + * Date on which the tag was updated. + * @property \Illuminate\Database\Eloquent\Collection $news + * Associated news of the tag. */ class NewsTag extends Model implements TranslatableModel { @@ -50,33 +57,19 @@ class NewsTag extends Model implements TranslatableModel /** * Relations should be included in the cache. * - * @var array + * @var list */ protected static $cacheRelations = [ 'news', ]; - /** - * Relation to Document - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function news(): \Illuminate\Database\Eloquent\Relations\BelongsToMany - { - return $this->morphToMany( - News::class, - 'newsable', - 'newsables', - 'newsable_id', - 'news_id' - ); - } + // * METHODS /** * Get all Tags by category. * * @param string $slugCategory - * @return \Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public static function getTagsByCategoryInCurrentLocale( string $slugCategory, @@ -93,4 +86,22 @@ class NewsTag extends Model implements TranslatableModel })->isNotEmpty(); }); } + + // * RELATIONSHIPS + + /** + * Associated news of the tag. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function news(): \Illuminate\Database\Eloquent\Relations\MorphToMany + { + return $this->morphToMany( + News::class, + 'newsable', + 'newsables', + 'newsable_id', + 'news_id' + ); + } } diff --git a/app/Models/PageConfig.php b/app/Models/PageConfig.php index 03f5cf47..2936c572 100644 --- a/app/Models/PageConfig.php +++ b/app/Models/PageConfig.php @@ -113,51 +113,21 @@ class PageConfig extends Model implements TranslatableModel TranslationHelper::validateFallbackTranslations($model); } - /** - * Check if the config is updated. - * - * @param array $newArray - * @param array $originalArray - * @return boolean - */ - private static function isConfigUpdated(array $newArray, array $originalArray): bool - { - if (count($newArray) !== count($originalArray)) { - return false; - } - - foreach ($newArray as $i => $subA) { - $subB = $originalArray[$i] ?? null; - if ($subB === null) { - return false; - } - - ksort($subA); - ksort($subB); - - if ($subA != $subB) { - return false; - } - } - - return true; - } - /** * Get the target model from a specific id and model name. * * @param string $modelId * @param string $modelName - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|null */ public static function getModelFromInputModelConfig( string $modelId, string $modelName, - ): \Illuminate\Database\Eloquent\Model { + ): ?\Illuminate\Database\Eloquent\Model { $studly = Str::studly(Str::singular($modelName)); $class = "App\\Models\\{$studly}"; - if (!$class || !class_exists($class)) { + if (!class_exists($class)) { return null; } diff --git a/app/Providers/DynamicPageRouteServiceProvider.php b/app/Providers/DynamicPageRouteServiceProvider.php index b71a0317..3a5562ad 100644 --- a/app/Providers/DynamicPageRouteServiceProvider.php +++ b/app/Providers/DynamicPageRouteServiceProvider.php @@ -53,6 +53,7 @@ class DynamicPageRouteServiceProvider extends ServiceProvider $slug = $dynamicPageModel->getTranslation('slug', $locale); // If no slug for the locale → skip. + /** @phpstan-ignore-next-line */ if (!empty($slug) && !$slug) { continue; } diff --git a/app/Traits/Models/HasCache.php b/app/Traits/Models/HasCache.php index 396366f1..df9dfefc 100644 --- a/app/Traits/Models/HasCache.php +++ b/app/Traits/Models/HasCache.php @@ -28,10 +28,13 @@ trait HasCache static::deleted(function () { self::resetCache(); }); + /** @phpstan-ignore-next-line */ if (method_exists(static::class, 'initializeSoftDeletes')) { + /** @phpstan-ignore-next-line */ static::restored(function () { self::resetCache(); }); + /** @phpstan-ignore-next-line */ static::forceDeleted(function () { self::resetCache(); }); @@ -57,11 +60,12 @@ trait HasCache public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection { return Cache::remember(static::getCacheKey(), 86400, function () { + /** @var class-string $class */ $class = static::class; - - /** @var \Illuminate\Database\Eloquent\Model $class */ + /** @phpstan-ignore-next-line */ return $class::query() ->when( + /** @phpstan-ignore-next-line */ property_exists($class, 'cacheRelations') && is_array($class::$cacheRelations), function ($query) use ($class) { $query->with($class::$cacheRelations); @@ -76,8 +80,8 @@ trait HasCache * * @return string */ - private static function getCacheKey(): string + public static function getCacheKey(): string { - return 'cache_' . str_replace('\\', '_', static::class); + return sprintf("cache_%s", str_replace('\\', '_', static::class)); } } diff --git a/app/Traits/Models/HasUwilImages.php b/app/Traits/Models/HasUwilImages.php index 593843ab..eaadb519 100644 --- a/app/Traits/Models/HasUwilImages.php +++ b/app/Traits/Models/HasUwilImages.php @@ -42,9 +42,11 @@ trait HasUwilImages */ protected static function bootHasUwilImages(): void { + /** @phpstan-ignore-next-line */ $hadSoftDelete = method_exists(static::class, 'initializeSoftDeletes'); if ($hadSoftDelete) { + /** @phpstan-ignore-next-line */ static::forceDeleted(function (self $model) { self::initLoop($model, self::FORCE_DELETE_ACTION); }); @@ -134,9 +136,8 @@ trait HasUwilImages continue; } //end if - // PAS TESTE. + // TODO pas testé if (is_array($originalValue) && is_array($currentValue)) { - dd('juste array'); static::traverseAndManage( $model, $originalValue, @@ -168,7 +169,7 @@ trait HasUwilImages $forceDeleteImage = $eventType === self::FORCE_DELETE_ACTION; $imagesFields = self::getImageFields($model); $wysiwygFields = self::getWysiwygFields($model); - $isTranslatable = method_exists($model, 'getTranslations') ?? false; + $isTranslatable = method_exists($model, 'getTranslations'); $locale = config('app.locale'); $availableLocales = array_keys(config('laravellocalization.supportedLocales', ['fr' => "Frenchouz"])); @@ -230,7 +231,6 @@ trait HasUwilImages $path = $isList ? "$fieldPath.$key" : (is_int($key) ? $fieldPath : "$fieldPath.$key"); // TODO cette récursivité n'a pas encore été testé. if (is_array($oldValue) || is_array($newValue)) { - dd('pas testé'); static::traverseAndManage( $model, (array) $oldValue, diff --git a/app/Traits/Requests/Api/HasLaravelFailedValidation.php b/app/Traits/Requests/Api/HasLaravelFailedValidation.php index 3f273d07..239fb689 100644 --- a/app/Traits/Requests/Api/HasLaravelFailedValidation.php +++ b/app/Traits/Requests/Api/HasLaravelFailedValidation.php @@ -14,7 +14,7 @@ trait HasLaravelFailedValidation * @return void * @throws \Illuminate\Http\Exceptions\HttpResponseException Override ajax code error. */ - protected function failedValidation(Validator $validator): \Illuminate\Http\Exceptions\HttpResponseException + protected function failedValidation(Validator $validator): void { $response = response()->json([ 'errors' => $validator->errors(), diff --git a/app/Traits/Requests/HasInertiaPicture.php b/app/Traits/Requests/HasInertiaPicture.php index f38ed71c..7371b9af 100644 --- a/app/Traits/Requests/HasInertiaPicture.php +++ b/app/Traits/Requests/HasInertiaPicture.php @@ -13,7 +13,7 @@ trait HasInertiaPicture */ protected function mergeInertiaPicture(): void { - if (empty($this->convertedFiles) || !is_array($this->convertedFiles)) { + if (empty($this->convertedFiles)) { return; } $original = $this->all(); @@ -47,7 +47,7 @@ trait HasInertiaPicture * Set picture rules (UploadedFile or string path). * * @param string $rules - * @return string + * @return array */ protected function pictureRules(string $rules): array { diff --git a/app/View/Components/Front/News/NewsNextEventComponent.php b/app/View/Components/Front/News/NewsNextEventComponent.php index ae85b805..ae930507 100644 --- a/app/View/Components/Front/News/NewsNextEventComponent.php +++ b/app/View/Components/Front/News/NewsNextEventComponent.php @@ -9,7 +9,7 @@ use Illuminate\View\Component; class NewsNextEventComponent extends Component { - /** @var array<\App\Models\News> $nextEvents List of published news. */ + /** @var \Illuminate\Support\Collection $nextEvents List of published news. */ public $nextEvents; /** @@ -17,12 +17,16 @@ class NewsNextEventComponent extends Component */ public function __construct() { + /** @var \App\Models\NewsCategory|null $newsCategory */ $newsCategory = NewsCategory::getModelsCached() ->filter(fn($category) => $category->getTranslation('slug', 'fr') === "actualites") ->first(); + /** @var \App\Models\NewsTag|null $eventTag */ $eventTag = NewsTag::getTagsByCategoryInCurrentLocale($newsCategory->slug) - ->filter(fn($tag) => $tag->getTranslation('slug', 'fr') === "evenement") + ->filter( + fn(\Illuminate\Database\Eloquent\Model $tag) => $tag->getTranslation('slug', 'fr') === "evenement" + ) ->first(); $eventTagId = $eventTag ? $eventTag->id : null; @@ -30,7 +34,7 @@ class NewsNextEventComponent extends Component $this->nextEvents = News::getPublishedNewsByCategoryInCurrentLocale($newsCategory->slug) ->filter(function ($news) use ($eventTagId) { return $news->tags->contains( - fn ($tag) => $eventTagId === $tag->id + fn($tag) => $eventTagId === $tag->id ); }) ->sortByDesc('published_at') diff --git a/app/View/Components/Front/Pages/KnowUs/OurImplantations.php b/app/View/Components/Front/Pages/KnowUs/OurImplantations.php index d2b43285..f6ee402d 100644 --- a/app/View/Components/Front/Pages/KnowUs/OurImplantations.php +++ b/app/View/Components/Front/Pages/KnowUs/OurImplantations.php @@ -11,13 +11,13 @@ class OurImplantations extends Component /** @var string $id Identification of the section. */ public string $id; - /** @var $implantations Content section. */ + /** @var array Content section. */ public $implantations; - /** @var array<\App\Models\Company> $companyModels List of published companies. */ + /** @var \Illuminate\Database\Eloquent\Collection $companyModels List of published companies. */ public $companyModels; - /** @var array<\App\Models\CompanyActivity> $companyActivityModels List of published company activities. */ + /** @var \Illuminate\Database\Eloquent\Collection $companyActivityModels List of published company activities. */ public $companyActivityModels; /** From f55972ea962b0a2c9b9f55f03ed47349e7187ad9 Mon Sep 17 00:00:00 2001 From: K Muller Date: Wed, 11 Feb 2026 09:11:01 +0100 Subject: [PATCH 2/3] fix: :globe_with_meridians: update translation of GoToFrontView in news formulary --- resources/ts/back/Pages/News/Form.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/ts/back/Pages/News/Form.tsx b/resources/ts/back/Pages/News/Form.tsx index 3de78627..acbae551 100644 --- a/resources/ts/back/Pages/News/Form.tsx +++ b/resources/ts/back/Pages/News/Form.tsx @@ -197,7 +197,9 @@ export default function Form({ choice: 1, })} pathField={data.slug} - additionalGroupPath="actualites" // TODO: ce sera translatable plus tard + additionalGroupPath={useTrans("models.classes.news", { + choice: 1, + })} isAvailable={ model?.status === enumNewsStatus.published.value } From 26697c0b58ac5df041b2c332e49573fbbf05d6fe Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Fri, 13 Feb 2026 16:24:37 +0100 Subject: [PATCH 3/3] fix: :bug: replace old Model type by DefaultModel --- resources/ts/back/Components/Inputs/EnumSelect.tsx | 2 +- resources/ts/back/Components/Table/DataTable.tsx | 4 ++-- resources/ts/back/Components/Table/DetailsTable.tsx | 6 +++--- resources/ts/back/Components/WordCounter.tsx | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/ts/back/Components/Inputs/EnumSelect.tsx b/resources/ts/back/Components/Inputs/EnumSelect.tsx index c51f98b9..5345b88c 100644 --- a/resources/ts/back/Components/Inputs/EnumSelect.tsx +++ b/resources/ts/back/Components/Inputs/EnumSelect.tsx @@ -81,7 +81,7 @@ export default function EnumSelect({ /** * Get the identification field of specific option. - * @param option Model + * @param value number * @return string */ const getEnumLabel = (value: number): string => { diff --git a/resources/ts/back/Components/Table/DataTable.tsx b/resources/ts/back/Components/Table/DataTable.tsx index 5fad4da5..6305a240 100644 --- a/resources/ts/back/Components/Table/DataTable.tsx +++ b/resources/ts/back/Components/Table/DataTable.tsx @@ -18,7 +18,7 @@ import { TableRow, } from "@/components/ui/table"; // * Other -import { Model, Resource, Views } from "@/back/types/global"; +import { DefaultModel, Resource, Views } from "@/back/types/global"; import ModelActions from "@/back/Components/ModelActions"; import DataTableFilterButton from "@/back/Components/Table/DataTableFilterButton"; import PaginationWrapper from "@/back/Components/Pagination/PaginationWrapper"; @@ -102,7 +102,7 @@ export default function DataTable({ diff --git a/resources/ts/back/Components/Table/DetailsTable.tsx b/resources/ts/back/Components/Table/DetailsTable.tsx index 6a16fc56..2dc5209d 100644 --- a/resources/ts/back/Components/Table/DetailsTable.tsx +++ b/resources/ts/back/Components/Table/DetailsTable.tsx @@ -11,16 +11,16 @@ import { } from "@/components/ui/table"; // * Other import useTrans from "@/hooks/use-translations"; -import { Model } from "@/back/types/global"; +import { DefaultModel } from "@/back/types/global"; interface DetailsTableProps { columns: { - accessorKey: keyof Model; + accessorKey: keyof DefaultModel; header: string; // eslint-disable-next-line no-unused-vars cell?: (params: { value: unknown }) => ReactNode; }[]; - model: Model; + model: DefaultModel; forceRenderValue?: boolean; } diff --git a/resources/ts/back/Components/WordCounter.tsx b/resources/ts/back/Components/WordCounter.tsx index a822a319..67596b98 100644 --- a/resources/ts/back/Components/WordCounter.tsx +++ b/resources/ts/back/Components/WordCounter.tsx @@ -1,4 +1,4 @@ -// * Packages +// * Other import useTrans from "@/hooks/use-translations"; export default function WordCounter({ value }: { value: string }) {