mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -20,13 +20,22 @@ class BackupFilesList extends Widget
|
||||
{
|
||||
public Backup $backup;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<BackupFile>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return BackupFile::query()->where('backup_id', $this->backup->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
@ -38,7 +47,7 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('restored_to')
|
||||
->searchable(),
|
||||
TextColumn::make('restored_at')
|
||||
->formatStateUsing(fn (BackupFile $record) => $record->getDateTimeByTimezone($record->restored_at))
|
||||
->formatStateUsing(fn (BackupFile $record): string => $record->getDateTimeByTimezone($record->restored_at))
|
||||
->sortable(),
|
||||
TextColumn::make('status')
|
||||
->badge()
|
||||
@ -48,6 +57,10 @@ protected function getTableColumns(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<BackupFile> $query
|
||||
* @return Builder<BackupFile>
|
||||
*/
|
||||
protected function applyDefaultSortingToTableQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->latest('created_at');
|
||||
@ -55,6 +68,9 @@ protected function applyDefaultSortingToTableQuery(Builder $query): Builder
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -63,19 +79,17 @@ public function table(Table $table): Table
|
||||
Action::make('download')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->visible(fn (BackupFile $record) => $record->isAvailable() && $record->isLocal())
|
||||
->visible(fn (BackupFile $record): bool => $record->isAvailable() && $record->isLocal())
|
||||
->tooltip('Download')
|
||||
->action(function (BackupFile $record) {
|
||||
return app(ManageBackupFile::class)->download($record);
|
||||
})
|
||||
->authorize(fn (BackupFile $record) => auth()->user()->can('view', $record)),
|
||||
->action(fn (BackupFile $record) => app(ManageBackupFile::class)->download($record))
|
||||
->authorize(fn (BackupFile $record) => $user->can('view', $record)),
|
||||
Action::make('restore')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->modalHeading('Restore Backup')
|
||||
->tooltip('Restore Backup')
|
||||
->disabled(fn (BackupFile $record) => ! $record->isAvailable())
|
||||
->authorize(fn (BackupFile $record) => auth()->user()->can('update', $record->backup))
|
||||
->disabled(fn (BackupFile $record): bool => ! $record->isAvailable())
|
||||
->authorize(fn (BackupFile $record) => $user->can('update', $record->backup))
|
||||
->form([
|
||||
Select::make('database')
|
||||
->label('Restore to')
|
||||
@ -84,8 +98,8 @@ public function table(Table $table): Table
|
||||
->native(false),
|
||||
])
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->action(function (BackupFile $record, array $data) {
|
||||
run_action($this, function () use ($record, $data) {
|
||||
->action(function (BackupFile $record, array $data): void {
|
||||
run_action($this, function () use ($record, $data): void {
|
||||
$this->validate();
|
||||
|
||||
/** @var Database $database */
|
||||
@ -108,11 +122,11 @@ public function table(Table $table): Table
|
||||
->icon('heroicon-o-trash')
|
||||
->modalHeading('Delete Backup File')
|
||||
->color('danger')
|
||||
->disabled(fn (BackupFile $record) => ! $record->isAvailable())
|
||||
->disabled(fn (BackupFile $record): bool => ! $record->isAvailable())
|
||||
->tooltip('Delete')
|
||||
->authorize(fn (BackupFile $record) => auth()->user()->can('delete', $record))
|
||||
->authorize(fn (BackupFile $record) => $user->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (BackupFile $record) {
|
||||
->action(function (BackupFile $record): void {
|
||||
app(ManageBackupFile::class)->delete($record);
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
|
@ -21,8 +21,14 @@ class BackupsList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Backup>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Backup::query()->where('server_id', $this->server->id);
|
||||
@ -56,6 +62,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())
|
||||
@ -65,8 +74,8 @@ public function table(Table $table): Table
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-pencil')
|
||||
->tooltip('Edit Configuration')
|
||||
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
|
||||
->authorize(fn (Backup $record) => auth()->user()->can('update', $record))
|
||||
->disabled(fn (Backup $record): bool => ! in_array($record->status, ['running', 'failed']))
|
||||
->authorize(fn (Backup $record) => $user->can('update', $record))
|
||||
->modelLabel('Edit Backup')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->modalSubmitActionLabel('Update')
|
||||
@ -80,7 +89,7 @@ public function table(Table $table): Table
|
||||
TextInput::make('custom_interval')
|
||||
->label('Custom Interval (Cron)')
|
||||
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['custom_interval'])
|
||||
->visible(fn (callable $get) => $get('interval') === 'custom')
|
||||
->visible(fn (callable $get): bool => $get('interval') === 'custom')
|
||||
->default(fn (Backup $record) => $record->isCustomInterval() ? $record->interval : '')
|
||||
->placeholder('0 * * * *'),
|
||||
TextInput::make('keep')
|
||||
@ -89,8 +98,8 @@ public function table(Table $table): Table
|
||||
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['keep'])
|
||||
->helperText('How many backups to keep before deleting the oldest one'),
|
||||
])
|
||||
->action(function (Backup $backup, array $data) {
|
||||
run_action($this, function () use ($data, $backup) {
|
||||
->action(function (Backup $backup, array $data): void {
|
||||
run_action($this, function () use ($data, $backup): void {
|
||||
app(ManageBackup::class)->update($backup, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
@ -107,8 +116,8 @@ public function table(Table $table): Table
|
||||
->modalHeading('Backup Files')
|
||||
->color('gray')
|
||||
->tooltip('Show backup files')
|
||||
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
|
||||
->authorize(fn (Backup $record) => auth()->user()->can('viewAny', [BackupFile::class, $record]))
|
||||
->disabled(fn (Backup $record): bool => ! in_array($record->status, ['running', 'failed']))
|
||||
->authorize(fn (Backup $record) => $user->can('viewAny', [BackupFile::class, $record]))
|
||||
->modalContent(fn (Backup $record) => view('components.dynamic-widget', [
|
||||
'widget' => BackupFilesList::class,
|
||||
'params' => [
|
||||
@ -124,7 +133,7 @@ public function table(Table $table): Table
|
||||
->label('Run Backup')
|
||||
->icon('heroicon-o-play')
|
||||
->color('primary')
|
||||
->action(function (Backup $record) {
|
||||
->action(function (Backup $record): void {
|
||||
app(RunBackup::class)->run($record);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
@ -134,12 +143,12 @@ public function table(Table $table): Table
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-trash')
|
||||
->modalHeading('Delete Backup & Files')
|
||||
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
|
||||
->disabled(fn (Backup $record): bool => ! in_array($record->status, ['running', 'failed']))
|
||||
->color('danger')
|
||||
->tooltip('Delete')
|
||||
->authorize(fn (Backup $record) => auth()->user()->can('delete', $record))
|
||||
->authorize(fn (Backup $record) => $user->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (Backup $record) {
|
||||
->action(function (Backup $record): void {
|
||||
app(ManageBackup::class)->delete($record);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
@ -20,8 +20,14 @@ class DatabaseUsersList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<DatabaseUser>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return DatabaseUser::query()->where('server_id', $this->server->id);
|
||||
@ -59,6 +65,9 @@ public function table(Table $table): Table
|
||||
|
||||
private function passwordAction(): Action
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return Action::make('password')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-key')
|
||||
@ -66,14 +75,14 @@ private function passwordAction(): Action
|
||||
->modalHeading('Database user\'s password')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->tooltip('Show the password')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
->authorize(fn ($record) => $user->can('view', $record))
|
||||
->form([
|
||||
TextInput::make('password')
|
||||
->label('Password')
|
||||
->default(fn (DatabaseUser $record) => $record->password)
|
||||
->disabled(),
|
||||
])
|
||||
->action(function (DatabaseUser $record, array $data) {
|
||||
->action(function (DatabaseUser $record, array $data): void {
|
||||
//
|
||||
})
|
||||
->modalSubmitAction(false)
|
||||
@ -82,6 +91,9 @@ private function passwordAction(): Action
|
||||
|
||||
private function linkAction(): Action
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return Action::make('link')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-link')
|
||||
@ -89,16 +101,16 @@ private function linkAction(): Action
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->tooltip('Link user')
|
||||
->modalSubmitActionLabel('Save')
|
||||
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||
->authorize(fn ($record) => $user->can('update', $record))
|
||||
->form([
|
||||
CheckboxList::make('databases')
|
||||
->label('Databases')
|
||||
->options($this->server->databases()->pluck('name', 'name')->toArray())
|
||||
->rules(fn (callable $get) => LinkUser::rules($this->server, $get()))
|
||||
->rules(fn (callable $get): array => LinkUser::rules($this->server, $get()))
|
||||
->default(fn (DatabaseUser $record) => $record->databases),
|
||||
])
|
||||
->action(function (DatabaseUser $record, array $data) {
|
||||
run_action($this, function () use ($record, $data) {
|
||||
->action(function (DatabaseUser $record, array $data): void {
|
||||
run_action($this, function () use ($record, $data): void {
|
||||
app(LinkUser::class)->link($record, $data);
|
||||
|
||||
Notification::make()
|
||||
@ -111,16 +123,19 @@ private function linkAction(): Action
|
||||
|
||||
private function deleteAction(): Action
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return Action::make('delete')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-trash')
|
||||
->modalHeading('Delete Database User')
|
||||
->color('danger')
|
||||
->tooltip('Delete')
|
||||
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||
->authorize(fn ($record) => $user->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (DatabaseUser $record) {
|
||||
run_action($this, function () use ($record) {
|
||||
->action(function (DatabaseUser $record): void {
|
||||
run_action($this, function () use ($record): void {
|
||||
app(DeleteDatabaseUser::class)->delete($this->server, $record);
|
||||
$this->dispatch('$refresh');
|
||||
});
|
||||
|
@ -15,8 +15,14 @@ class DatabasesList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Database>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Database::query()->where('server_id', $this->server->id);
|
||||
@ -47,6 +53,9 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -58,10 +67,10 @@ public function table(Table $table): Table
|
||||
->modalHeading('Delete Database')
|
||||
->color('danger')
|
||||
->tooltip('Delete')
|
||||
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||
->authorize(fn ($record) => $user->can('delete', $record))
|
||||
->requiresConfirmation()
|
||||
->action(function (Database $record) {
|
||||
run_action($this, function () use ($record) {
|
||||
->action(function (Database $record): void {
|
||||
run_action($this, function () use ($record): void {
|
||||
app(DeleteDatabase::class)->delete($this->server, $record);
|
||||
$this->dispatch('$refresh');
|
||||
});
|
||||
|
Reference in New Issue
Block a user