Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan workflow + PHPStan fixes #339

Merged
merged 8 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- '**'

jobs:
lint:
name: Lint
pint:
name: Pint
runs-on: ubuntu-latest
steps:
- name: Code Checkout
Expand All @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
php-version: "8.3"
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
tools: composer:v2
coverage: none
Expand All @@ -29,3 +29,26 @@ jobs:

- name: Pint
run: vendor/bin/pint --test
phpstan:
DjordyKoert marked this conversation as resolved.
Show resolved Hide resolved
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
tools: composer:v2
coverage: none

- name: Setup .env
run: cp .env.example .env

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: PHPStan
run: vendor/bin/phpstan --memory-limit=1G
lancepioch marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion app/Filament/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ protected function getHeaderActions(): array

])
->action(function (array $data): void {

/** @var EggImporterService $eggImportService */
$eggImportService = resolve(EggImporterService::class);

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 @@ -395,10 +395,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,7 +3,7 @@
namespace App\Filament\Resources\NodeResource\RelationManagers;

use App\Models\Allocation;
use App\Models\Server;
use App\Models\Node;
use App\Services\Allocations\AssignmentService;
use Filament\Forms;
use Filament\Forms\Form;
Expand All @@ -12,6 +12,9 @@
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;

/**
* @method Node getOwnerRecord()
*/
class AllocationsRelationManager extends RelationManager
{
protected static string $relationship = 'allocations';
Expand Down Expand Up @@ -66,7 +69,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 @@ -425,7 +425,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 @@ -575,6 +574,7 @@ public function form(Form $form): Form
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
default => throw new \LogicException('Invalid state'),
};

$set('swap', $value);
Expand All @@ -594,7 +594,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 @@ -606,7 +608,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 @@ -624,7 +626,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 @@ -634,7 +636,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 @@ -650,7 +652,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
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
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();
lancepioch marked this conversation as resolved.
Show resolved Hide resolved
} 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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"scripts": {
"cs:fix": "php-cs-fixer fix",
"cs:check": "php-cs-fixer fix --dry-run --diff --verbose",
"phpstan": "phpstan --memory-limit=1G",
lancepioch marked this conversation as resolved.
Show resolved Hide resolved
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
Expand Down
Loading