mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -20,6 +20,9 @@ class Index extends Page
|
||||
|
||||
protected static ?string $title = 'Firewall';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
public function mount(): void
|
||||
@ -34,6 +37,9 @@ public function getWidgets(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public static function getFirewallForm(?FirewallRule $record = null): array
|
||||
{
|
||||
return [
|
||||
@ -68,7 +74,7 @@ public static function getFirewallForm(?FirewallRule $record = null): array
|
||||
->helperText('Allow connections from any source, regardless of their IP address or subnet mask.')
|
||||
->live(),
|
||||
TextInput::make('source')
|
||||
->hidden(fn (Get $get) => $get('source_any') == true)
|
||||
->hidden(fn (Get $get): bool => $get('source_any') == true)
|
||||
->label('Source')
|
||||
->helperText('The IP address of the source of the connection.')
|
||||
->rules(ManageRule::rules()['source'])
|
||||
@ -78,13 +84,13 @@ public static function getFirewallForm(?FirewallRule $record = null): array
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->color('primary')
|
||||
->tooltip('Use My IP')
|
||||
->action(function ($set) {
|
||||
->action(function ($set): void {
|
||||
$ip = Request::ip();
|
||||
$set('source', $ip);
|
||||
})
|
||||
),
|
||||
TextInput::make('mask')
|
||||
->hidden(fn (Get $get) => $get('source_any') == true)
|
||||
->hidden(fn (Get $get): bool => $get('source_any') == true)
|
||||
->label('Mask')
|
||||
->default($record->mask ?? null)
|
||||
->helperText('The subnet mask of the source of the connection. Leave blank for a single IP address.')
|
||||
@ -110,8 +116,8 @@ protected function getHeaderActions(): array
|
||||
->modalDescription('Add a new rule to the firewall')
|
||||
->modalSubmitActionLabel('Create')
|
||||
->form(self::getFirewallForm())
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
->action(function (array $data): void {
|
||||
run_action($this, function () use ($data): void {
|
||||
app(ManageRule::class)->create($this->server, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
@ -19,8 +19,14 @@ class RulesList extends Widget
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<FirewallRule>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return FirewallRule::query()->where('server_id', $this->server->id);
|
||||
@ -36,7 +42,7 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('type')
|
||||
->sortable()
|
||||
->badge()
|
||||
->color(fn ($state) => $state === 'allow' ? 'success' : 'warning')
|
||||
->color(fn ($state): string => $state === 'allow' ? 'success' : 'warning')
|
||||
->label('Type')
|
||||
->formatStateUsing(fn ($state) => Str::upper($state)),
|
||||
TextColumn::make('id')
|
||||
@ -62,12 +68,15 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn (FirewallRule $record) => $record->getStatusColor()),
|
||||
->color(fn (FirewallRule $record): string => $record->getStatusColor()),
|
||||
];
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -81,10 +90,10 @@ public function table(Table $table): Table
|
||||
->modalHeading('Edit Firewall Rule')
|
||||
->modalDescription('Edit the associated servers firewall rule.')
|
||||
->modalSubmitActionLabel('Update')
|
||||
->authorize(fn (FirewallRule $record) => auth()->user()->can('update', $record))
|
||||
->form(fn ($record) => Index::getFirewallForm($record))
|
||||
->action(function (FirewallRule $record, array $data) {
|
||||
run_action($this, function () use ($record, $data) {
|
||||
->authorize(fn (FirewallRule $record) => $user->can('update', $record))
|
||||
->form(fn ($record): array => Index::getFirewallForm($record))
|
||||
->action(function (FirewallRule $record, array $data): void {
|
||||
run_action($this, function () use ($record, $data): void {
|
||||
app(ManageRule::class)->update($record, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
@ -101,8 +110,8 @@ public function table(Table $table): Table
|
||||
->color('danger')
|
||||
->hiddenLabel()
|
||||
->requiresConfirmation()
|
||||
->authorize(fn (FirewallRule $record) => auth()->user()->can('delete', $record))
|
||||
->action(function (FirewallRule $record) {
|
||||
->authorize(fn (FirewallRule $record) => $user->can('delete', $record))
|
||||
->action(function (FirewallRule $record): void {
|
||||
try {
|
||||
app(ManageRule::class)->delete($record);
|
||||
} catch (\Exception $e) {
|
||||
|
Reference in New Issue
Block a user