Skip to content

Commit 10b5e59

Browse files
authored
refactor: upgrade PHPStan to level 6 with type annotations (#189)
## Summary - Upgrade PHPStan from level 1 to level 6 - Add proper PHPDoc annotations across events module and app - Fix type safety issues identified by stricter analysis ## Changes - `phpstan.neon`: level 1 → level 6 - Events models: proper `@property`, `@return`, and `@param` annotations - Filament resources: type-safe static analysis fixes - App support files: improved type annotations ## Testing - [ ] `composer phpstan` passes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Improved null-safety when retrieving event attendance information * Fixed potential null reference issues when checking event participation status * **Refactor** * Enhanced type safety and null-checking throughout the application * Optimized queries for participant and attendance lookups * **Chores** * Increased static code analysis strictness to improve overall code quality * Improved code documentation and type annotations for better maintainability <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent acd26d4 commit 10b5e59

27 files changed

Lines changed: 175 additions & 77 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ _ide_helper_models.php
4141
tests/Browser/Screenshots
4242
/.github/git-commit-instructions.md
4343
/.laracord
44+
.claude

app-modules/events/src/Actions/AttendEventAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use He4rt\Events\Models\EventModel;
9+
use He4rt\Events\Models\Pivot\EventAttend;
910

1011
final class AttendEventAction
1112
{
@@ -14,7 +15,9 @@ final class AttendEventAction
1415
*/
1516
public function execute(EventModel $eventModel): void
1617
{
17-
$attendingStatus = $eventModel->attendees()->first()->pivot->status;
18+
/** @var EventAttend|null $pivot */
19+
$pivot = $eventModel->attendees()->first()?->pivot;
20+
$attendingStatus = $pivot->status;
1821
$eventModel->attend(auth()->user()->id, $attendingStatus);
1922
}
2023
}

app-modules/events/src/Filament/Admin/Resources/EventAgenda/EventAgendaResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public static function getGloballySearchableAttributes(): array
153153

154154
public static function getGlobalSearchResultDetails(Model $record): array
155155
{
156+
/** @var EventAgenda $record */
156157
$details = [];
157158

158159
if ($record->tenant) {

app-modules/events/src/Filament/Admin/Resources/Events/RelationManagers/AttendeesRelationManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Filament\Tables\Columns\IconColumn;
1212
use Filament\Tables\Columns\TextColumn;
1313
use Filament\Tables\Table;
14+
use He4rt\Events\Models\EventModel;
1415
use He4rt\Identity\Filament\Admin\Resources\Users\UserResource;
1516
use He4rt\Identity\User\Models\User;
1617
use Illuminate\Database\Eloquent\Model;
@@ -27,6 +28,7 @@ class AttendeesRelationManager extends RelationManager
2728

2829
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
2930
{
31+
/** @var EventModel $ownerRecord */
3032
return (string) $ownerRecord->attendees()->count();
3133
}
3234

@@ -48,7 +50,11 @@ public function table(Table $table): Table
4850
])
4951
->recordActions([
5052
DetachAction::make()
51-
->using(fn (User $record) => $this->getOwnerRecord()->leave($record->getKey())),
53+
->using(function (User $record): void {
54+
/** @var EventModel $ownerRecord */
55+
$ownerRecord = $this->getOwnerRecord();
56+
$ownerRecord->leave($record->getKey());
57+
}),
5258
]);
5359
}
5460
}

app-modules/events/src/Filament/Admin/Resources/Events/RelationManagers/TalksRelationManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Filament\Support\Icons\Heroicon;
1111
use Filament\Tables\Table;
1212
use He4rt\Events\Filament\Admin\Resources\Talks\TalkResource;
13+
use He4rt\Events\Models\EventModel;
1314
use Illuminate\Database\Eloquent\Model;
1415

1516
class TalksRelationManager extends RelationManager
@@ -20,6 +21,7 @@ class TalksRelationManager extends RelationManager
2021

2122
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
2223
{
24+
/** @var EventModel $ownerRecord */
2325
return (string) $ownerRecord->talks()->count();
2426
}
2527

app-modules/events/src/Filament/App/EventModels/Pages/ListEventModels.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function leave(string|int $eventModelId): void
4040
->send();
4141
}
4242

43+
/**
44+
* @param Builder<EventModel> $query
45+
* @return Builder<EventModel>
46+
*/
4347
protected function modifyQueryWithActiveTab(Builder $query, bool $isResolvingRecord = false): Builder
4448
{
4549
return $query->where('active', true)->with('attendees')->latest('end_at');

app-modules/events/src/Filament/Events/EventLandingPage.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66

77
use Filament\Pages\Dashboard;
88
use Filament\Support\Enums\Width;
9+
use He4rt\Identity\Tenant\Models\Tenant;
910

1011
class EventLandingPage extends Dashboard
1112
{
12-
public $tenant;
13+
public ?Tenant $tenant = null;
1314

1415
protected static bool $shouldRegisterNavigation = false;
1516

1617
protected Width|string|null $maxContentWidth = Width::Full;
1718

1819
public function mount(): void
1920
{
20-
$this->tenant = filament()->getTenant();
21+
/** @var Tenant|null $tenant */
22+
$tenant = filament()->getTenant();
23+
$this->tenant = $tenant;
2124
}
2225

2326
public function getView(): string

app-modules/events/src/Filament/Events/ParticipantDashboard.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
use He4rt\Identity\Tenant\Models\Tenant;
1212
use Illuminate\Contracts\Support\Htmlable;
1313

14-
/** @property Tenant $tenant */
1514
class ParticipantDashboard extends Page
1615
{
17-
/** @var Tenant|null */
18-
public $tenant;
16+
public ?Tenant $tenant = null;
1917

2018
/** @var EventModel|null */
2119
public $event;
@@ -34,14 +32,16 @@ public function getTitle(): string|Htmlable
3432

3533
public function mount(): void
3634
{
37-
$this->tenant = filament()->getTenant();
35+
/** @var Tenant $tenant */
36+
$tenant = filament()->getTenant();
37+
$this->tenant = $tenant;
3838

3939
$this->event = $this->tenant
4040
->events()
4141
->where('active', true)
4242
->first();
4343

44-
abort_unless($this->event, 404);
44+
abort_unless($this->event !== null, 404);
4545
}
4646

4747
public function getView(): string

app-modules/events/src/Filament/Resources/EventSubmissionSpeakerResource.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,21 @@ public static function getEloquentQuery(): Builder
110110

111111
public static function getGlobalSearchEloquentQuery(): Builder
112112
{
113-
return parent::getGlobalSearchEloquentQuery()->with(['event', 'user']);
113+
return parent::getGlobalSearchEloquentQuery()->with(['submission.event', 'user']);
114114
}
115115

116116
public static function getGloballySearchableAttributes(): array
117117
{
118-
return ['event.title', 'user.name'];
118+
return ['submission.event.title', 'user.name'];
119119
}
120120

121121
public static function getGlobalSearchResultDetails(Model $record): array
122122
{
123+
/** @var EventSubmissionSpeaker $record */
123124
$details = [];
124125

125-
if ($record->event) {
126-
$details['Event'] = $record->event->title;
126+
if ($record->submission?->event) {
127+
$details['Event'] = $record->submission->event->title;
127128
}
128129

129130
if ($record->user) {

app-modules/events/src/Filament/Shared/EventLogin.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ public function defaultMultiFactorChallengeForm(Schema $schema): Schema
174174
return [];
175175
}
176176

177-
$authProvider = Filament::auth()->getProvider();
178-
/** @phpstan-ignore-line */
177+
/** @var SessionGuard $guard */
178+
$guard = Filament::auth();
179+
$authProvider = $guard->getProvider();
179180
$user = $authProvider->retrieveById(decrypt($this->userUndertakingMultiFactorAuthentication));
180181

181182
$enabledMultiFactorAuthenticationProviders = array_filter(
@@ -341,8 +342,9 @@ protected function getRememberFormComponent(): Component
341342

342343
protected function getMultiFactorProviderFormComponent(): ?Component
343344
{
344-
$authProvider = Filament::auth()->getProvider();
345-
/** @phpstan-ignore-line */
345+
/** @var SessionGuard $guard */
346+
$guard = Filament::auth();
347+
$authProvider = $guard->getProvider();
346348
$user = $authProvider->retrieveById(decrypt($this->userUndertakingMultiFactorAuthentication));
347349

348350
$enabledMultiFactorAuthenticationProviders = array_filter(

0 commit comments

Comments
 (0)