Skip to content

Commit c049753

Browse files
committed
Stricter code
1 parent 1b098f1 commit c049753

24 files changed

+221
-91
lines changed

resources/views/admin/_form-registration.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1 class="header-title @if (!$model->present()->title) text-muted @endif">
44
{{ $model->present()->title ?: __('Untitled') }}
55
</h1>
6-
<x-core::form-buttons :$model :locales="locales()" />
6+
<x-core::form-buttons :$model />
77
</div>
88

99
<div class="content">

resources/views/admin/_form.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div class="header">
22
<x-core::back-button :url="$model->indexUrl()" :title="__('Events')" />
33
<x-core::title :$model :default="__('New event')" />
4-
<x-core::form-buttons :$model :locales="locales()" />
4+
<x-core::form-buttons :$model />
55
</div>
66

77
<div class="content">
88
<x-core::form-errors />
99

1010
<div class="row">
1111
<div class="col-lg-8">
12-
<x-core::title-and-slug-fields :locales="locales()" />
12+
<x-core::title-and-slug-fields />
1313
<div class="mb-3">
1414
{!! TranslatableBootForm::hidden('status')->value(0) !!}
1515
{!! TranslatableBootForm::checkbox(__('Published'), 'status') !!}
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Composers;
46

57
use Illuminate\Support\Facades\Gate;
@@ -14,15 +16,22 @@ public function compose(View $view): void
1416
if (Gate::denies('read events')) {
1517
return;
1618
}
17-
$view->offsetGet('sidebar')->group(__(config('typicms.modules.contacts.sidebar.group', 'Content')), function (SidebarGroup $group): void {
18-
$group->id = 'content';
19-
$group->weight = 30;
20-
$group->addItem(__(config('typicms.modules.events.sidebar.label', 'Events')), function (SidebarItem $item): void {
21-
$item->id = 'events';
22-
$item->icon = config('typicms.modules.events.sidebar.icon');
23-
$item->weight = config('typicms.modules.events.sidebar.weight');
24-
$item->route('admin::index-events');
25-
});
26-
});
19+
20+
$view->offsetGet('sidebar')->group(
21+
__(config('typicms.modules.contacts.sidebar.group', 'Content')),
22+
function (SidebarGroup $group): void {
23+
$group->id = 'content';
24+
$group->weight = 30;
25+
$group->addItem(
26+
__(config('typicms.modules.events.sidebar.label', 'Events')),
27+
function (SidebarItem $item): void {
28+
$item->id = 'events';
29+
$item->icon = config('typicms.modules.events.sidebar.icon');
30+
$item->weight = config('typicms.modules.events.sidebar.weight');
31+
$item->route('admin::index-events');
32+
},
33+
);
34+
},
35+
);
2736
}
2837
}

src/Exports/Export.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Exports;
46

57
use Illuminate\Database\Eloquent\Collection;

src/Exports/RegistrationsExport.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Exports;
46

57
use Illuminate\Database\Eloquent\Collection;
@@ -28,14 +30,18 @@ public function __construct(Request $request)
2830
->selectFields()
2931
->where('event_id', $request->route()->originalParameter('event'))
3032
->addSelect([
31-
'event_name' => Event::query()->select(column('title'))
33+
'event_name' => Event::query()
34+
->select(column('title'))
3235
->whereColumn('event_id', 'events.id')
3336
->limit(1),
3437
]);
3538
$this->collection = QueryBuilder::for($query)
3639
->allowedSorts(['created_at', 'first_name', 'last_name', 'email', 'locale', 'number_of_people', 'message'])
3740
->allowedFilters([
38-
AllowedFilter::custom('created_at,first_name,last_name,email,locale,number_of_people,message', new FilterRegistrations()),
41+
AllowedFilter::custom(
42+
'created_at,first_name,last_name,email,locale,number_of_people,message',
43+
new FilterRegistrations(),
44+
),
3945
])
4046
->get();
4147
}

src/Facades/Events.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Facades;
46

57
use Illuminate\Support\Facades\Facade;

src/Filters/FilterRegistrations.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Filters;
46

57
use Illuminate\Database\Eloquent\Builder;

src/Http/Controllers/AdminController.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Http\Controllers;
46

57
use Illuminate\Http\RedirectResponse;
@@ -12,7 +14,7 @@
1214
use TypiCMS\Modules\Events\Http\Requests\FormRequest;
1315
use TypiCMS\Modules\Events\Models\Event;
1416

15-
class AdminController extends BaseAdminController
17+
final class AdminController extends BaseAdminController
1618
{
1719
public function index(): View
1820
{
@@ -30,29 +32,25 @@ public function create(): View
3032
{
3133
$model = new Event();
3234

33-
return view('events::admin.create')
34-
->with(['model' => $model]);
35+
return view('events::admin.create', ['model' => $model]);
3536
}
3637

3738
public function edit(Event $event): View
3839
{
39-
return view('events::admin.edit')
40-
->with(['model' => $event]);
40+
return view('events::admin.edit', ['model' => $event]);
4141
}
4242

4343
public function store(FormRequest $request): RedirectResponse
4444
{
4545
$event = Event::query()->create($request->validated());
4646

47-
return $this->redirect($request, $event)
48-
->withMessage(__('Item successfully created.'));
47+
return $this->redirect($request, $event)->withMessage(__('Item successfully created.'));
4948
}
5049

5150
public function update(Event $event, FormRequest $request): RedirectResponse
5251
{
5352
$event->update($request->validated());
5453

55-
return $this->redirect($request, $event)
56-
->withMessage(__('Item successfully updated.'));
54+
return $this->redirect($request, $event)->withMessage(__('Item successfully updated.'));
5755
}
5856
}

src/Http/Controllers/ApiController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Http\Controllers;
46

57
use Illuminate\Http\JsonResponse;
@@ -12,15 +14,17 @@
1214
use TypiCMS\Modules\Core\Http\Controllers\BaseApiController;
1315
use TypiCMS\Modules\Events\Models\Event;
1416

15-
class ApiController extends BaseApiController
17+
final class ApiController extends BaseApiController
1618
{
1719
/** @return LengthAwarePaginator<int, mixed> */
1820
public function index(Request $request): LengthAwarePaginator
1921
{
2022
$query = Event::query()
2123
->selectFields()
2224
->addSelect([
23-
'registration_count' => DB::table('registrations')->selectRaw('COUNT(*)')->whereColumn('events.id', 'registrations.event_id'),
25+
'registration_count' => DB::table('registrations')
26+
->selectRaw('COUNT(*)')
27+
->whereColumn('events.id', 'registrations.event_id'),
2428
]);
2529

2630
return QueryBuilder::for($query)

src/Http/Controllers/PublicController.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TypiCMS\Modules\Events\Http\Controllers;
46

57
use Illuminate\Http\RedirectResponse;
@@ -14,9 +16,11 @@
1416
use TypiCMS\Modules\Events\Notifications\RegisteredToEvent;
1517
use TypiCMS\Modules\Events\Services\Calendar;
1618

17-
class PublicController extends BasePublicController
19+
final class PublicController extends BasePublicController
1820
{
19-
public function __construct(protected Calendar $calendar) {}
21+
public function __construct(
22+
protected Calendar $calendar,
23+
) {}
2024

2125
public function index(): View
2226
{
@@ -27,8 +31,7 @@ public function index(): View
2731
->where('end_date', '>=', date('Y-m-d'))
2832
->paginate(config('typicms.modules.events.per_page'));
2933

30-
return view('events::public.index')
31-
->with(['models' => $models]);
34+
return view('events::public.index', ['models' => $models]);
3235
}
3336

3437
public function past(): View
@@ -40,8 +43,7 @@ public function past(): View
4043
->where('end_date', '<', date('Y-m-d'))
4144
->paginate(config('typicms.modules.events.per_page'));
4245

43-
return view('events::public.past')
44-
->with(['models' => $models]);
46+
return view('events::public.past', ['models' => $models]);
4547
}
4648

4749
public function show(string $slug): View
@@ -56,8 +58,7 @@ public function show(string $slug): View
5658
->whereSlugIs($slug)
5759
->firstOrFail();
5860

59-
return view('events::public.show')
60-
->with(['model' => $model]);
61+
return view('events::public.show', ['model' => $model]);
6162
}
6263

6364
public function showRegistrationForm(string $slug): View
@@ -68,8 +69,7 @@ public function showRegistrationForm(string $slug): View
6869
->firstOrFail();
6970
abort_if(!$event->registration_form || $event->end_date < date('Y-m-d'), 404);
7071

71-
return view('events::public.registration')
72-
->with(['event' => $event]);
72+
return view('events::public.registration', ['event' => $event]);
7373
}
7474

7575
public function register(string $slug, RegistrationFormRequest $request): RedirectResponse
@@ -91,14 +91,14 @@ public function register(string $slug, RegistrationFormRequest $request): Redire
9191
$registration = Registration::query()->create($data);
9292
(new Event())->flushCache();
9393

94-
Notification::route('mail', config('typicms.webmaster_email'))
95-
->notify(new NewRegistrationToAnEvent($event, $registration));
94+
Notification::route('mail', config('typicms.webmaster_email'))->notify(new NewRegistrationToAnEvent(
95+
$event,
96+
$registration,
97+
));
9698

97-
Notification::route('mail', $data['email'])
98-
->notify(new RegisteredToEvent($event, $registration));
99+
Notification::route('mail', $data['email'])->notify(new RegisteredToEvent($event, $registration));
99100

100-
return to_route(app()->getLocale() . '::event-registered', $event->slug)
101-
->with('success', true);
101+
return to_route(app()->getLocale() . '::event-registered', $event->slug)->with('success', true);
102102
}
103103

104104
public function registered(string $slug): RedirectResponse|View
@@ -108,7 +108,7 @@ public function registered(string $slug): RedirectResponse|View
108108
->whereSlugIs($slug)
109109
->firstOrFail();
110110
if (session('success')) {
111-
return view('events::public.registered')->with(['event' => $event]);
111+
return view('events::public.registered', ['event' => $event]);
112112
}
113113

114114
return redirect(url('/'));

0 commit comments

Comments
 (0)