Skip to content

Commit

Permalink
PHPStan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Jun 6, 2024
1 parent d2181f1 commit 4d91352
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getHeaderActions(): array
->multiple(),
])
->action(function (array $data): void {
/** @var TemporaryUploadedFile $eggFile */
/** @var TemporaryUploadedFile[] $eggFile */
$eggFile = $data['egg'];

/** @var EggImporterService $eggImportService */
Expand Down
9 changes: 5 additions & 4 deletions app/Filament/Resources/NodeResource/Pages/EditNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,11 @@ public function form(Forms\Form $form): Forms\Form
->requiresConfirmation()
->modalHeading('Reset Daemon Token?')
->modalDescription('Resetting the daemon token will void any request coming from the old token. This token is used for all sensitive operations on the daemon including server creation and deletion. We suggest changing this token regularly for security.')
->action(fn (NodeUpdateService $nodeUpdateService, Node $node) => $nodeUpdateService->handle($node, [], true)
&& Notification::make()->success()->title('Daemon Key Reset')->send()
&& $this->fillForm()
),
->action(function (NodeUpdateService $nodeUpdateService, Node $node) {
$nodeUpdateService->handle($node, [], true);
Notification::make()->success()->title('Daemon Key Reset')->send();
$this->fillForm();
}),
]),
]),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
namespace App\Filament\Resources\NodeResource\RelationManagers;

use App\Models\Allocation;
use App\Models\Node;
use App\Models\Server;
use App\Services\Allocations\AssignmentService;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;

/**
* @method Node getOwnerRecord()
*/
class AllocationsRelationManager extends RelationManager
{
protected static string $relationship = 'allocations';
Expand Down Expand Up @@ -66,7 +71,7 @@ public function table(Table $table): Table
Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
->form(fn () => [
Forms\Components\TextInput::make('allocation_ip')
->datalist($this->getOwnerRecord()->ipAddresses() ?? [])
->datalist($this->getOwnerRecord()->ipAddresses())
->label('IP Address')
->inlineLabel()
->ipv4()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources\NodeResource\RelationManagers;

use App\Models\Node;
use App\Models\Server;
use Filament\Tables;
use Filament\Tables\Table;
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/ServerResource/Pages/CreateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ public function form(Form $form): Form

$components = [$text, $select];

/** @var Forms\Components\Component $component */
foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
Expand Down Expand Up @@ -549,6 +548,7 @@ public function form(Form $form): Form
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
default => throw new \LogicException('Invalid state'),
};

$set('swap', $value);
Expand All @@ -568,7 +568,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
'disabled', 'unlimited' => true,
'limited' => false,
default => false,
})
->label('Swap Memory')
->default(0)
Expand Down
14 changes: 8 additions & 6 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources\ServerResource\Pages;

use LogicException;
use App\Filament\Resources\ServerResource;
use App\Http\Controllers\Admin\ServersController;
use App\Services\Servers\RandomWordService;
Expand Down Expand Up @@ -299,6 +300,7 @@ public function form(Form $form): Form
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
default => throw new LogicException('Invalid state')
};

$set('swap', $value);
Expand All @@ -308,6 +310,7 @@ public function form(Form $form): Form
$get('swap') > 0 => 'limited',
$get('swap') == 0 => 'disabled',
$get('swap') < 0 => 'unlimited',
default => throw new LogicException('Invalid state')
};
})
->options([
Expand All @@ -325,7 +328,7 @@ public function form(Form $form): Form
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
'disabled', 'unlimited', true => true,
'limited', false => false,
default => false,
})
->label('Swap Memory')->inlineLabel()
->suffix('MiB')
Expand Down Expand Up @@ -553,7 +556,6 @@ public function form(Form $form): Form

$components = [$text, $select];

/** @var Forms\Components\Component $component */
foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
Expand Down Expand Up @@ -605,7 +607,7 @@ public function form(Form $form): Form
->action(function (ServersController $serversController, Server $server) {
$serversController->toggleInstall($server);

return $this->refreshFormData(['status', 'docker']);
$this->refreshFormData(['status', 'docker']);
}),
])->fullWidth(),
Forms\Components\ToggleButtons::make('')
Expand All @@ -623,7 +625,7 @@ public function form(Form $form): Form
$suspensionService->toggle($server, 'suspend');
Notification::make()->success()->title('Server Suspended!')->send();

return $this->refreshFormData(['status', 'docker']);
$this->refreshFormData(['status', 'docker']);
}),
Forms\Components\Actions\Action::make('toggleUnsuspend')
->label('Unsuspend')
Expand All @@ -633,7 +635,7 @@ public function form(Form $form): Form
$suspensionService->toggle($server, 'unsuspend');
Notification::make()->success()->title('Server Unsuspended!')->send();

return $this->refreshFormData(['status', 'docker']);
$this->refreshFormData(['status', 'docker']);
}),
])->fullWidth(),
Forms\Components\ToggleButtons::make('')
Expand All @@ -649,7 +651,7 @@ public function form(Form $form): Form
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('transfer')
->label('Transfer Soon™')
->action(fn (TransferServerService $transfer, Server $server) => $transfer->handle($server, $data))
->action(fn (TransferServerService $transfer, Server $server) => $transfer->handle($server, []))
->disabled() //TODO!
->form([ //TODO!
Forms\Components\Select::make('newNode')
Expand Down
8 changes: 1 addition & 7 deletions app/Filament/Resources/ServerResource/Pages/ListServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ public function table(Table $table): Table
Tables\Columns\TextColumn::make('status')
->default('unknown')
->badge()
->default(function (Server $server) {
if ($server->status !== null) {
return $server->status;
}

return $server->retrieveStatus() ?? 'node_fail';
})
->default(fn (Server $server) => $server->status ?? $server->retrieveStatus())
->icon(fn ($state) => match ($state) {
'node_fail' => 'tabler-server-off',
'running' => 'tabler-heartbeat',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace App\Filament\Resources\ServerResource\RelationManagers;

use App\Models\Allocation;
use App\Models\Server;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

/**
* @method Server getOwnerRecord()
*/
class AllocationsRelationManager extends RelationManager
{
protected static string $relationship = 'allocations';
Expand Down Expand Up @@ -38,12 +42,12 @@ public function table(Table $table): Table
Tables\Columns\TextInputColumn::make('ip_alias')->label('Alias'),
Tables\Columns\IconColumn::make('primary')
->icon(fn ($state) => match ($state) {
false => 'tabler-star',
true => 'tabler-star-filled',
default => 'tabler-star',
})
->color(fn ($state) => match ($state) {
false => 'gray',
true => 'warning',
default => 'gray',
})
->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]))
->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
Expand Down
5 changes: 5 additions & 0 deletions app/Filament/Resources/UserResource/Pages/EditProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\HtmlString;
use Illuminate\Validation\Rules\Password;

/**
* @method User getUser()
*/
class EditProfile extends \Filament\Pages\Auth\EditProfile
{
protected function getForms(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public function startTransfer(ServerWriteRequest $request, Server $server): Resp

if ($this->transferServerService->handle($server, $validatedData)) {
// Transfer started
$this->returnNoContent();
} else {
// Node was not viable
return new Response('', Response::HTTP_NOT_ACCEPTABLE);
return $this->returnNoContent();
}

// Node was not viable
return new Response('', Response::HTTP_NOT_ACCEPTABLE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
class UpdateMountRequest extends StoreMountRequest
{
/**
* Apply validation rules to this request. Uses the parent class rules()
* function but passes in the rules for updating rather than creating.
* Apply validation rules to this request.
*/
public function rules(array $rules = null): array
{
/** @var Mount $mount */
$mount = $this->route()->parameter('mount');

return parent::rules(Mount::getRulesForUpdate($mount->id));
return Mount::getRulesForUpdate($mount->id);
}
}
3 changes: 2 additions & 1 deletion app/Models/Allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function getHasAliasAttribute(?string $value): bool
return !is_null($this->ip_alias);
}

public function address(): Attribute
/** @return Attribute<string, never> */
protected function address(): Attribute
{
return Attribute::make(
get: fn () => "$this->ip:$this->port",
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @property int $node_id
* @property string $name
* @property string $description
* @property string|null $status
* @property ServerState|null $status
* @property bool $skip_scripts
* @property int $owner_id
* @property int $memory
Expand Down
6 changes: 3 additions & 3 deletions app/Repositories/Daemon/DaemonServerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function getDetails(): array
Assert::isInstanceOf($this->server, Server::class);

try {
$response = $this->getHttpClient()->get(
return $this->getHttpClient()->get(
sprintf('/api/servers/%s', $this->server->uuid)
)->throw();
)->throw()->json();
} catch (RequestException $exception) {
$cfId = $exception->response->header('Cf-Ray');
$cfCache = $exception->response->header('Cf-Cache-Status');
Expand All @@ -48,7 +48,7 @@ public function getDetails(): array
report($exception);
}

return $response?->json() ?? ['state' => ContainerStatus::Missing->value];
return ['state' => ContainerStatus::Missing->value];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Transformers/Api/Client/ActivityLogTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function properties(ActivityLog $model): object

$properties = $model->properties
->mapWithKeys(function ($value, $key) use ($model) {
if ($key === 'ip' && $model->actor && !$model->actor->is($this->request->user())) {
if ($key === 'ip' && !$model->actor->is($this->request->user())) {
return [$key => '[hidden]'];
}

Expand Down

0 comments on commit 4d91352

Please sign in to comment.