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

@ -67,8 +67,8 @@ protected function getHeaderActions(): array
->default(false),
]),
])
->using(function (array $data) {
run_action($this, function () use ($data) {
->using(function (array $data): void {
run_action($this, function () use ($data): void {
app(CreateQueue::class)->create($this->site, $data);
$this->dispatch('$refresh');

View File

@ -27,8 +27,14 @@ class QueuesList extends Widget
{
public Site $site;
/**
* @var array<string>
*/
protected $listeners = ['$refresh'];
/**
* @return Builder<Queue>
*/
protected function getTableQuery(): Builder
{
return Queue::query()->where('site_id', $this->site->id);
@ -75,12 +81,15 @@ public function table(Table $table): Table
private function operationAction(string $type, string $icon): Action
{
/** @var \App\Models\User */
$user = auth()->user();
return Action::make($type)
->authorize(fn (Queue $record) => auth()->user()->can('update', [$record, $this->site, $this->site->server]))
->authorize(fn (Queue $record) => $user->can('update', [$record, $this->site, $this->site->server]))
->label(ucfirst($type).' queue')
->icon($icon)
->action(function (Queue $record) use ($type) {
run_action($this, function () use ($record, $type) {
->action(function (Queue $record) use ($type): void {
run_action($this, function () use ($record, $type): void {
app(ManageQueue::class)->$type($record);
$this->dispatch('$refresh');
});
@ -89,27 +98,31 @@ private function operationAction(string $type, string $icon): Action
private function logsAction(): Action
{
/** @var \App\Models\User */
$user = auth()->user();
return Action::make('logs')
->icon('heroicon-o-eye')
->authorize(fn (Queue $record) => auth()->user()->can('view', [$record, $this->site, $this->site->server]))
->authorize(fn (Queue $record) => $user->can('view', [$record, $this->site, $this->site->server]))
->modalHeading('View Log')
->modalContent(function (Queue $record) {
return view('components.console-view', [
'slot' => app(GetQueueLogs::class)->getLogs($record),
'attributes' => new ComponentAttributeBag,
]);
})
->modalContent(fn (Queue $record) => view('components.console-view', [
'slot' => app(GetQueueLogs::class)->getLogs($record),
'attributes' => new ComponentAttributeBag,
]))
->modalSubmitAction(false)
->modalCancelActionLabel('Close');
}
private function editAction(): Action
{
/** @var \App\Models\User */
$user = auth()->user();
return EditAction::make('edit')
->icon('heroicon-o-pencil-square')
->authorize(fn (Queue $record) => auth()->user()->can('update', [$record, $this->site, $this->site->server]))
->authorize(fn (Queue $record) => $user->can('update', [$record, $this->site, $this->site->server]))
->modalWidth(MaxWidth::ExtraLarge)
->fillForm(fn (Queue $record) => [
->fillForm(fn (Queue $record): array => [
'command' => $record->command,
'user' => $record->user,
'numprocs' => $record->numprocs,
@ -138,8 +151,8 @@ private function editAction(): Action
->default(false),
]),
])
->using(function (Queue $record, array $data) {
run_action($this, function () use ($record, $data) {
->using(function (Queue $record, array $data): void {
run_action($this, function () use ($record, $data): void {
app(EditQueue::class)->edit($record, $data);
$this->dispatch('$refresh');
});
@ -148,11 +161,14 @@ private function editAction(): Action
private function deleteAction(): Action
{
/** @var \App\Models\User */
$user = auth()->user();
return DeleteAction::make('delete')
->icon('heroicon-o-trash')
->authorize(fn (Queue $record) => auth()->user()->can('delete', [$record, $this->site, $this->site->server]))
->using(function (Queue $record) {
run_action($this, function () use ($record) {
->authorize(fn (Queue $record) => $user->can('delete', [$record, $this->site, $this->site->server]))
->using(function (Queue $record): void {
run_action($this, function () use ($record): void {
app(DeleteQueue::class)->delete($record);
$this->dispatch('$refresh');
});

View File

@ -47,11 +47,11 @@ protected function getHeaderActions(): array
->openUrlInNewTab(),
Action::make('force-ssl')
->label('Force SSL')
->tooltip(fn () => $this->site->force_ssl ? 'Disable force SSL' : 'Enable force SSL')
->icon(fn () => $this->site->force_ssl ? 'icon-force-ssl-enabled' : 'icon-force-ssl-disabled')
->tooltip(fn (): string => $this->site->force_ssl ? 'Disable force SSL' : 'Enable force SSL')
->icon(fn (): string => $this->site->force_ssl ? 'icon-force-ssl-enabled' : 'icon-force-ssl-disabled')
->requiresConfirmation()
->modalSubmitActionLabel(fn () => $this->site->force_ssl ? 'Disable' : 'Enable')
->action(function () {
->modalSubmitActionLabel(fn (): string => $this->site->force_ssl ? 'Disable' : 'Enable')
->action(function (): void {
$this->site->update([
'force_ssl' => ! $this->site->force_ssl,
]);
@ -72,34 +72,34 @@ protected function getHeaderActions(): array
->message('Let\'s Encrypt has rate limits. Read more about them <a href="https://letsencrypt.org/docs/rate-limits/" target="_blank" class="underline">here</a>.'),
Select::make('type')
->options(
collect(config('core.ssl_types'))->mapWithKeys(fn ($type) => [$type => $type])
collect((array) config('core.ssl_types'))->mapWithKeys(fn ($type) => [$type => $type])
)
->rules(fn (Get $get) => CreateSSL::rules($get())['type'])
->reactive(),
TextInput::make('email')
->rules(fn (Get $get) => CreateSSL::rules($get())['email'] ?? [])
->visible(fn (Get $get) => $get('type') === SslType::LETSENCRYPT)
->visible(fn (Get $get): bool => $get('type') === SslType::LETSENCRYPT)
->helperText('Email address to provide to Certbot.'),
Textarea::make('certificate')
->rows(5)
->rules(fn (Get $get) => CreateSSL::rules($get())['certificate'])
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
->visible(fn (Get $get): bool => $get('type') === SslType::CUSTOM),
Textarea::make('private')
->label('Private Key')
->rows(5)
->rules(fn (Get $get) => CreateSSL::rules($get())['private'])
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
->visible(fn (Get $get): bool => $get('type') === SslType::CUSTOM),
DatePicker::make('expires_at')
->format('Y-m-d')
->rules(fn (Get $get) => CreateSSL::rules($get())['expires_at'])
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
->visible(fn (Get $get): bool => $get('type') === SslType::CUSTOM),
Checkbox::make('aliases')
->label("Set SSL for site's aliases as well"),
])
->createAnother(false)
->modalWidth(MaxWidth::Large)
->using(function (array $data) {
run_action($this, function () use ($data) {
->using(function (array $data): void {
run_action($this, function () use ($data): void {
app(CreateSSL::class)->create($this->site, $data);
$this->dispatch('$refresh');

View File

@ -20,8 +20,14 @@ class SslsList extends Widget
{
public Site $site;
/**
* @var array<string>
*/
protected $listeners = ['$refresh'];
/**
* @return Builder<Ssl>
*/
protected function getTableQuery(): Builder
{
return Ssl::query()->where('site_id', $this->site->id);
@ -29,10 +35,12 @@ protected function getTableQuery(): Builder
protected function getTableColumns(): array
{
auth()->user();
return [
IconColumn::make('is_active')
->color(fn (Ssl $record) => $record->is_active ? 'green' : 'gray')
->icon(fn (Ssl $record) => $record->is_active ? 'heroicon-o-lock-closed' : 'heroicon-o-lock-open'),
->color(fn (Ssl $record): string => $record->is_active ? 'green' : 'gray')
->icon(fn (Ssl $record): string => $record->is_active ? 'heroicon-o-lock-closed' : 'heroicon-o-lock-open'),
TextColumn::make('type')
->searchable()
->sortable(),
@ -40,7 +48,7 @@ protected function getTableColumns(): array
->formatStateUsing(fn (Ssl $record) => $record->created_at_by_timezone)
->sortable(),
TextColumn::make('expires_at')
->formatStateUsing(fn (Ssl $record) => $record->getDateTimeByTimezone($record->expires_at))
->formatStateUsing(fn (Ssl $record): string => $record->getDateTimeByTimezone($record->expires_at))
->sortable(),
TextColumn::make('status')
->label('Status')
@ -53,6 +61,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())
@ -60,15 +71,15 @@ public function table(Table $table): Table
->actions([
Action::make('activate-ssl')
->hiddenLabel()
->visible(fn (Ssl $record) => ! $record->is_active)
->visible(fn (Ssl $record): bool => ! $record->is_active)
->tooltip('Activate SSL')
->icon('heroicon-o-lock-closed')
->authorize(fn (Ssl $record) => auth()->user()->can('update', [$record->site, $this->site->server]))
->authorize(fn (Ssl $record) => $user->can('update', [$record->site, $this->site->server]))
->requiresConfirmation()
->modalHeading('Activate SSL')
->modalSubmitActionLabel('Activate')
->action(function (Ssl $record) {
run_action($this, function () use ($record) {
->action(function (Ssl $record): void {
run_action($this, function () use ($record): void {
app(ActivateSSL::class)->activate($record);
Notification::make()
@ -81,23 +92,21 @@ public function table(Table $table): Table
->hiddenLabel()
->tooltip('Logs')
->icon('heroicon-o-eye')
->authorize(fn (Ssl $record) => auth()->user()->can('view', [$record, $this->site, $this->site->server]))
->authorize(fn (Ssl $record) => $user->can('view', [$record, $this->site, $this->site->server]))
->modalHeading('View Log')
->modalContent(function (Ssl $record) {
return view('components.console-view', [
'slot' => $record->log?->getContent(),
'attributes' => new ComponentAttributeBag,
]);
})
->modalContent(fn (Ssl $record) => view('components.console-view', [
'slot' => $record->log?->getContent(),
'attributes' => new ComponentAttributeBag,
]))
->modalSubmitAction(false)
->modalCancelActionLabel('Close'),
DeleteAction::make('delete')
->hiddenLabel()
->tooltip('Delete')
->icon('heroicon-o-trash')
->authorize(fn (Ssl $record) => auth()->user()->can('delete', [$record, $this->site, $this->site->server]))
->using(function (Ssl $record) {
run_action($this, function () use ($record) {
->authorize(fn (Ssl $record) => $user->can('delete', [$record, $this->site, $this->site->server]))
->using(function (Ssl $record): void {
run_action($this, function () use ($record): void {
app(DeleteSSL::class)->delete($record);
$this->dispatch('$refresh');
});