mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 08:52:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -7,7 +7,9 @@
|
||||
use App\Enums\PHP;
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Enums\Webserver;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use App\Web\Components\Page;
|
||||
use App\Web\Fields\AlertField;
|
||||
use App\Web\Fields\ProviderField;
|
||||
@ -37,7 +39,10 @@ public static function getNavigationItemActiveRoutePattern(): string
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('viewAny', [Server::class, auth()->user()->currentProject]);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$this->authorize('viewAny', [Server::class, $user->currentProject]);
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
@ -53,7 +58,11 @@ protected function getHeaderActions(): array
|
||||
'public_key' => get_public_key_content(),
|
||||
]);
|
||||
|
||||
$project = auth()->user()->currentProject;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $user->currentProject;
|
||||
|
||||
return [
|
||||
\Filament\Actions\Action::make('read-the-docs')
|
||||
@ -65,7 +74,7 @@ protected function getHeaderActions(): array
|
||||
\Filament\Actions\Action::make('create')
|
||||
->label('Create a Server')
|
||||
->icon('heroicon-o-plus')
|
||||
->authorize('create', [Server::class, auth()->user()->currentProject])
|
||||
->authorize('create', [Server::class, $user->currentProject])
|
||||
->modalWidth(MaxWidth::FiveExtraLarge)
|
||||
->slideOver()
|
||||
->form([
|
||||
@ -74,7 +83,7 @@ protected function getHeaderActions(): array
|
||||
->default(ServerProvider::CUSTOM)
|
||||
->live()
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
->afterStateUpdated(function (callable $set): void {
|
||||
$set('server_provider', null);
|
||||
$set('region', null);
|
||||
$set('plan', null);
|
||||
@ -83,16 +92,14 @@ protected function getHeaderActions(): array
|
||||
AlertField::make('alert')
|
||||
->warning()
|
||||
->message(__('servers.create.public_key_warning'))
|
||||
->visible(fn ($get) => $get('provider') === ServerProvider::CUSTOM),
|
||||
->visible(fn ($get): bool => $get('provider') === ServerProvider::CUSTOM),
|
||||
Select::make('server_provider')
|
||||
->visible(fn ($get) => $get('provider') !== ServerProvider::CUSTOM)
|
||||
->visible(fn ($get): bool => $get('provider') !== ServerProvider::CUSTOM)
|
||||
->label('Server provider connection')
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['server_provider'])
|
||||
->options(function ($get) {
|
||||
return \App\Models\ServerProvider::getByProjectId(auth()->user()->current_project_id)
|
||||
->where('provider', $get('provider'))
|
||||
->pluck('profile', 'id');
|
||||
})
|
||||
->options(fn ($get) => \App\Models\ServerProvider::getByProjectId($project->id)
|
||||
->where('provider', $get('provider'))
|
||||
->pluck('profile', 'id'))
|
||||
->suffixAction(
|
||||
Action::make('connect')
|
||||
->form(Create::form())
|
||||
@ -101,7 +108,7 @@ protected function getHeaderActions(): array
|
||||
->icon('heroicon-o-wifi')
|
||||
->tooltip('Connect to a new server provider')
|
||||
->modalWidth(MaxWidth::Medium)
|
||||
->authorize(fn () => auth()->user()->can('create', \App\Models\ServerProvider::class))
|
||||
->authorize(fn () => $user->can('create', \App\Models\ServerProvider::class))
|
||||
->action(fn (array $data) => Create::action($data))
|
||||
)
|
||||
->placeholder('Select profile')
|
||||
@ -109,7 +116,7 @@ protected function getHeaderActions(): array
|
||||
->live()
|
||||
->reactive()
|
||||
->selectablePlaceholder(false)
|
||||
->visible(fn ($get) => $get('provider') !== ServerProvider::CUSTOM),
|
||||
->visible(fn ($get): bool => $get('provider') !== ServerProvider::CUSTOM),
|
||||
Grid::make()
|
||||
->schema([
|
||||
Select::make('region')
|
||||
@ -117,7 +124,7 @@ protected function getHeaderActions(): array
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['region'] ?? [])
|
||||
->live()
|
||||
->reactive()
|
||||
->options(function ($get) {
|
||||
->options(function ($get): array {
|
||||
if (! $get('server_provider')) {
|
||||
return [];
|
||||
}
|
||||
@ -125,14 +132,14 @@ protected function getHeaderActions(): array
|
||||
return \App\Models\ServerProvider::regions($get('server_provider'));
|
||||
})
|
||||
->loadingMessage('Loading regions...')
|
||||
->disabled(fn ($get) => ! $get('server_provider'))
|
||||
->placeholder(fn ($get) => $get('server_provider') ? 'Select region' : 'Select connection first')
|
||||
->disabled(fn ($get): bool => ! $get('server_provider'))
|
||||
->placeholder(fn ($get): string => $get('server_provider') ? 'Select region' : 'Select connection first')
|
||||
->searchable(),
|
||||
Select::make('plan')
|
||||
->label('Plan')
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['plan'] ?? [])
|
||||
->reactive()
|
||||
->options(function ($get) {
|
||||
->options(function ($get): array {
|
||||
if (! $get('server_provider') || ! $get('region')) {
|
||||
return [];
|
||||
}
|
||||
@ -140,11 +147,11 @@ protected function getHeaderActions(): array
|
||||
return \App\Models\ServerProvider::plans($get('server_provider'), $get('region'));
|
||||
})
|
||||
->loadingMessage('Loading plans...')
|
||||
->disabled(fn ($get) => ! $get('region'))
|
||||
->placeholder(fn ($get) => $get('region') ? 'Select plan' : 'Select plan first')
|
||||
->disabled(fn ($get): bool => ! $get('region'))
|
||||
->placeholder(fn ($get): string => $get('region') ? 'Select plan' : 'Select plan first')
|
||||
->searchable(),
|
||||
])
|
||||
->visible(fn ($get) => $get('provider') !== ServerProvider::CUSTOM),
|
||||
->visible(fn ($get): bool => $get('provider') !== ServerProvider::CUSTOM),
|
||||
TextInput::make('public_key')
|
||||
->label('Public Key')
|
||||
->default($publicKey)
|
||||
@ -152,7 +159,7 @@ protected function getHeaderActions(): array
|
||||
Action::make('copy')
|
||||
->icon('heroicon-o-clipboard-document-list')
|
||||
->tooltip('Copy')
|
||||
->action(function ($livewire, $state) {
|
||||
->action(function ($livewire, string $state): void {
|
||||
$livewire->js(
|
||||
'window.navigator.clipboard.writeText("'.$state.'");'
|
||||
);
|
||||
@ -164,7 +171,7 @@ protected function getHeaderActions(): array
|
||||
)
|
||||
->helperText('Run this command on your server as root user')
|
||||
->disabled()
|
||||
->visible(fn ($get) => $get('provider') === ServerProvider::CUSTOM),
|
||||
->visible(fn ($get): bool => $get('provider') === ServerProvider::CUSTOM),
|
||||
Grid::make()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
@ -175,7 +182,7 @@ protected function getHeaderActions(): array
|
||||
->native(false)
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['os'])
|
||||
->options(
|
||||
collect(config('core.operating_systems'))
|
||||
collect((array) config('core.operating_systems'))
|
||||
->mapWithKeys(fn ($value) => [$value => $value])
|
||||
),
|
||||
]),
|
||||
@ -188,7 +195,7 @@ protected function getHeaderActions(): array
|
||||
->label('SSH Port')
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['port']),
|
||||
])
|
||||
->visible(fn ($get) => $get('provider') === ServerProvider::CUSTOM),
|
||||
->visible(fn ($get): bool => $get('provider') === ServerProvider::CUSTOM),
|
||||
Fieldset::make('Services')
|
||||
->columns(1)
|
||||
->schema([
|
||||
@ -204,7 +211,7 @@ protected function getHeaderActions(): array
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['webserver'] ?? [])
|
||||
->default(Webserver::NONE)
|
||||
->options(
|
||||
collect(config('core.webservers'))->mapWithKeys(fn ($value) => [$value => $value])
|
||||
collect((array) config('core.webservers'))->mapWithKeys(fn ($value) => [$value => $value])
|
||||
),
|
||||
Select::make('database')
|
||||
->label('Database')
|
||||
@ -213,7 +220,7 @@ protected function getHeaderActions(): array
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['database'] ?? [])
|
||||
->default(Database::NONE)
|
||||
->options(
|
||||
collect(config('core.databases_name'))
|
||||
collect((array) config('core.databases_name'))
|
||||
->mapWithKeys(fn ($value, $key) => [
|
||||
$key => $value.' '.config('core.databases_version')[$key],
|
||||
])
|
||||
@ -225,16 +232,16 @@ protected function getHeaderActions(): array
|
||||
->rules(fn ($get) => CreateServerAction::rules($project, $get())['php'] ?? [])
|
||||
->default(PHP::NONE)
|
||||
->options(
|
||||
collect(config('core.php_versions'))
|
||||
collect((array) config('core.php_versions'))
|
||||
->mapWithKeys(fn ($value) => [$value => $value])
|
||||
),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
->modalSubmitActionLabel('Create')
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
$server = app(CreateServerAction::class)->create(auth()->user(), auth()->user()->currentProject, $data);
|
||||
->action(function (array $data) use ($user, $project): void {
|
||||
run_action($this, function () use ($data, $user, $project): void {
|
||||
$server = app(CreateServerAction::class)->create($user, $project, $data);
|
||||
|
||||
$this->redirect(View::getUrl(['server' => $server]));
|
||||
});
|
||||
|
Reference in New Issue
Block a user