mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 23:12:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -12,12 +12,15 @@
|
||||
|
||||
class Create
|
||||
{
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public static function form(): array
|
||||
{
|
||||
return [
|
||||
Select::make('provider')
|
||||
->options(
|
||||
collect(config('core.notification_channels_providers'))
|
||||
collect((array) config('core.notification_channels_providers'))
|
||||
->mapWithKeys(fn ($provider) => [$provider => $provider])
|
||||
)
|
||||
->live()
|
||||
@ -47,12 +50,16 @@ public static function form(): array
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function action(array $data): void
|
||||
{
|
||||
try {
|
||||
app(AddChannel::class)->add(auth()->user(), $data);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
app(AddChannel::class)->add($user, $data);
|
||||
} catch (Exception $e) {
|
||||
Notification::make()
|
||||
->title($e->getMessage())
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
class Edit
|
||||
{
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public static function form(): array
|
||||
{
|
||||
return [
|
||||
@ -20,8 +23,13 @@ public static function form(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function action(NotificationChannel $channel, array $data): void
|
||||
{
|
||||
app(EditChannel::class)->edit($channel, auth()->user(), $data);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
app(EditChannel::class)->edit($channel, $user, $data);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ protected function getHeaderActions(): array
|
||||
->form(Actions\Create::form())
|
||||
->authorize('create', NotificationChannel::class)
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->action(function (array $data) {
|
||||
->action(function (array $data): void {
|
||||
try {
|
||||
Actions\Create::action($data);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Web\Pages\Settings\NotificationChannels\Widgets;
|
||||
|
||||
use App\Models\NotificationChannel;
|
||||
use App\Models\User;
|
||||
use App\Web\Pages\Settings\NotificationChannels\Actions\Edit;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
@ -15,18 +16,27 @@
|
||||
|
||||
class NotificationChannelsList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<NotificationChannel>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return NotificationChannel::getByProjectId(auth()->user()->current_project_id);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return NotificationChannel::getByProjectId($user->current_project_id);
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
IconColumn::make('provider')
|
||||
->icon(fn (NotificationChannel $record) => 'icon-'.$record->provider)
|
||||
->icon(fn (NotificationChannel $record): string => 'icon-'.$record->provider)
|
||||
->width(24),
|
||||
TextColumn::make('label')
|
||||
->default(fn (NotificationChannel $record) => $record->label)
|
||||
@ -35,10 +45,8 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('id')
|
||||
->label('Global')
|
||||
->badge()
|
||||
->color(fn (NotificationChannel $record) => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(function (NotificationChannel $record) {
|
||||
return $record->project_id ? 'No' : 'Yes';
|
||||
}),
|
||||
->color(fn (NotificationChannel $record): string => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(fn (NotificationChannel $record): string => $record->project_id ? 'No' : 'Yes'),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn (NotificationChannel $record) => $record->created_at_by_timezone)
|
||||
@ -49,6 +57,9 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -56,20 +67,18 @@ public function table(Table $table): Table
|
||||
->actions([
|
||||
EditAction::make('edit')
|
||||
->modalHeading('Edit Notification Channel')
|
||||
->mutateRecordDataUsing(function (array $data, NotificationChannel $record) {
|
||||
return [
|
||||
'label' => $record->label,
|
||||
'global' => ! $record->project_id,
|
||||
];
|
||||
})
|
||||
->mutateRecordDataUsing(fn (array $data, NotificationChannel $record): array => [
|
||||
'label' => $record->label,
|
||||
'global' => ! $record->project_id,
|
||||
])
|
||||
->form(Edit::form())
|
||||
->authorize(fn (NotificationChannel $record) => auth()->user()->can('update', $record))
|
||||
->authorize(fn (NotificationChannel $record) => $user->can('update', $record))
|
||||
->using(fn (array $data, NotificationChannel $record) => Edit::action($record, $data))
|
||||
->modalWidth(MaxWidth::Medium),
|
||||
DeleteAction::make('delete')
|
||||
->modalHeading('Delete Notification Channel')
|
||||
->authorize(fn (NotificationChannel $record) => auth()->user()->can('delete', $record))
|
||||
->using(function (array $data, NotificationChannel $record) {
|
||||
->authorize(fn (NotificationChannel $record) => $user->can('delete', $record))
|
||||
->using(function (array $data, NotificationChannel $record): void {
|
||||
$record->delete();
|
||||
}),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user