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

@ -4,6 +4,7 @@
use App\Actions\SourceControl\ConnectSourceControl;
use App\Enums\SourceControl;
use App\Models\User;
use Exception;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Select;
@ -13,12 +14,15 @@
class Create
{
/**
* @return array<int, mixed>
*/
public static function form(): array
{
return [
Select::make('provider')
->options(
collect(config('core.source_control_providers'))
collect((array) config('core.source_control_providers'))
->mapWithKeys(fn ($provider) => [$provider => $provider])
)
->live()
@ -29,21 +33,21 @@ public static function form(): array
TextInput::make('token')
->label('API Key')
->validationAttribute('API Key')
->visible(fn ($get) => in_array($get('provider'), [
->visible(fn ($get): bool => in_array($get('provider'), [
SourceControl::GITHUB,
SourceControl::GITLAB,
]))
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['token']),
TextInput::make('url')
->label('URL (optional)')
->visible(fn ($get) => $get('provider') == SourceControl::GITLAB)
->visible(fn ($get): bool => $get('provider') == SourceControl::GITLAB)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['url'])
->helperText('If you run a self-managed gitlab enter the url here, leave empty to use gitlab.com'),
TextInput::make('username')
->visible(fn ($get) => $get('provider') == SourceControl::BITBUCKET)
->visible(fn ($get): bool => $get('provider') == SourceControl::BITBUCKET)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['username']),
TextInput::make('password')
->visible(fn ($get) => $get('provider') == SourceControl::BITBUCKET)
->visible(fn ($get): bool => $get('provider') == SourceControl::BITBUCKET)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['password']),
Checkbox::make('global')
->label('Is Global (Accessible in all projects)'),
@ -51,12 +55,17 @@ public static function form(): array
}
/**
* @param array<string, mixed> $data
*
* @throws Exception
*/
public static function action(array $data): void
{
/** @var User $user */
$user = auth()->user();
try {
app(ConnectSourceControl::class)->connect(auth()->user(), auth()->user()->currentProject, $data);
app(ConnectSourceControl::class)->connect($user->currentProject, $data);
} catch (Exception $e) {
Notification::make()
->title($e->getMessage())

View File

@ -4,6 +4,7 @@
use App\Actions\SourceControl\EditSourceControl;
use App\Models\SourceControl;
use App\Models\User;
use Exception;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TextInput;
@ -12,6 +13,9 @@
class Edit
{
/**
* @return array<int, mixed>
*/
public static function form(SourceControl $sourceControl): array
{
return [
@ -39,12 +43,17 @@ public static function form(SourceControl $sourceControl): array
}
/**
* @param array<string, mixed> $data
*
* @throws Exception
*/
public static function action(SourceControl $sourceControl, array $data): void
{
/** @var User $user */
$user = auth()->user();
try {
app(EditSourceControl::class)->edit($sourceControl, auth()->user()->currentProject, $data);
app(EditSourceControl::class)->edit($sourceControl, $user->currentProject, $data);
} catch (Exception $e) {
Notification::make()
->title($e->getMessage())

View File

@ -42,7 +42,7 @@ protected function getHeaderActions(): array
->form(Actions\Create::form())
->authorize('create', SourceControl::class)
->modalWidth(MaxWidth::Large)
->action(function (array $data) {
->action(function (array $data): void {
Actions\Create::action($data);
$this->dispatch('$refresh');

View File

@ -4,6 +4,7 @@
use App\Actions\SourceControl\DeleteSourceControl;
use App\Models\SourceControl;
use App\Models\User;
use App\Web\Pages\Settings\SourceControls\Actions\Edit;
use Exception;
use Filament\Notifications\Notification;
@ -18,18 +19,27 @@
class SourceControlsList extends Widget
{
/**
* @var array<string>
*/
protected $listeners = ['$refresh'];
/**
* @return Builder<SourceControl>
*/
protected function getTableQuery(): Builder
{
return SourceControl::getByProjectId(auth()->user()->current_project_id);
/** @var User $user */
$user = auth()->user();
return SourceControl::getByProjectId($user->current_project_id);
}
protected function getTableColumns(): array
{
return [
IconColumn::make('provider')
->icon(fn (SourceControl $record) => 'icon-'.$record->provider)
->icon(fn (SourceControl $record): string => 'icon-'.$record->provider)
->width(24),
TextColumn::make('name')
->default(fn (SourceControl $record) => $record->profile)
@ -39,10 +49,8 @@ protected function getTableColumns(): array
TextColumn::make('id')
->label('Global')
->badge()
->color(fn (SourceControl $record) => $record->project_id ? 'gray' : 'success')
->formatStateUsing(function (SourceControl $record) {
return $record->project_id ? 'No' : 'Yes';
}),
->color(fn (SourceControl $record): string => $record->project_id ? 'gray' : 'success')
->formatStateUsing(fn (SourceControl $record): string => $record->project_id ? 'No' : 'Yes'),
TextColumn::make('created_at')
->label('Created At')
->formatStateUsing(fn (SourceControl $record) => $record->created_at_by_timezone)
@ -53,6 +61,9 @@ protected function getTableColumns(): array
public function table(Table $table): Table
{
/** @var User $user */
$user = auth()->user();
return $table
->heading(null)
->query($this->getTableQuery())
@ -61,18 +72,16 @@ public function table(Table $table): Table
EditAction::make('edit')
->label('Edit')
->modalHeading('Edit Source Control')
->fillForm(function (array $data, SourceControl $record) {
return [
'provider' => $record->provider,
'name' => $record->profile,
'token' => $record->provider_data['token'] ?? null,
'username' => $record->provider_data['username'] ?? null,
'password' => $record->provider_data['password'] ?? null,
'global' => $record->project_id === null,
];
})
->form(fn (SourceControl $record) => Edit::form($record))
->authorize(fn (SourceControl $record) => auth()->user()->can('update', $record))
->fillForm(fn (array $data, SourceControl $record): array => [
'provider' => $record->provider,
'name' => $record->profile,
'token' => $record->provider_data['token'] ?? null,
'username' => $record->provider_data['username'] ?? null,
'password' => $record->provider_data['password'] ?? null,
'global' => $record->project_id === null,
])
->form(fn (SourceControl $record): array => Edit::form($record))
->authorize(fn (SourceControl $record) => $user->can('update', $record))
->using(fn (array $data, SourceControl $record) => Edit::action($record, $data))
->modalWidth(MaxWidth::Medium),
Action::make('delete')
@ -81,8 +90,8 @@ public function table(Table $table): Table
->color('danger')
->requiresConfirmation()
->modalHeading('Delete Source Control')
->authorize(fn (SourceControl $record) => auth()->user()->can('delete', $record))
->action(function (array $data, SourceControl $record) {
->authorize(fn (SourceControl $record) => $user->can('delete', $record))
->action(function (array $data, SourceControl $record): void {
try {
app(DeleteSourceControl::class)->delete($record);