mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 23:12:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -24,11 +24,17 @@ class Index extends Page
|
||||
|
||||
public string $token = '';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('viewAny', PersonalAccessToken::class) ?? false;
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('viewAny', PersonalAccessToken::class);
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
@ -47,6 +53,9 @@ public function unmountAction(bool $shouldCancelParentActions = true, bool $shou
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return [
|
||||
Action::make('read-the-docs')
|
||||
->label('Read the Docs')
|
||||
@ -59,8 +68,8 @@ protected function getHeaderActions(): array
|
||||
->icon('heroicon-o-plus')
|
||||
->modalHeading('Create a new Key')
|
||||
->modalSubmitActionLabel('Create')
|
||||
->form(function () {
|
||||
if ($this->token) {
|
||||
->form(function (): array {
|
||||
if ($this->token !== '' && $this->token !== '0') {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -76,8 +85,8 @@ protected function getHeaderActions(): array
|
||||
->required(),
|
||||
];
|
||||
})
|
||||
->infolist(function () {
|
||||
if ($this->token) {
|
||||
->infolist(function (): array {
|
||||
if ($this->token !== '' && $this->token !== '0') {
|
||||
return [
|
||||
TextEntry::make('token')
|
||||
->state($this->token)
|
||||
@ -91,12 +100,12 @@ protected function getHeaderActions(): array
|
||||
})
|
||||
->authorize('create', PersonalAccessToken::class)
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->action(function (array $data) {
|
||||
->action(function (array $data) use ($user): void {
|
||||
$permissions = ['read'];
|
||||
if ($data['permission'] === 'write') {
|
||||
$permissions[] = 'write';
|
||||
}
|
||||
$token = auth()->user()->createToken($data['name'], $permissions);
|
||||
$token = $user->createToken($data['name'], $permissions);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
||||
@ -105,11 +114,11 @@ protected function getHeaderActions(): array
|
||||
$this->halt();
|
||||
})
|
||||
->modalSubmitAction(function () {
|
||||
if ($this->token) {
|
||||
if ($this->token !== '' && $this->token !== '0') {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
->closeModalByClickingAway(fn () => ! $this->token),
|
||||
->closeModalByClickingAway(fn (): bool => $this->token === '' || $this->token === '0'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,23 @@
|
||||
|
||||
class ApiKeysList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<PersonalAccessToken>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return auth()->user()->tokens()->getQuery();
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var Builder<PersonalAccessToken> $query */
|
||||
$query = $user->tokens()->getQuery();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
@ -35,7 +47,7 @@ protected function getTableColumns(): array
|
||||
->sortable(),
|
||||
TextColumn::make('last_used_at')
|
||||
->label('Last Used At')
|
||||
->formatStateUsing(fn (PersonalAccessToken $record) => $record->getDateTimeByTimezone($record->last_used_at))
|
||||
->formatStateUsing(fn (PersonalAccessToken $record): string => $record->getDateTimeByTimezone($record->last_used_at))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
];
|
||||
@ -43,6 +55,9 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -50,15 +65,15 @@ public function table(Table $table): Table
|
||||
->actions([
|
||||
DeleteAction::make('delete')
|
||||
->modalHeading('Delete Token')
|
||||
->authorize(fn (PersonalAccessToken $record) => auth()->user()->can('delete', $record))
|
||||
->using(function (array $data, PersonalAccessToken $record) {
|
||||
->authorize(fn (PersonalAccessToken $record) => $user->can('delete', $record))
|
||||
->using(function (array $data, PersonalAccessToken $record): void {
|
||||
$record->delete();
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
DeleteBulkAction::make()
|
||||
->requiresConfirmation()
|
||||
->authorize(auth()->user()->can('deleteMany', PersonalAccessToken::class)),
|
||||
->authorize($user->can('deleteMany', PersonalAccessToken::class)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user