Skip to content
Open

F/P #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/assets_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: production-assets | ci

env:
PHP_VERSION: 8.4
PHP_VERSION: 8.5
NODE_VERSION: 24

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/larastan_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: pull-request | ci larastan

env:
PHP_VERSION: 8.4
PHP_VERSION: 8.5
NODE_VERSION: 24

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pest_coverage_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: pull-request | ci pest coverage

env:
PHP_VERSION: 8.4
PHP_VERSION: 8.5
NODE_VERSION: 24
PEST_MIN_COVERAGE: 1
PEST_MIN_TYPE_COVERAGE: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pest_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: pull-request | ci pest

env:
PHP_VERSION: 8.4
PHP_VERSION: 8.5
NODE_VERSION: 24

steps:
Expand Down
91 changes: 71 additions & 20 deletions app/Actions/PageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
use App\Models\News;
use App\Models\Page;
use App\Models\Product;
use App\Models\Reference;
use App\Models\Service;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

class PageAction
{
/**
* @param Collection<int, PageDTO>|null $referencePages
*/
public function __construct(
private ?string $locale = null,
private ?string $routeName = null,
Expand All @@ -37,7 +40,7 @@ public function default(): ?PageDTO
title: $page->title,
description: $page->description,
image: $page->image,
lastModificationDate: $page->updated_at ?? now(),
lastModificationDate: Carbon::parse($page->updated_at ?? now()),
routeParameters: $this->routeParameters,
referencePages: $this->referencePages
);
Expand All @@ -52,13 +55,9 @@ public function news(News $news, bool $withReferences = false, ?string $locale =
title: $news->title,
description: $news->teaser,
image: $news->image,
lastModificationDate: $news->updated_at ?? now(),
lastModificationDate: Carbon::parse($news->updated_at ?? now()),
routeParameters: ['locale' => $news->locale, 'news' => $news],
referencePages: $withReferences ? $news->references->map(function (Reference $reference) {
$reference->load(['target']);

return self::news(news: $reference->target, withReferences: false, locale: $reference->reference_locale);
}) : null,
referencePages: $withReferences ? $this->newsReferencePages($news) : null,
);
}

Expand All @@ -71,13 +70,9 @@ public function product(Product $product, bool $withReferences = false, ?string
title: $product->name,
description: $product->teaser,
image: $product->image,
lastModificationDate: $product->updated_at ?? now(),
lastModificationDate: Carbon::parse($product->updated_at ?? now()),
routeParameters: ['locale' => $product->locale, 'product' => $product],
referencePages: $withReferences ? $product->references->map(function (Reference $reference) {
$reference->load(['target']);

return self::product(product: $reference->target, withReferences: false, locale: $reference->reference_locale);
}) : null,
referencePages: $withReferences ? $this->productReferencePages($product) : null,
);
}

Expand All @@ -90,16 +85,72 @@ public function service(Service $service, bool $withReferences = false, ?string
title: $service->name,
description: $service->teaser,
image: $service->image,
lastModificationDate: $service->updated_at ?? now(),
lastModificationDate: Carbon::parse($service->updated_at ?? now()),
routeParameters: ['locale' => $service->locale, 'service' => $service],
referencePages: $withReferences ? $service->references->map(function (Reference $reference) {
$reference->load(['target']);

return self::service(service: $reference->target, withReferences: false, locale: $reference->reference_locale);
}) : null,
referencePages: $withReferences ? $this->serviceReferencePages($service) : null,
);
}

/**
* @return Collection<int, PageDTO>
*/
private function newsReferencePages(News $news): Collection
{
$pages = [];

foreach ($news->references as $reference) {
$reference->load(['target']);

if (! $reference->target instanceof News) {
continue;
}

$pages[] = $this->news(news: $reference->target, withReferences: false, locale: $reference->reference_locale);
}

return collect($pages);
}

/**
* @return Collection<int, PageDTO>
*/
private function productReferencePages(Product $product): Collection
{
$pages = [];

foreach ($product->references as $reference) {
$reference->load(['target']);

if (! $reference->target instanceof Product) {
continue;
}

$pages[] = $this->product(product: $reference->target, withReferences: false, locale: $reference->reference_locale);
}

return collect($pages);
}

/**
* @return Collection<int, PageDTO>
*/
private function serviceReferencePages(Service $service): Collection
{
$pages = [];

foreach ($service->references as $reference) {
$reference->load(['target']);

if (! $reference->target instanceof Service) {
continue;
}

$pages[] = $this->service(service: $reference->target, withReferences: false, locale: $reference->reference_locale);
}

return collect($pages);
}

private function findPage(): ?Page
{
return Page::where('locale', $this->locale)
Expand Down
15 changes: 15 additions & 0 deletions app/Actions/ViewDataAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function configuration(string $locale): ?Configuration
});
}

/**
* @return Collection<int, Product>
*/
public function products(string $locale): Collection
{
$key = Str::slug("products_published_{$locale}");
Expand All @@ -35,6 +38,9 @@ public function products(string $locale): Collection
});
}

/**
* @return Collection<int, Service>
*/
public function services(string $locale): Collection
{
$key = Str::slug("services_published_{$locale}");
Expand All @@ -44,6 +50,9 @@ public function services(string $locale): Collection
});
}

/**
* @return Collection<int, News>
*/
public function news(string $locale): Collection
{
$key = Str::slug("news_published_{$locale}");
Expand All @@ -53,6 +62,9 @@ public function news(string $locale): Collection
});
}

/**
* @return Collection<int, Technology>
*/
public function technologies(string $locale): Collection
{
$key = Str::slug("technologies_published_{$locale}");
Expand All @@ -62,6 +74,9 @@ public function technologies(string $locale): Collection
});
}

/**
* @return Collection<int, OpenSource>
*/
public function openSource(string $locale): Collection
{
$key = Str::slug("open_source_published_{$locale}");
Expand Down
7 changes: 5 additions & 2 deletions app/DTO/ContactDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class ContactDTO
{
/**
* @param array<array-key, mixed> $icons
*/
public function __construct(
public readonly string $locale,
public readonly string $section,
Expand All @@ -18,11 +21,11 @@ public function __construct(

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

return new self(
name: $contact->name,
role: $role,
role: is_string($role) ? $role : null,
locale: $locale,
image: $contact->image,
icons: $contact->icons ?? [],
Expand Down
3 changes: 3 additions & 0 deletions app/DTO/PageDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class PageDTO
{
/**
* @param Collection<int, self>|null $referencePages
*/
public function __construct(
public string $locale,
public string $routeKey,
Expand Down
4 changes: 3 additions & 1 deletion app/Helpers/HelperDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class HelperDevice
{
public function isMobileDevice(): bool
{
return Arr::has($_SERVER, 'HTTP_USER_AGENT') && Str::contains($_SERVER['HTTP_USER_AGENT'], ['mobile', 'Mobile']);
$userAgent = Arr::get($_SERVER, 'HTTP_USER_AGENT');

return is_string($userAgent) && Str::contains($userAgent, ['mobile', 'Mobile']);
}
}
14 changes: 9 additions & 5 deletions app/Http/Controllers/Locale/LocaleUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use App\Actions\LocaleAction;
use App\Enums\LocaleEnum;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
Expand All @@ -18,20 +18,24 @@ class LocaleUpdateController extends Controller
/**
* Display the user's profile form.
*/
public function __invoke(Request $request)
public function __invoke(Request $request): RedirectResponse
{
$validated = $request->validate([
'language' => ['required', new Enum(LocaleEnum::class)],
]);

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

$locale = (new LocaleAction($locale))->setLocale();
$language = $validated['language'];

$locale = (new LocaleAction($language))->setLocale();

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

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

$localeSlug = Str::slug($locale);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/News/NewsShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(string $locale, News $news): View
'title' => $news->title,
'teaser' => $news->teaser,
'tags' => collect($news->tags),
'content' => Str::of($news->content)->markdown(),
'content' => Str::of($news->content ?? '')->markdown(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(string $locale, Product $product): View
'page' => (new PageAction(locale: $locale))->product(product: $product),
'name' => $product->name,
'teaser' => $product->teaser,
'content' => Str::of($product->content)->markdown(),
'content' => Str::of($product->content ?? '')->markdown(),
'tags' => $product->tags,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Products/ProductsShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(string $locale, Product $product): View
'page' => (new PageAction(locale: $locale))->product(product: $product),
'name' => $product->name,
'teaser' => $product->teaser,
'content' => Str::of($product->content)->markdown(),
'content' => Str::of($product->content ?? '')->markdown(),
'tags' => $product->tags,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Robots/RobotsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RobotsController extends Controller
{
public function __invoke(): Response
{
$sitemapUrl = rtrim(config('app.url'), '/').'/sitemap.xml';
$sitemapUrl = rtrim(config()->string('app.url'), '/').'/sitemap.xml';

$content = implode("\n", [
'User-agent: *',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Services/ServicesShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(string $locale, Service $service): View
'page' => (new PageAction(locale: $locale, routeName: null))->service(service: $service),
'name' => $service->name,
'teaser' => $service->teaser,
'content' => Str::of($service->content)->markdown(),
'content' => Str::of($service->content ?? '')->markdown(),
'tags' => $service->tags,
]);
}
Expand Down
Loading
Loading