Skip to content

Commit fe3e718

Browse files
author
Sebastian BURGIN-FIX (ext)
committed
wip
1 parent 0d63108 commit fe3e718

33 files changed

Lines changed: 247 additions & 72 deletions

app/Actions/PageAction.php

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
use App\Models\News;
77
use App\Models\Page;
88
use App\Models\Product;
9-
use App\Models\Reference;
109
use App\Models\Service;
10+
use Illuminate\Support\Carbon;
1111
use Illuminate\Support\Collection;
1212
use Illuminate\Support\Str;
1313

1414
class PageAction
1515
{
16+
/**
17+
* @param Collection<int, PageDTO>|null $referencePages
18+
*/
1619
public function __construct(
1720
private ?string $locale = null,
1821
private ?string $routeName = null,
@@ -37,7 +40,7 @@ public function default(): ?PageDTO
3740
title: $page->title,
3841
description: $page->description,
3942
image: $page->image,
40-
lastModificationDate: $page->updated_at ?? now(),
43+
lastModificationDate: Carbon::parse($page->updated_at ?? now()),
4144
routeParameters: $this->routeParameters,
4245
referencePages: $this->referencePages
4346
);
@@ -52,13 +55,9 @@ public function news(News $news, bool $withReferences = false, ?string $locale =
5255
title: $news->title,
5356
description: $news->teaser,
5457
image: $news->image,
55-
lastModificationDate: $news->updated_at ?? now(),
58+
lastModificationDate: Carbon::parse($news->updated_at ?? now()),
5659
routeParameters: ['locale' => $news->locale, 'news' => $news],
57-
referencePages: $withReferences ? $news->references->map(function (Reference $reference) {
58-
$reference->load(['target']);
59-
60-
return self::news(news: $reference->target, withReferences: false, locale: $reference->reference_locale);
61-
}) : null,
60+
referencePages: $withReferences ? $this->newsReferencePages($news) : null,
6261
);
6362
}
6463

@@ -71,13 +70,9 @@ public function product(Product $product, bool $withReferences = false, ?string
7170
title: $product->name,
7271
description: $product->teaser,
7372
image: $product->image,
74-
lastModificationDate: $product->updated_at ?? now(),
73+
lastModificationDate: Carbon::parse($product->updated_at ?? now()),
7574
routeParameters: ['locale' => $product->locale, 'product' => $product],
76-
referencePages: $withReferences ? $product->references->map(function (Reference $reference) {
77-
$reference->load(['target']);
78-
79-
return self::product(product: $reference->target, withReferences: false, locale: $reference->reference_locale);
80-
}) : null,
75+
referencePages: $withReferences ? $this->productReferencePages($product) : null,
8176
);
8277
}
8378

@@ -90,16 +85,72 @@ public function service(Service $service, bool $withReferences = false, ?string
9085
title: $service->name,
9186
description: $service->teaser,
9287
image: $service->image,
93-
lastModificationDate: $service->updated_at ?? now(),
88+
lastModificationDate: Carbon::parse($service->updated_at ?? now()),
9489
routeParameters: ['locale' => $service->locale, 'service' => $service],
95-
referencePages: $withReferences ? $service->references->map(function (Reference $reference) {
96-
$reference->load(['target']);
97-
98-
return self::service(service: $reference->target, withReferences: false, locale: $reference->reference_locale);
99-
}) : null,
90+
referencePages: $withReferences ? $this->serviceReferencePages($service) : null,
10091
);
10192
}
10293

94+
/**
95+
* @return Collection<int, PageDTO>
96+
*/
97+
private function newsReferencePages(News $news): Collection
98+
{
99+
$pages = [];
100+
101+
foreach ($news->references as $reference) {
102+
$reference->load(['target']);
103+
104+
if (! $reference->target instanceof News) {
105+
continue;
106+
}
107+
108+
$pages[] = $this->news(news: $reference->target, withReferences: false, locale: $reference->reference_locale);
109+
}
110+
111+
return collect($pages);
112+
}
113+
114+
/**
115+
* @return Collection<int, PageDTO>
116+
*/
117+
private function productReferencePages(Product $product): Collection
118+
{
119+
$pages = [];
120+
121+
foreach ($product->references as $reference) {
122+
$reference->load(['target']);
123+
124+
if (! $reference->target instanceof Product) {
125+
continue;
126+
}
127+
128+
$pages[] = $this->product(product: $reference->target, withReferences: false, locale: $reference->reference_locale);
129+
}
130+
131+
return collect($pages);
132+
}
133+
134+
/**
135+
* @return Collection<int, PageDTO>
136+
*/
137+
private function serviceReferencePages(Service $service): Collection
138+
{
139+
$pages = [];
140+
141+
foreach ($service->references as $reference) {
142+
$reference->load(['target']);
143+
144+
if (! $reference->target instanceof Service) {
145+
continue;
146+
}
147+
148+
$pages[] = $this->service(service: $reference->target, withReferences: false, locale: $reference->reference_locale);
149+
}
150+
151+
return collect($pages);
152+
}
153+
103154
private function findPage(): ?Page
104155
{
105156
return Page::where('locale', $this->locale)

app/Actions/ViewDataAction.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public function configuration(string $locale): ?Configuration
2626
});
2727
}
2828

29+
/**
30+
* @return Collection<int, Product>
31+
*/
2932
public function products(string $locale): Collection
3033
{
3134
$key = Str::slug("products_published_{$locale}");
@@ -35,6 +38,9 @@ public function products(string $locale): Collection
3538
});
3639
}
3740

41+
/**
42+
* @return Collection<int, Service>
43+
*/
3844
public function services(string $locale): Collection
3945
{
4046
$key = Str::slug("services_published_{$locale}");
@@ -44,6 +50,9 @@ public function services(string $locale): Collection
4450
});
4551
}
4652

53+
/**
54+
* @return Collection<int, News>
55+
*/
4756
public function news(string $locale): Collection
4857
{
4958
$key = Str::slug("news_published_{$locale}");
@@ -53,6 +62,9 @@ public function news(string $locale): Collection
5362
});
5463
}
5564

65+
/**
66+
* @return Collection<int, Technology>
67+
*/
5668
public function technologies(string $locale): Collection
5769
{
5870
$key = Str::slug("technologies_published_{$locale}");
@@ -62,6 +74,9 @@ public function technologies(string $locale): Collection
6274
});
6375
}
6476

77+
/**
78+
* @return Collection<int, OpenSource>
79+
*/
6580
public function openSource(string $locale): Collection
6681
{
6782
$key = Str::slug("open_source_published_{$locale}");

app/DTO/ContactDTO.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class ContactDTO
99
{
10+
/**
11+
* @param array<array-key, mixed> $icons
12+
*/
1013
public function __construct(
1114
public readonly string $locale,
1215
public readonly string $section,
@@ -18,11 +21,11 @@ public function __construct(
1821

1922
public static function fromModel(Contact $contact, string $section, string $locale): self
2023
{
21-
$role = Arr::get($contact->sections, "$section.role.$locale");
24+
$role = Arr::get($contact->sections ?? [], "$section.role.$locale");
2225

2326
return new self(
2427
name: $contact->name,
25-
role: $role,
28+
role: is_string($role) ? $role : null,
2629
locale: $locale,
2730
image: $contact->image,
2831
icons: $contact->icons ?? [],

app/DTO/PageDTO.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class PageDTO
99
{
10+
/**
11+
* @param Collection<int, self>|null $referencePages
12+
*/
1013
public function __construct(
1114
public string $locale,
1215
public string $routeKey,

app/Helpers/HelperDevice.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class HelperDevice
99
{
1010
public function isMobileDevice(): bool
1111
{
12-
return Arr::has($_SERVER, 'HTTP_USER_AGENT') && Str::contains($_SERVER['HTTP_USER_AGENT'], ['mobile', 'Mobile']);
12+
$userAgent = Arr::get($_SERVER, 'HTTP_USER_AGENT');
13+
14+
return is_string($userAgent) && Str::contains($userAgent, ['mobile', 'Mobile']);
1315
}
1416
}

app/Http/Controllers/Locale/LocaleUpdateController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use App\Actions\LocaleAction;
66
use App\Enums\LocaleEnum;
77
use App\Http\Controllers\Controller;
8+
use Illuminate\Http\RedirectResponse;
89
use Illuminate\Http\Request;
9-
use Illuminate\Support\Arr;
1010
use Illuminate\Support\Facades\Artisan;
1111
use Illuminate\Support\Facades\Route;
1212
use Illuminate\Support\Str;
@@ -18,20 +18,24 @@ class LocaleUpdateController extends Controller
1818
/**
1919
* Display the user's profile form.
2020
*/
21-
public function __invoke(Request $request)
21+
public function __invoke(Request $request): RedirectResponse
2222
{
2323
$validated = $request->validate([
2424
'language' => ['required', new Enum(LocaleEnum::class)],
2525
]);
2626

27-
$locale = Arr::get($validated, 'language');
27+
if (! is_array($validated) || ! is_string($validated['language'] ?? null)) {
28+
abort(422);
29+
}
2830

29-
$locale = (new LocaleAction($locale))->setLocale();
31+
$language = $validated['language'];
32+
33+
$locale = (new LocaleAction($language))->setLocale();
3034

3135
$previousUrl = url()->previous();
3236

3337
$route = Route::getRoutes()->match(request()->create($previousUrl));
34-
$routeName = Str::after($route->getName(), '.');
38+
$routeName = Str::after((string) $route->getName(), '.');
3539
$routeParameters = $route->parameters();
3640

3741
$localeSlug = Str::slug($locale);

app/Http/Controllers/News/NewsShowController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __invoke(string $locale, News $news): View
2323
'title' => $news->title,
2424
'teaser' => $news->teaser,
2525
'tags' => collect($news->tags),
26-
'content' => Str::of($news->content)->markdown(),
26+
'content' => Str::of($news->content ?? '')->markdown(),
2727
]);
2828
}
2929
}

app/Http/Controllers/OpenSource/OpenSoruceShowController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __invoke(string $locale, Product $product): View
1919
'page' => (new PageAction(locale: $locale))->product(product: $product),
2020
'name' => $product->name,
2121
'teaser' => $product->teaser,
22-
'content' => Str::of($product->content)->markdown(),
22+
'content' => Str::of($product->content ?? '')->markdown(),
2323
'tags' => $product->tags,
2424
]);
2525
}

app/Http/Controllers/Products/ProductsShowController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __invoke(string $locale, Product $product): View
1919
'page' => (new PageAction(locale: $locale))->product(product: $product),
2020
'name' => $product->name,
2121
'teaser' => $product->teaser,
22-
'content' => Str::of($product->content)->markdown(),
22+
'content' => Str::of($product->content ?? '')->markdown(),
2323
'tags' => $product->tags,
2424
]);
2525
}

app/Http/Controllers/Robots/RobotsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RobotsController extends Controller
99
{
1010
public function __invoke(): Response
1111
{
12-
$sitemapUrl = rtrim(config('app.url'), '/').'/sitemap.xml';
12+
$sitemapUrl = rtrim(config()->string('app.url'), '/').'/sitemap.xml';
1313

1414
$content = implode("\n", [
1515
'User-agent: *',

0 commit comments

Comments
 (0)