mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-06 00:12:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -25,18 +25,31 @@ class Commands extends Widget
|
||||
{
|
||||
public Site $site;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Command>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Command::query()->where('site_id', $this->site->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Command> $query
|
||||
* @return Builder<Command>
|
||||
*/
|
||||
protected function applySortingToTableQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->latest('created_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
@ -56,14 +69,17 @@ protected function getTableColumns(): array
|
||||
|
||||
protected function getTableHeaderActions(): array
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return [
|
||||
Action::make('new-command')
|
||||
->label('Create a Command')
|
||||
->modalDescription('The command will be executed inside the site\'s directory')
|
||||
->icon('heroicon-o-plus')
|
||||
->authorize(fn () => auth()->user()->can('create', [Command::class, $this->site, $this->site->server]))
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
->authorize(fn () => $user->can('create', [Command::class, $this->site, $this->site->server]))
|
||||
->action(function (array $data): void {
|
||||
run_action($this, function () use ($data): void {
|
||||
app(CreateCommand::class)->create($this->site, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
@ -91,6 +107,9 @@ protected function getTableHeaderActions(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->query($this->getTableQuery())
|
||||
->headerActions($this->getTableHeaderActions())
|
||||
@ -118,10 +137,8 @@ public function table(Table $table): Table
|
||||
|
||||
return $form;
|
||||
})
|
||||
->authorize(fn (Command $record) => auth()->user()->can('update', [$record->site, $record->site->server]))
|
||||
->action(function (array $data, Command $record) {
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
->authorize(fn (Command $record) => $user->can('update', [$record->site, $record->site->server]))
|
||||
->action(function (array $data, Command $record) use ($user): void {
|
||||
app(ExecuteCommand::class)->execute($record, $user, $data);
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
@ -130,24 +147,20 @@ public function table(Table $table): Table
|
||||
->tooltip('Last Log')
|
||||
->icon('heroicon-o-eye')
|
||||
->modalHeading('View Last Execution Log')
|
||||
->modalContent(function (Command $record) {
|
||||
return view('components.console-view', [
|
||||
'slot' => $record->lastExecution?->serverLog?->getContent() ?? 'Not executed yet',
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]);
|
||||
})
|
||||
->modalContent(fn (Command $record) => view('components.console-view', [
|
||||
'slot' => $record->lastExecution?->serverLog?->getContent() ?? 'Not executed yet',
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close'),
|
||||
EditAction::make('edit')
|
||||
->hiddenLabel()
|
||||
->tooltip('Edit')
|
||||
->modalHeading('Edit Command')
|
||||
->mutateRecordDataUsing(function (array $data, Command $record) {
|
||||
return [
|
||||
'name' => $record->name,
|
||||
'command' => $record->command,
|
||||
];
|
||||
})
|
||||
->mutateRecordDataUsing(fn (array $data, Command $record): array => [
|
||||
'name' => $record->name,
|
||||
'command' => $record->command,
|
||||
])
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->rules(EditCommand::rules()['name']),
|
||||
@ -156,8 +169,8 @@ public function table(Table $table): Table
|
||||
->helperText('You can use variables like ${VARIABLE_NAME} in the command. The variables will be asked when executing the command'),
|
||||
|
||||
])
|
||||
->authorize(fn (Command $record) => auth()->user()->can('update', [$record, $this->site, $this->site->server]))
|
||||
->using(function (array $data, Command $record) {
|
||||
->authorize(fn (Command $record) => $user->can('update', [$record, $this->site, $this->site->server]))
|
||||
->using(function (array $data, Command $record): void {
|
||||
app(EditCommand::class)->edit($record, $data);
|
||||
$this->dispatch('$refresh');
|
||||
})
|
||||
@ -167,8 +180,8 @@ public function table(Table $table): Table
|
||||
->hiddenLabel()
|
||||
->tooltip('Delete')
|
||||
->modalHeading('Delete Command')
|
||||
->authorize(fn (Command $record) => auth()->user()->can('delete', [$record, $this->site, $this->site->server]))
|
||||
->using(function (array $data, Command $record) {
|
||||
->authorize(fn (Command $record) => $user->can('delete', [$record, $this->site, $this->site->server]))
|
||||
->using(function (array $data, Command $record): void {
|
||||
$record->delete();
|
||||
}),
|
||||
]);
|
||||
|
@ -15,13 +15,23 @@ class DeploymentsList extends Widget
|
||||
{
|
||||
public Site $site;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Deployment>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Deployment::query()->where('site_id', $this->site->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Deployment> $query
|
||||
* @return Builder<Deployment>
|
||||
*/
|
||||
protected function applySortingToTableQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->latest('created_at');
|
||||
@ -53,6 +63,9 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->query($this->getTableQuery())
|
||||
->columns($this->getTableColumns())
|
||||
@ -62,14 +75,12 @@ public function table(Table $table): Table
|
||||
->hiddenLabel()
|
||||
->tooltip('View')
|
||||
->icon('heroicon-o-eye')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record->log))
|
||||
->authorize(fn ($record) => $user->can('view', $record->log))
|
||||
->modalHeading('View Log')
|
||||
->modalContent(function (Deployment $record) {
|
||||
return view('components.console-view', [
|
||||
'slot' => $record->log?->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]);
|
||||
})
|
||||
->modalContent(fn (Deployment $record) => view('components.console-view', [
|
||||
'slot' => $record->log?->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close'),
|
||||
Action::make('download')
|
||||
@ -77,7 +88,7 @@ public function table(Table $table): Table
|
||||
->tooltip('Download')
|
||||
->color('gray')
|
||||
->icon('heroicon-o-archive-box-arrow-down')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record->log))
|
||||
->authorize(fn ($record) => $user->can('view', $record->log))
|
||||
->action(fn (Deployment $record) => $record->log?->download()),
|
||||
]);
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ class Installing extends Widget implements HasForms, HasInfolists
|
||||
use InteractsWithForms;
|
||||
use InteractsWithInfolists;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected static bool $isLazy = false;
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Actions\Site\UpdateLoadBalancer;
|
||||
use App\Enums\LoadBalancerMethod;
|
||||
use App\Models\LoadBalancerServer;
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
@ -29,12 +30,15 @@ class LoadBalancerServers extends Widget implements HasForms
|
||||
|
||||
public string $method;
|
||||
|
||||
/**
|
||||
* @var array<int, mixed>
|
||||
*/
|
||||
public array $servers = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->setLoadBalancerServers();
|
||||
if (empty($this->servers)) {
|
||||
if ($this->servers === []) {
|
||||
$this->servers = [
|
||||
[
|
||||
'server' => null,
|
||||
@ -50,14 +54,12 @@ public function mount(): void
|
||||
#[On('load-balancer-updated')]
|
||||
public function setLoadBalancerServers(): void
|
||||
{
|
||||
$this->servers = $this->site->loadBalancerServers->map(function (LoadBalancerServer $server) {
|
||||
return [
|
||||
'server' => $server->ip,
|
||||
'port' => $server->port,
|
||||
'weight' => $server->weight,
|
||||
'backup' => $server->backup,
|
||||
];
|
||||
})->toArray();
|
||||
$this->servers = $this->site->loadBalancerServers->map(fn (LoadBalancerServer $server): array => [
|
||||
'server' => $server->ip,
|
||||
'port' => $server->port,
|
||||
'weight' => $server->weight,
|
||||
'backup' => $server->backup,
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
@ -84,14 +86,14 @@ public function form(Form $form): Form
|
||||
->searchable()
|
||||
->required()
|
||||
->rules(UpdateLoadBalancer::rules($this->site)['servers.*.server'])
|
||||
->options(function () {
|
||||
return $this->site->project->servers()
|
||||
->where('id', '!=', $this->site->server_id)
|
||||
->get()
|
||||
->mapWithKeys(function ($server) {
|
||||
return [$server->local_ip => $server->name.' ('.$server->local_ip.')'];
|
||||
});
|
||||
}),
|
||||
->options(fn () => $this->site->project->servers()
|
||||
->where('id', '!=', $this->site->server_id)
|
||||
->whereNotNull('local_ip')
|
||||
->get()
|
||||
->mapWithKeys(function ($server): array {
|
||||
/** @var Server $server */
|
||||
return $server->local_ip ? [$server->local_ip => $server->name.' ('.$server->local_ip.')'] : [];
|
||||
})),
|
||||
TextInput::make('port')
|
||||
->default(80)
|
||||
->required()
|
||||
@ -124,7 +126,7 @@ public function save(): void
|
||||
|
||||
$this->validate();
|
||||
|
||||
run_action($this, function () {
|
||||
run_action($this, function (): void {
|
||||
app(UpdateLoadBalancer::class)->update($this->site, [
|
||||
'method' => $this->method,
|
||||
'servers' => $this->servers,
|
||||
|
@ -7,6 +7,7 @@
|
||||
use App\Actions\Site\UpdateSourceControl;
|
||||
use App\Models\Site;
|
||||
use App\Models\SourceControl;
|
||||
use App\Models\User;
|
||||
use App\Web\Pages\Settings\SourceControls\Actions\Create;
|
||||
use App\Web\Pages\Settings\Tags\Actions\EditTags;
|
||||
use Filament\Forms\Components\Select;
|
||||
@ -28,6 +29,9 @@ class SiteDetails extends Widget implements HasForms, HasInfolists
|
||||
use InteractsWithForms;
|
||||
use InteractsWithInfolists;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected static bool $isLazy = false;
|
||||
@ -38,6 +42,9 @@ class SiteDetails extends Widget implements HasForms, HasInfolists
|
||||
|
||||
public function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $infolist
|
||||
->schema([
|
||||
Section::make()
|
||||
@ -59,15 +66,15 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->inlineLabel(),
|
||||
TextEntry::make('type')
|
||||
->extraAttributes(['class' => 'capitalize'])
|
||||
->icon(fn ($state) => 'icon-'.$state)
|
||||
->icon(fn ($state): string => 'icon-'.$state)
|
||||
->inlineLabel(),
|
||||
TextEntry::make('tags.*')
|
||||
->default('No tags')
|
||||
->formatStateUsing(fn ($state) => is_object($state) ? $state->name : $state)
|
||||
->formatStateUsing(fn ($state) => is_object($state) && isset($state->name) ? $state->name : $state)
|
||||
->inlineLabel()
|
||||
->badge()
|
||||
->color(fn ($state) => is_object($state) ? $state->color : 'gray')
|
||||
->icon(fn ($state) => is_object($state) ? 'heroicon-o-tag' : '')
|
||||
->color(fn ($state) => is_object($state) && isset($state->color) ? $state->color : 'gray')
|
||||
->icon(fn ($state): string => is_object($state) ? 'heroicon-o-tag' : '')
|
||||
->suffixAction(
|
||||
EditTags::infolist($this->site)
|
||||
),
|
||||
@ -93,8 +100,8 @@ public function infolist(Infolist $infolist): Infolist
|
||||
),
|
||||
|
||||
])
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
->action(function (array $data): void {
|
||||
run_action($this, function () use ($data): void {
|
||||
app(UpdatePHPVersion::class)->update($this->site, $data);
|
||||
|
||||
Notification::make()
|
||||
@ -108,7 +115,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->inlineLabel()
|
||||
->badge()
|
||||
->default('No aliases')
|
||||
->color(fn ($state) => $state == 'No aliases' ? 'gray' : 'primary')
|
||||
->color(fn ($state): string => $state == 'No aliases' ? 'gray' : 'primary')
|
||||
->suffixAction(
|
||||
Action::make('edit_aliases')
|
||||
->icon('heroicon-o-pencil-square')
|
||||
@ -124,8 +131,8 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->nestedRecursiveRules(UpdateAliases::rules()['aliases.*']),
|
||||
|
||||
])
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
->action(function (array $data): void {
|
||||
run_action($this, function () use ($data): void {
|
||||
app(UpdateAliases::class)->update($this->site, $data);
|
||||
|
||||
Notification::make()
|
||||
@ -152,7 +159,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->label('Source Control')
|
||||
->rules(UpdateSourceControl::rules()['source_control'])
|
||||
->options(
|
||||
SourceControl::getByProjectId(auth()->user()->current_project_id)
|
||||
SourceControl::getByProjectId($user->current_project_id)
|
||||
->pluck('profile', 'id')
|
||||
)
|
||||
->default($this->site->source_control_id)
|
||||
@ -164,13 +171,13 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->icon('heroicon-o-wifi')
|
||||
->tooltip('Connect to a source control')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->authorize(fn () => auth()->user()->can('create', SourceControl::class))
|
||||
->authorize(fn () => $user->can('create', SourceControl::class))
|
||||
->action(fn (array $data) => Create::action($data))
|
||||
)
|
||||
->placeholder('Select source control'),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
->action(function (array $data): void {
|
||||
run_action($this, function () use ($data): void {
|
||||
app(UpdateSourceControl::class)->update($this->site, $data);
|
||||
|
||||
Notification::make()
|
||||
|
@ -18,6 +18,9 @@ class SiteSummary extends Widget implements HasForms, HasInfolists
|
||||
use InteractsWithForms;
|
||||
use InteractsWithInfolists;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected static bool $isLazy = false;
|
||||
@ -44,9 +47,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
TextEntry::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(static function ($state): string {
|
||||
return Site::$statusColors[$state];
|
||||
}),
|
||||
->color(static fn ($state): string => Site::$statusColors[$state]),
|
||||
])
|
||||
->columns(3),
|
||||
])
|
||||
|
@ -17,6 +17,9 @@ class SitesList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* @return Builder<Site>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Site::query()->where('server_id', $this->server->id);
|
||||
@ -26,7 +29,7 @@ protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
IconColumn::make('type')
|
||||
->icon(fn (Site $record) => 'icon-'.$record->type)
|
||||
->icon(fn (Site $record): string => 'icon-'.$record->type)
|
||||
->tooltip(fn (Site $record) => $record->type)
|
||||
->width(24),
|
||||
TextColumn::make('domain')
|
||||
@ -54,17 +57,20 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
->columns($this->getTableColumns())
|
||||
->recordUrl(fn (Site $record) => View::getUrl(parameters: ['server' => $this->server, 'site' => $record]))
|
||||
->recordUrl(fn (Site $record): string => View::getUrl(parameters: ['server' => $this->server, 'site' => $record]))
|
||||
->actions([
|
||||
Action::make('settings')
|
||||
->label('Settings')
|
||||
->icon('heroicon-o-cog-6-tooth')
|
||||
->authorize(fn (Site $record) => auth()->user()->can('update', [$record, $this->server]))
|
||||
->url(fn (Site $record) => Settings::getUrl(parameters: ['server' => $this->server, 'site' => $record])),
|
||||
->authorize(fn (Site $record) => $user->can('update', [$record, $this->server]))
|
||||
->url(fn (Site $record): string => Settings::getUrl(parameters: ['server' => $this->server, 'site' => $record])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user