Add phpstan level 7(#544)

This commit is contained in:
Saeed Vaziry
2025-03-12 13:31:10 +01:00
committed by GitHub
parent c22bb1fa80
commit 493cbb0849
437 changed files with 4505 additions and 2193 deletions

View File

@ -54,7 +54,7 @@ public function infolist(Infolist $infolist): Infolist
->label('Password')
->required(),
])
->action(function (array $data) {
->action(function (array $data): void {
self::logoutOtherBrowserSessions($data['password']);
})
->modalWidth('2xl'),
@ -62,6 +62,9 @@ public function infolist(Infolist $infolist): Infolist
]);
}
/**
* @return array<int, mixed>
*/
private function getDynamicSchema(): array
{
$sections = [];
@ -71,8 +74,8 @@ private function getDynamicSchema(): array
->schema([
TextEntry::make('device')
->hiddenLabel()
->icon($session->device['desktop'] ? 'heroicon-o-computer-desktop' : 'heroicon-o-device-phone-mobile')
->state($session->device['platform'].' - '.$session->device['browser']),
->icon(isset($session->device['desktop']) ? 'heroicon-o-computer-desktop' : 'heroicon-o-device-phone-mobile')
->state(($session->device['platform'] ?? 'Platform').' - '.($session->device['browser'] ?? 'Browser')),
TextEntry::make('browser')
->hiddenLabel()
->icon('heroicon-o-map-pin')
@ -92,15 +95,32 @@ private function getDynamicSchema(): array
return $sections;
}
/**
* @return array<int, object{
* device: array{
* browser: string,
* desktop: bool,
* mobile: bool,
* tablet: bool,
* platform: string
* },
* ip_address: string|null,
* is_current_device: bool,
* last_active: string
* }>
*/
private function getSessions(): array
{
/** @var \App\Models\User $user */
$user = Auth::user();
if (config(key: 'session.driver') !== 'database') {
return [];
}
return collect(
value: DB::connection(config(key: 'session.connection'))->table(table: config(key: 'session.table', default: 'sessions'))
->where(column: 'user_id', operator: Auth::user()->getAuthIdentifier())
->where(column: 'user_id', operator: $user->getAuthIdentifier())
->latest(column: 'last_activity')
->get()
)->map(callback: function ($session): object {
@ -121,17 +141,20 @@ private function getSessions(): array
})->toArray();
}
private function createAgent(mixed $session)
private function createAgent(mixed $session): Agent
{
return tap(
value: new Agent,
callback: fn ($agent) => $agent->setUserAgent(userAgent: $session->user_agent)
callback: fn ($agent): string => $agent->setUserAgent(userAgent: $session->user_agent)
);
}
private function logoutOtherBrowserSessions($password): void
private function logoutOtherBrowserSessions(string $password): void
{
if (! Hash::check($password, Auth::user()->password)) {
/** @var \App\Models\User $user */
$user = Auth::user();
if (! Hash::check($password, $user->password)) {
Notification::make()
->danger()
->title('The password you entered was incorrect. Please try again.')
@ -143,7 +166,7 @@ private function logoutOtherBrowserSessions($password): void
Auth::guard()->logoutOtherDevices($password);
request()->session()->put([
'password_hash_'.Auth::getDefaultDriver() => Auth::user()->getAuthPassword(),
'password_hash_'.Auth::getDefaultDriver() => $user->getAuthPassword(),
]);
$this->deleteOtherSessionRecords();
@ -156,12 +179,15 @@ private function logoutOtherBrowserSessions($password): void
private function deleteOtherSessionRecords(): void
{
/** @var \App\Models\User $user */
$user = Auth::user();
if (config(key: 'session.driver') !== 'database') {
return;
}
DB::connection(config(key: 'session.connection'))->table(table: config(key: 'session.table', default: 'sessions'))
->where('user_id', Auth::user()->getAuthIdentifier())
->where('user_id', $user->getAuthIdentifier())
->where('id', '!=', request()->session()->getId())
->delete();
}