mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 04:04:45 +02:00
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:
parent
e95cd0cd98
commit
1d66d4c320
29
.github/workflows/lint.yaml
vendored
29
.github/workflows/lint.yaml
vendored
@ -6,8 +6,8 @@ on:
|
|||||||
- '**'
|
- '**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
pint:
|
||||||
name: Lint
|
name: Pint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Code Checkout
|
- name: Code Checkout
|
||||||
@ -16,7 +16,7 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: "8.2"
|
php-version: "8.3"
|
||||||
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
|
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
coverage: none
|
coverage: none
|
||||||
@ -29,3 +29,26 @@ jobs:
|
|||||||
|
|
||||||
- name: Pint
|
- name: Pint
|
||||||
run: vendor/bin/pint --test
|
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
|
||||||
|
@ -89,7 +89,6 @@ class ListEggs extends ListRecords
|
|||||||
|
|
||||||
])
|
])
|
||||||
->action(function (array $data): void {
|
->action(function (array $data): void {
|
||||||
|
|
||||||
/** @var EggImporterService $eggImportService */
|
/** @var EggImporterService $eggImportService */
|
||||||
$eggImportService = resolve(EggImporterService::class);
|
$eggImportService = resolve(EggImporterService::class);
|
||||||
|
|
||||||
|
@ -395,10 +395,11 @@ class EditNode extends EditRecord
|
|||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->modalHeading('Reset Daemon Token?')
|
->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.')
|
->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)
|
->action(function (NodeUpdateService $nodeUpdateService, Node $node) {
|
||||||
&& Notification::make()->success()->title('Daemon Key Reset')->send()
|
$nodeUpdateService->handle($node, [], true);
|
||||||
&& $this->fillForm()
|
Notification::make()->success()->title('Daemon Key Reset')->send();
|
||||||
),
|
$this->fillForm();
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace App\Filament\Resources\NodeResource\RelationManagers;
|
namespace App\Filament\Resources\NodeResource\RelationManagers;
|
||||||
|
|
||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
use App\Models\Server;
|
use App\Models\Node;
|
||||||
use App\Services\Allocations\AssignmentService;
|
use App\Services\Allocations\AssignmentService;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@ -12,6 +12,9 @@ use Filament\Tables;
|
|||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Support\HtmlString;
|
use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Node getOwnerRecord()
|
||||||
|
*/
|
||||||
class AllocationsRelationManager extends RelationManager
|
class AllocationsRelationManager extends RelationManager
|
||||||
{
|
{
|
||||||
protected static string $relationship = 'allocations';
|
protected static string $relationship = 'allocations';
|
||||||
@ -66,7 +69,7 @@ class AllocationsRelationManager extends RelationManager
|
|||||||
Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
|
Tables\Actions\Action::make('create new allocation')->label('Create Allocations')
|
||||||
->form(fn () => [
|
->form(fn () => [
|
||||||
Forms\Components\TextInput::make('allocation_ip')
|
Forms\Components\TextInput::make('allocation_ip')
|
||||||
->datalist($this->getOwnerRecord()->ipAddresses() ?? [])
|
->datalist($this->getOwnerRecord()->ipAddresses())
|
||||||
->label('IP Address')
|
->label('IP Address')
|
||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->ipv4()
|
->ipv4()
|
||||||
|
@ -426,7 +426,6 @@ class CreateServer extends CreateRecord
|
|||||||
|
|
||||||
$components = [$text, $select];
|
$components = [$text, $select];
|
||||||
|
|
||||||
/** @var Forms\Components\Component $component */
|
|
||||||
foreach ($components as &$component) {
|
foreach ($components as &$component) {
|
||||||
$component = $component
|
$component = $component
|
||||||
->live(onBlur: true)
|
->live(onBlur: true)
|
||||||
@ -576,6 +575,7 @@ class CreateServer extends CreateRecord
|
|||||||
'unlimited' => -1,
|
'unlimited' => -1,
|
||||||
'disabled' => 0,
|
'disabled' => 0,
|
||||||
'limited' => 128,
|
'limited' => 128,
|
||||||
|
default => throw new \LogicException('Invalid state'),
|
||||||
};
|
};
|
||||||
|
|
||||||
$set('swap', $value);
|
$set('swap', $value);
|
||||||
@ -595,7 +595,7 @@ class CreateServer extends CreateRecord
|
|||||||
->dehydratedWhenHidden()
|
->dehydratedWhenHidden()
|
||||||
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
|
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
|
||||||
'disabled', 'unlimited' => true,
|
'disabled', 'unlimited' => true,
|
||||||
'limited' => false,
|
default => false,
|
||||||
})
|
})
|
||||||
->label('Swap Memory')
|
->label('Swap Memory')
|
||||||
->default(0)
|
->default(0)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\ServerResource\Pages;
|
namespace App\Filament\Resources\ServerResource\Pages;
|
||||||
|
|
||||||
|
use LogicException;
|
||||||
use App\Filament\Resources\ServerResource;
|
use App\Filament\Resources\ServerResource;
|
||||||
use App\Http\Controllers\Admin\ServersController;
|
use App\Http\Controllers\Admin\ServersController;
|
||||||
use App\Services\Servers\RandomWordService;
|
use App\Services\Servers\RandomWordService;
|
||||||
@ -299,6 +300,7 @@ class EditServer extends EditRecord
|
|||||||
'unlimited' => -1,
|
'unlimited' => -1,
|
||||||
'disabled' => 0,
|
'disabled' => 0,
|
||||||
'limited' => 128,
|
'limited' => 128,
|
||||||
|
default => throw new LogicException('Invalid state')
|
||||||
};
|
};
|
||||||
|
|
||||||
$set('swap', $value);
|
$set('swap', $value);
|
||||||
@ -308,6 +310,7 @@ class EditServer extends EditRecord
|
|||||||
$get('swap') > 0 => 'limited',
|
$get('swap') > 0 => 'limited',
|
||||||
$get('swap') == 0 => 'disabled',
|
$get('swap') == 0 => 'disabled',
|
||||||
$get('swap') < 0 => 'unlimited',
|
$get('swap') < 0 => 'unlimited',
|
||||||
|
default => throw new LogicException('Invalid state')
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
->options([
|
->options([
|
||||||
@ -325,7 +328,7 @@ class EditServer extends EditRecord
|
|||||||
->dehydratedWhenHidden()
|
->dehydratedWhenHidden()
|
||||||
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
|
->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
|
||||||
'disabled', 'unlimited', true => true,
|
'disabled', 'unlimited', true => true,
|
||||||
'limited', false => false,
|
default => false,
|
||||||
})
|
})
|
||||||
->label('Swap Memory')->inlineLabel()
|
->label('Swap Memory')->inlineLabel()
|
||||||
->suffix('MiB')
|
->suffix('MiB')
|
||||||
@ -553,7 +556,6 @@ class EditServer extends EditRecord
|
|||||||
|
|
||||||
$components = [$text, $select];
|
$components = [$text, $select];
|
||||||
|
|
||||||
/** @var Forms\Components\Component $component */
|
|
||||||
foreach ($components as &$component) {
|
foreach ($components as &$component) {
|
||||||
$component = $component
|
$component = $component
|
||||||
->live(onBlur: true)
|
->live(onBlur: true)
|
||||||
@ -606,7 +608,7 @@ class EditServer extends EditRecord
|
|||||||
->action(function (ServersController $serversController, Server $server) {
|
->action(function (ServersController $serversController, Server $server) {
|
||||||
$serversController->toggleInstall($server);
|
$serversController->toggleInstall($server);
|
||||||
|
|
||||||
return $this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
}),
|
}),
|
||||||
])->fullWidth(),
|
])->fullWidth(),
|
||||||
Forms\Components\ToggleButtons::make('')
|
Forms\Components\ToggleButtons::make('')
|
||||||
@ -624,7 +626,7 @@ class EditServer extends EditRecord
|
|||||||
$suspensionService->toggle($server, 'suspend');
|
$suspensionService->toggle($server, 'suspend');
|
||||||
Notification::make()->success()->title('Server Suspended!')->send();
|
Notification::make()->success()->title('Server Suspended!')->send();
|
||||||
|
|
||||||
return $this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
}),
|
}),
|
||||||
Forms\Components\Actions\Action::make('toggleUnsuspend')
|
Forms\Components\Actions\Action::make('toggleUnsuspend')
|
||||||
->label('Unsuspend')
|
->label('Unsuspend')
|
||||||
@ -634,7 +636,7 @@ class EditServer extends EditRecord
|
|||||||
$suspensionService->toggle($server, 'unsuspend');
|
$suspensionService->toggle($server, 'unsuspend');
|
||||||
Notification::make()->success()->title('Server Unsuspended!')->send();
|
Notification::make()->success()->title('Server Unsuspended!')->send();
|
||||||
|
|
||||||
return $this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
}),
|
}),
|
||||||
])->fullWidth(),
|
])->fullWidth(),
|
||||||
Forms\Components\ToggleButtons::make('')
|
Forms\Components\ToggleButtons::make('')
|
||||||
@ -650,7 +652,7 @@ class EditServer extends EditRecord
|
|||||||
Forms\Components\Actions::make([
|
Forms\Components\Actions::make([
|
||||||
Forms\Components\Actions\Action::make('transfer')
|
Forms\Components\Actions\Action::make('transfer')
|
||||||
->label('Transfer Soon™')
|
->label('Transfer Soon™')
|
||||||
->action(fn (TransferServerService $transfer, Server $server) => $transfer->handle($server, $data))
|
->action(fn (TransferServerService $transfer, Server $server) => $transfer->handle($server, []))
|
||||||
->disabled() //TODO!
|
->disabled() //TODO!
|
||||||
->form([ //TODO!
|
->form([ //TODO!
|
||||||
Forms\Components\Select::make('newNode')
|
Forms\Components\Select::make('newNode')
|
||||||
|
@ -22,13 +22,7 @@ class ListServers extends ListRecords
|
|||||||
Tables\Columns\TextColumn::make('status')
|
Tables\Columns\TextColumn::make('status')
|
||||||
->default('unknown')
|
->default('unknown')
|
||||||
->badge()
|
->badge()
|
||||||
->default(function (Server $server) {
|
->default(fn (Server $server) => $server->status ?? $server->retrieveStatus())
|
||||||
if ($server->status !== null) {
|
|
||||||
return $server->status;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $server->retrieveStatus() ?? 'node_fail';
|
|
||||||
})
|
|
||||||
->icon(fn ($state) => match ($state) {
|
->icon(fn ($state) => match ($state) {
|
||||||
'node_fail' => 'tabler-server-off',
|
'node_fail' => 'tabler-server-off',
|
||||||
'running' => 'tabler-heartbeat',
|
'running' => 'tabler-heartbeat',
|
||||||
|
@ -3,12 +3,16 @@
|
|||||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||||
|
|
||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
|
use App\Models\Server;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\RelationManagers\RelationManager;
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Server getOwnerRecord()
|
||||||
|
*/
|
||||||
class AllocationsRelationManager extends RelationManager
|
class AllocationsRelationManager extends RelationManager
|
||||||
{
|
{
|
||||||
protected static string $relationship = 'allocations';
|
protected static string $relationship = 'allocations';
|
||||||
@ -38,12 +42,12 @@ class AllocationsRelationManager extends RelationManager
|
|||||||
Tables\Columns\TextInputColumn::make('ip_alias')->label('Alias'),
|
Tables\Columns\TextInputColumn::make('ip_alias')->label('Alias'),
|
||||||
Tables\Columns\IconColumn::make('primary')
|
Tables\Columns\IconColumn::make('primary')
|
||||||
->icon(fn ($state) => match ($state) {
|
->icon(fn ($state) => match ($state) {
|
||||||
false => 'tabler-star',
|
|
||||||
true => 'tabler-star-filled',
|
true => 'tabler-star-filled',
|
||||||
|
default => 'tabler-star',
|
||||||
})
|
})
|
||||||
->color(fn ($state) => match ($state) {
|
->color(fn ($state) => match ($state) {
|
||||||
false => 'gray',
|
|
||||||
true => 'warning',
|
true => 'warning',
|
||||||
|
default => 'gray',
|
||||||
})
|
})
|
||||||
->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]))
|
->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]))
|
||||||
->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
|
->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id)
|
||||||
|
@ -75,11 +75,11 @@ class ServerManagementController extends ApplicationApiController
|
|||||||
|
|
||||||
if ($this->transferServerService->handle($server, $validatedData)) {
|
if ($this->transferServerService->handle($server, $validatedData)) {
|
||||||
// Transfer started
|
// Transfer started
|
||||||
$this->returnNoContent();
|
return $this->returnNoContent();
|
||||||
} else {
|
|
||||||
// Node was not viable
|
|
||||||
return new Response('', Response::HTTP_NOT_ACCEPTABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node was not viable
|
||||||
|
return new Response('', Response::HTTP_NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,14 +7,13 @@ use App\Models\Mount;
|
|||||||
class UpdateMountRequest extends StoreMountRequest
|
class UpdateMountRequest extends StoreMountRequest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Apply validation rules to this request. Uses the parent class rules()
|
* Apply validation rules to this request.
|
||||||
* function but passes in the rules for updating rather than creating.
|
|
||||||
*/
|
*/
|
||||||
public function rules(array $rules = null): array
|
public function rules(array $rules = null): array
|
||||||
{
|
{
|
||||||
/** @var Mount $mount */
|
/** @var Mount $mount */
|
||||||
$mount = $this->route()->parameter('mount');
|
$mount = $this->route()->parameter('mount');
|
||||||
|
|
||||||
return parent::rules(Mount::getRulesForUpdate($mount->id));
|
return Mount::getRulesForUpdate($mount->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,8 @@ class Allocation extends Model
|
|||||||
return !is_null($this->ip_alias);
|
return !is_null($this->ip_alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function address(): Attribute
|
/** @return Attribute<string, never> */
|
||||||
|
protected function address(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => "$this->ip:$this->port",
|
get: fn () => "$this->ip:$this->port",
|
||||||
|
@ -26,7 +26,7 @@ use App\Exceptions\Http\Server\ServerStateConflictException;
|
|||||||
* @property int $node_id
|
* @property int $node_id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $description
|
* @property string $description
|
||||||
* @property string|null $status
|
* @property ServerState|null $status
|
||||||
* @property bool $skip_scripts
|
* @property bool $skip_scripts
|
||||||
* @property int $owner_id
|
* @property int $owner_id
|
||||||
* @property int $memory
|
* @property int $memory
|
||||||
|
@ -25,9 +25,9 @@ class DaemonServerRepository extends DaemonRepository
|
|||||||
Assert::isInstanceOf($this->server, Server::class);
|
Assert::isInstanceOf($this->server, Server::class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->getHttpClient()->get(
|
return $this->getHttpClient()->get(
|
||||||
sprintf('/api/servers/%s', $this->server->uuid)
|
sprintf('/api/servers/%s', $this->server->uuid)
|
||||||
)->throw();
|
)->throw()->json();
|
||||||
} catch (RequestException $exception) {
|
} catch (RequestException $exception) {
|
||||||
$cfId = $exception->response->header('Cf-Ray');
|
$cfId = $exception->response->header('Cf-Ray');
|
||||||
$cfCache = $exception->response->header('Cf-Cache-Status');
|
$cfCache = $exception->response->header('Cf-Cache-Status');
|
||||||
@ -48,7 +48,7 @@ class DaemonServerRepository extends DaemonRepository
|
|||||||
report($exception);
|
report($exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response?->json() ?? ['state' => ContainerStatus::Missing->value];
|
return ['state' => ContainerStatus::Missing->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +55,7 @@ class ActivityLogTransformer extends BaseClientTransformer
|
|||||||
|
|
||||||
$properties = $model->properties
|
$properties = $model->properties
|
||||||
->mapWithKeys(function ($value, $key) use ($model) {
|
->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]'];
|
return [$key => '[hidden]'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"cs:fix": "php-cs-fixer fix",
|
"cs:fix": "php-cs-fixer fix",
|
||||||
"cs:check": "php-cs-fixer fix --dry-run --diff --verbose",
|
"cs:check": "php-cs-fixer fix --dry-run --diff --verbose",
|
||||||
|
"phpstan": "phpstan --memory-limit=-1",
|
||||||
"post-autoload-dump": [
|
"post-autoload-dump": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
|
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user