PHPStan workflow + PHPStan fixes (#339)

* add PHPStan to workflow

Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
Co-authored-by: Djordy <djordy@lap-0394-djordy-koert.local>
Co-authored-by: Lance Pioch <lancepioch@gmail.com>
This commit is contained in:
Djordy Koert 2024-06-11 21:00:51 +02:00 committed by GitHub
parent e95cd0cd98
commit 1d66d4c320
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 67 additions and 40 deletions

View File

@ -6,8 +6,8 @@ on:
- '**'
jobs:
lint:
name: Lint
pint:
name: Pint
runs-on: ubuntu-latest
steps:
- name: Code Checkout
@ -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
@ -29,3 +29,26 @@ jobs:
- name: Pint
run: vendor/bin/pint --test
phpstan:
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=-1

View File

@ -89,7 +89,6 @@ class ListEggs extends ListRecords
])
->action(function (array $data): void {
/** @var EggImporterService $eggImportService */
$eggImportService = resolve(EggImporterService::class);

View File

@ -395,10 +395,11 @@ class EditNode extends EditRecord
->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();
}),
]),
]),
]),

View File

@ -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;
@ -12,6 +12,9 @@ use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;
/**
* @method Node getOwnerRecord()
*/
class AllocationsRelationManager extends RelationManager
{
protected static string $relationship = 'allocations';
@ -66,7 +69,7 @@ class AllocationsRelationManager extends RelationManager
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()

View File

@ -426,7 +426,6 @@ class CreateServer extends CreateRecord
$components = [$text, $select];
/** @var Forms\Components\Component $component */
foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
@ -576,6 +575,7 @@ class CreateServer extends CreateRecord
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
default => throw new \LogicException('Invalid state'),
};
$set('swap', $value);
@ -595,7 +595,7 @@ class CreateServer extends CreateRecord
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
'disabled', 'unlimited' => true,
'limited' => false,
default => false,
})
->label('Swap Memory')
->default(0)

View File

@ -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;
@ -299,6 +300,7 @@ class EditServer extends EditRecord
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
default => throw new LogicException('Invalid state')
};
$set('swap', $value);
@ -308,6 +310,7 @@ class EditServer extends EditRecord
$get('swap') > 0 => 'limited',
$get('swap') == 0 => 'disabled',
$get('swap') < 0 => 'unlimited',
default => throw new LogicException('Invalid state')
};
})
->options([
@ -325,7 +328,7 @@ class EditServer extends EditRecord
->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')
@ -553,7 +556,6 @@ class EditServer extends EditRecord
$components = [$text, $select];
/** @var Forms\Components\Component $component */
foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
@ -606,7 +608,7 @@ class EditServer extends EditRecord
->action(function (ServersController $serversController, Server $server) {
$serversController->toggleInstall($server);
return $this->refreshFormData(['status', 'docker']);
$this->refreshFormData(['status', 'docker']);
}),
])->fullWidth(),
Forms\Components\ToggleButtons::make('')
@ -624,7 +626,7 @@ class EditServer extends EditRecord
$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')
@ -634,7 +636,7 @@ class EditServer extends EditRecord
$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('')
@ -650,7 +652,7 @@ class EditServer extends EditRecord
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')

View File

@ -22,13 +22,7 @@ class ListServers extends ListRecords
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',

View File

@ -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';
@ -38,12 +42,12 @@ class AllocationsRelationManager extends RelationManager
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)

View File

@ -75,11 +75,11 @@ class ServerManagementController extends ApplicationApiController
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);
}
/**

View File

@ -7,14 +7,13 @@ use App\Models\Mount;
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);
}
}

View File

@ -103,7 +103,8 @@ class Allocation extends Model
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",

View File

@ -26,7 +26,7 @@ use App\Exceptions\Http\Server\ServerStateConflictException;
* @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

View File

@ -25,9 +25,9 @@ class DaemonServerRepository extends DaemonRepository
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');
@ -48,7 +48,7 @@ class DaemonServerRepository extends DaemonRepository
report($exception);
}
return $response?->json() ?? ['state' => ContainerStatus::Missing->value];
return ['state' => ContainerStatus::Missing->value];
}
/**

View File

@ -55,7 +55,7 @@ class ActivityLogTransformer extends BaseClientTransformer
$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]'];
}

View File

@ -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=-1",
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],