mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 06:26:16 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Actions\Script\EditScript;
|
||||
use App\Models\Script;
|
||||
use App\Models\User;
|
||||
use App\Web\Fields\CodeEditorField;
|
||||
use App\Web\Pages\Scripts\Executions;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
@ -18,11 +19,20 @@
|
||||
|
||||
class ScriptsList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Script>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Script::getByProjectId(auth()->user()->current_project_id, auth()->user()->id);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return Script::getByProjectId($user->current_project_id, $user->id);
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
@ -34,10 +44,8 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('id')
|
||||
->label('Global')
|
||||
->badge()
|
||||
->color(fn ($record) => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(function (Script $record) {
|
||||
return $record->project_id ? 'No' : 'Yes';
|
||||
}),
|
||||
->color(fn ($record): string => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(fn (Script $record): string => $record->project_id ? 'No' : 'Yes'),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn (Script $record) => $record->created_at_by_timezone)
|
||||
@ -48,22 +56,23 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
->columns($this->getTableColumns())
|
||||
->recordUrl(fn (Script $record) => Executions::getUrl(['script' => $record]))
|
||||
->recordUrl(fn (Script $record): string => Executions::getUrl(['script' => $record]))
|
||||
->actions([
|
||||
EditAction::make('edit')
|
||||
->label('Edit')
|
||||
->modalHeading('Edit Script')
|
||||
->mutateRecordDataUsing(function (array $data, Script $record) {
|
||||
return [
|
||||
'name' => $record->name,
|
||||
'content' => $record->content,
|
||||
'global' => $record->project_id === null,
|
||||
];
|
||||
})
|
||||
->mutateRecordDataUsing(fn (array $data, Script $record): array => [
|
||||
'name' => $record->name,
|
||||
'content' => $record->content,
|
||||
'global' => $record->project_id === null,
|
||||
])
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->rules(EditScript::rules()['name']),
|
||||
@ -73,17 +82,17 @@ public function table(Table $table): Table
|
||||
Checkbox::make('global')
|
||||
->label('Is Global (Accessible in all projects)'),
|
||||
])
|
||||
->authorize(fn (Script $record) => auth()->user()->can('update', $record))
|
||||
->using(function (array $data, Script $record) {
|
||||
app(EditScript::class)->edit($record, auth()->user(), $data);
|
||||
->authorize(fn (Script $record) => $user->can('update', $record))
|
||||
->using(function (array $data, Script $record) use ($user): void {
|
||||
app(EditScript::class)->edit($record, $user, $data);
|
||||
$this->dispatch('$refresh');
|
||||
})
|
||||
->modalWidth(MaxWidth::ThreeExtraLarge),
|
||||
DeleteAction::make('delete')
|
||||
->label('Delete')
|
||||
->modalHeading('Delete Script')
|
||||
->authorize(fn (Script $record) => auth()->user()->can('delete', $record))
|
||||
->using(function (array $data, Script $record) {
|
||||
->authorize(fn (Script $record) => $user->can('delete', $record))
|
||||
->using(function (array $data, Script $record): void {
|
||||
$record->delete();
|
||||
}),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user