1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 00:52:43 +01:00

php-cs-fixer and phpstan

This commit is contained in:
Matthew Penner 2022-12-14 18:04:16 -07:00
parent 363c4fd49f
commit 7ed2be50fd
No known key found for this signature in database
25 changed files with 102 additions and 109 deletions

View File

@ -15,7 +15,7 @@ class InfoCommand extends Command
/**
* VersionCommand constructor.
*/
public function __construct(private ConfigRepository $config, private SoftwareVersionService $versionService)
public function __construct(private ConfigRepository $config, private SoftwareVersionService $softwareVersionService)
{
parent::__construct();
}
@ -27,9 +27,9 @@ class InfoCommand extends Command
{
$this->output->title('Version Information');
$this->table([], [
['Panel Version', $this->config->get('app.version')],
['Latest Version', $this->versionService->getPanel()],
['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
['Panel Version', $this->softwareVersionService->getCurrentVersion()],
['Latest Version', $this->softwareVersionService->getLatestPanel()],
['Up-to-Date', $this->softwareVersionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
['Unique Identifier', $this->config->get('pterodactyl.service.author')],
], 'compact');

View File

@ -30,7 +30,7 @@ class NodeDeploymentController extends ApplicationApiController
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
->setMemory($data['memory'])
->setDisk($data['disk'])
->handle($request->query('per_page'), $request->query('page')); // @phpstan-ignore-line
->handle($request->query('per_page'), $request->query('page'));
return $this->fractal->collection($nodes)
->transformWith(NodeTransformer::class)

View File

@ -8,6 +8,6 @@ class UpdateDatabaseRequest extends StoreDatabaseRequest
{
public function rules(array $rules = null): array
{
return $rules ?? DatabaseHost::getRulesForUpdate($this->route()->parameter('databaseHost')->id);
return $rules ?? DatabaseHost::getRulesForUpdate($this->route()->parameter('databaseHost'));
}
}

View File

@ -8,7 +8,7 @@ class UpdateLocationRequest extends StoreLocationRequest
{
public function rules(): array
{
$locationId = $this->route()->parameter('location')->id;
$locationId = $this->route()->parameter('location');
return collect(Location::getRulesForUpdate($locationId))->only([
'short',

View File

@ -8,6 +8,6 @@ class UpdateMountRequest extends StoreMountRequest
{
public function rules(array $rules = null): array
{
return $rules ?? Mount::getRulesForUpdate($this->route()->parameter('mount')->id);
return $rules ?? Mount::getRulesForUpdate($this->route()->parameter('mount'));
}
}

View File

@ -8,6 +8,6 @@ class UpdateNestRequest extends StoreNestRequest
{
public function rules(array $rules = null): array
{
return $rules ?? Nest::getRulesForUpdate($this->route()->parameter('nest')->id);
return $rules ?? Nest::getRulesForUpdate($this->route()->parameter('nest'));
}
}

View File

@ -42,10 +42,8 @@ class StoreNodeRequest extends ApplicationApiRequest
/**
* Fields to rename for clarity in the API response.
*
* @return array
*/
public function attributes()
public function attributes(): array
{
return [
'daemon_base' => 'Daemon Base Path',
@ -58,13 +56,8 @@ class StoreNodeRequest extends ApplicationApiRequest
/**
* Change the formatting of some data keys in the validated response data
* to match what the application expects in the services.
*
* @param string|null $key
* @param string|array|null $default
*
* @return mixed
*/
public function validated($key = null, $default = null)
public function validated($key = null, $default = null): array
{
$response = parent::validated();
$response['daemon_base'] = $response['daemon_base'] ?? Node::DEFAULT_DAEMON_BASE;

View File

@ -8,6 +8,6 @@ class UpdateNodeRequest extends StoreNodeRequest
{
public function rules(array $rules = null): array
{
return parent::rules($rules ?? Node::getRulesForUpdate($this->route()->parameter('node')->id));
return parent::rules($rules ?? Node::getRulesForUpdate($this->route()->parameter('node')));
}
}

View File

@ -8,6 +8,6 @@ class UpdateRoleRequest extends StoreRoleRequest
{
public function rules(array $rules = null): array
{
return $rules ?? AdminRole::getRulesForUpdate($this->route()->parameter('role')->id);
return $rules ?? AdminRole::getRulesForUpdate($this->route()->parameter('role'));
}
}

View File

@ -13,7 +13,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
*/
public function rules(): array
{
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
$rules = Server::getRulesForUpdate($this->route()->parameter('server'));
return [
'allocation' => $rules['allocation_id'],

View File

@ -12,7 +12,7 @@ class UpdateServerDetailsRequest extends ServerWriteRequest
*/
public function rules(): array
{
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
$rules = Server::getRulesForUpdate($this->route()->parameter('server'));
return [
'external_id' => $rules['external_id'],

View File

@ -9,7 +9,7 @@ class UpdateServerStartupRequest extends ApplicationApiRequest
{
public function rules(): array
{
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
$rules = Server::getRulesForUpdate($this->route()->parameter('server'));
return [
'startup' => $rules['startup'],

View File

@ -8,6 +8,6 @@ class UpdateUserRequest extends StoreUserRequest
{
public function rules(array $rules = null): array
{
return parent::rules($rules ?? User::getRulesForUpdate($this->route()->parameter('user')->id));
return parent::rules($rules ?? User::getRulesForUpdate($this->route()->parameter('user')));
}
}

View File

@ -11,6 +11,7 @@ use Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException;
class UpdateEmailRequest extends ClientApiRequest
{
/**
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException
*/
public function authorize(): bool

View File

@ -2,6 +2,8 @@
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property string $name
@ -19,15 +21,11 @@ class AdminRole extends Model
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'admin_roles';
/**
* Fields that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
@ -37,8 +35,6 @@ class AdminRole extends Model
/**
* Cast values to correct type.
*
* @var array
*/
protected $casts = [
'sort_id' => 'int',
@ -51,17 +47,12 @@ class AdminRole extends Model
'sort_id' => 'sometimes|numeric',
];
/**
* @var bool
*/
public $timestamps = false;
/**
* Gets the permissions associated with a admin role.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* Gets the permissions associated with an admin role.
*/
public function permissions()
public function permissions(): HasMany
{
return $this->hasMany(Permission::class);
}

View File

@ -2,8 +2,8 @@
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
@ -19,7 +19,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property \Carbon\CarbonImmutable $updated_at
* @property bool $required
* @property Egg $egg
* @property ServerVariable $serverVariable
* @property ServerVariable $serverVariables
* @property string $field_type
*
* The "server_value" variable is only present on the object if you've loaded this model
@ -81,15 +81,18 @@ class EggVariable extends Model
return in_array('required', explode('|', $this->rules));
}
public function egg(): HasOne
/**
* Returns the egg that this variable belongs to.
*/
public function egg(): BelongsTo
{
return $this->hasOne(Egg::class);
return $this->belongsTo(Egg::class);
}
/**
* Return server variables associated with this variable.
*/
public function serverVariable(): HasMany
public function serverVariables(): HasMany
{
return $this->hasMany(ServerVariable::class, 'variable_id');
}

View File

@ -19,8 +19,13 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
* @property string $name
* @property string|null $description
* @property int $location_id
* @property string $fqdn
* @property int|null $database_host_id
* @property string $scheme
* @property string $fqdn
* @property int $listen_port_http
* @property int $listen_port_sftp
* @property int $public_port_http
* @property int $public_port_sftp
* @property bool $behind_proxy
* @property bool $maintenance_mode
* @property int $memory
@ -32,17 +37,16 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
* @property int $upload_size
* @property string $daemon_token_id
* @property string $daemon_token
* @property int $daemonListen
* @property int $daemonSFTP
* @property string $daemonBase
* @property string $daemon_base
* @property int $servers_count
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property Location $location
* @property int[]|\Illuminate\Support\Collection $ports
* @property Mount[]|Collection $mounts
* @property Server[]|Collection $servers
* @property Allocation[]|Collection $allocations
* @property \Pterodactyl\Models\DatabaseHost|null $databaseHost
* @property Location $location
* @property Mount[]|Collection $mounts
* @property int[]|\Illuminate\Support\Collection $ports
* @property Server[]|Collection $servers
*/
class Node extends Model
{
@ -54,6 +58,11 @@ class Node extends Model
*/
public const RESOURCE_NAME = 'node';
/**
* The default location of server files on the Wings instance.
*/
public const DEFAULT_DAEMON_BASE = '/var/lib/pterodactyl/volumes';
public const DAEMON_TOKEN_ID_LENGTH = 16;
public const DAEMON_TOKEN_LENGTH = 64;
@ -72,10 +81,13 @@ class Node extends Model
*/
protected $casts = [
'location_id' => 'integer',
'database_host_id' => 'integer',
'listen_port_http' => 'integer',
'listen_port_sftp' => 'integer',
'public_port_http' => 'integer',
'public_port_sftp' => 'integer',
'memory' => 'integer',
'disk' => 'integer',
'daemonListen' => 'integer',
'daemonSFTP' => 'integer',
'behind_proxy' => 'boolean',
'public' => 'boolean',
'maintenance_mode' => 'boolean',
@ -85,11 +97,11 @@ class Node extends Model
* Fields that are mass assignable.
*/
protected $fillable = [
'public', 'name', 'location_id',
'public', 'name', 'location_id', 'database_host_id',
'listen_port_http', 'listen_port_sftp', 'public_port_http', 'public_port_sftp',
'fqdn', 'scheme', 'behind_proxy',
'memory', 'memory_overallocate', 'disk',
'disk_overallocate', 'upload_size', 'daemonBase',
'daemonSFTP', 'daemonListen',
'disk_overallocate', 'upload_size', 'daemon_base',
'description', 'maintenance_mode',
];
@ -97,17 +109,20 @@ class Node extends Model
'name' => 'required|regex:/^([\w .-]{1,100})$/',
'description' => 'string|nullable',
'location_id' => 'required|exists:locations,id',
'database_host_id' => 'sometimes|nullable|exists:database_hosts,id',
'public' => 'boolean',
'fqdn' => 'required|string',
'listen_port_http' => 'required|numeric|between:1,65535',
'listen_port_sftp' => 'required|numeric|between:1,65535',
'public_port_http' => 'required|numeric|between:1,65535',
'public_port_sftp' => 'required|numeric|between:1,65535',
'scheme' => 'required',
'behind_proxy' => 'boolean',
'memory' => 'required|numeric|min:1',
'memory_overallocate' => 'required|numeric|min:-1',
'disk' => 'required|numeric|min:1',
'disk_overallocate' => 'required|numeric|min:-1',
'daemonBase' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/',
'daemonSFTP' => 'required|numeric|between:1,65535',
'daemonListen' => 'required|numeric|between:1,65535',
'daemon_base' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/',
'maintenance_mode' => 'boolean',
'upload_size' => 'int|between:1,1024',
];
@ -116,13 +131,15 @@ class Node extends Model
* Default values for specific columns that are generally not changed on base installs.
*/
protected $attributes = [
'listen_port_http' => 8080,
'listen_port_sftp' => 2022,
'public_port_http' => 8080,
'public_port_sftp' => 2022,
'public' => true,
'behind_proxy' => false,
'memory_overallocate' => 0,
'disk_overallocate' => 0,
'daemonBase' => '/var/lib/pterodactyl/volumes',
'daemonSFTP' => 2022,
'daemonListen' => 8080,
'daemon_base' => self::DEFAULT_DAEMON_BASE,
'maintenance_mode' => false,
];
@ -146,7 +163,7 @@ class Node extends Model
'token' => Container::getInstance()->make(Encrypter::class)->decrypt($this->daemon_token),
'api' => [
'host' => '0.0.0.0',
'port' => $this->daemonListen,
'port' => $this->listen_port_http,
'ssl' => [
'enabled' => (!$this->behind_proxy && $this->scheme === 'https'),
'cert' => '/etc/letsencrypt/live/' . Str::lower($this->fqdn) . '/fullchain.pem',
@ -155,9 +172,9 @@ class Node extends Model
'upload_limit' => $this->upload_size,
],
'system' => [
'data' => $this->daemonBase,
'data' => $this->daemon_base,
'sftp' => [
'bind_port' => $this->daemonSFTP,
'bind_port' => $this->listen_port_sftp,
],
],
'allowed_mounts' => $this->mounts->pluck('source')->toArray(),
@ -196,9 +213,20 @@ class Node extends Model
return $this->maintenance_mode;
}
public function mounts(): HasManyThrough
/**
* Gets the allocations associated with a node.
*/
public function allocations(): HasMany
{
return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id');
return $this->hasMany(Allocation::class);
}
/**
* Returns the database host associated with a node.
*/
public function databaseHost(): BelongsTo
{
return $this->belongsTo(DatabaseHost::class);
}
/**
@ -209,6 +237,14 @@ class Node extends Model
return $this->belongsTo(Location::class);
}
/**
* Returns a HasManyThrough relationship for all the mounts associated with a node.
*/
public function mounts(): HasManyThrough
{
return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id');
}
/**
* Gets the servers associated with a node.
*/
@ -217,14 +253,6 @@ class Node extends Model
return $this->hasMany(Server::class);
}
/**
* Gets the allocations associated with a node.
*/
public function allocations(): HasMany
{
return $this->hasMany(Allocation::class);
}
public function loadServerSums(): self
{
$this->loadSum('servers as sum_memory', 'memory');

View File

@ -116,7 +116,7 @@ class EggImporterService
'copy_script_from' => null,
]);
$egg = $this->parser->fillFromParsed($egg, $parsed);
$egg = $this->eggParserService->fillFromParsed($egg, $parsed);
$egg->save();
foreach ($parsed['variables'] ?? [] as $variable) {

View File

@ -8,7 +8,6 @@ use Pterodactyl\Models\EggVariable;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
class VariableUpdateService
@ -18,7 +17,7 @@ class VariableUpdateService
/**
* VariableUpdateService constructor.
*/
public function __construct(private EggVariableRepositoryInterface $repository, private ValidationFactory $validator)
public function __construct(private ValidationFactory $validator)
{
}

View File

@ -122,7 +122,7 @@ class SoftwareVersionService
protected function versionData(): array
{
return $this->cache->remember(self::GIT_VERSION_CACHE_KEY, CarbonImmutable::now()->addSeconds(15), function () {
$configVersion = config()->get('app.version');
$configVersion = $this->getCurrentVersion();
if (file_exists(base_path('.git/HEAD'))) {
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));

View File

@ -16,6 +16,7 @@ use Pterodactyl\Models\Location;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Http;
use Pterodactyl\Services\Helpers\SoftwareVersionService;
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
@ -26,7 +27,8 @@ class TelemetryCollectionService
*/
public function __construct(
private DaemonConfigurationRepository $daemonConfigurationRepository,
private SettingsRepository $settingsRepository
private SettingsRepository $settingsRepository,
private SoftwareVersionService $softwareVersionService
) {
}
@ -108,7 +110,7 @@ class TelemetryCollectionService
'id' => $uuid,
'panel' => [
'version' => config('app.version'),
'version' => $this->softwareVersionService->getCurrentVersion(),
'phpVersion' => phpversion(),
'drivers' => [

View File

@ -2,20 +2,12 @@
namespace Pterodactyl\Transformers\Api\Application;
use League\Fractal\Resource\Item;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Models\ServerVariable;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Transformer;
class ServerVariableTransformer extends Transformer
{
/**
* List of resources that can be included.
*/
protected array $availableIncludes = ['parent'];
/**
* Return the resource name for the JSONAPI output.
*/
@ -31,17 +23,4 @@ class ServerVariableTransformer extends Transformer
{
return $model->toArray();
}
/**
* Return the parent service variable data.
*/
public function includeParent(EggVariable $variable): Item|NullResource
{
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
// TODO: what the fuck?
return $this->item($variable->variable, new EggVariableTransformer());
}
}

View File

@ -17,7 +17,7 @@ return new class () extends Migration {
Schema::table('nodes', function (Blueprint $table) {
$table->integer('database_host_id')->nullable()->unsigned()->after('location_id');
$table->index('database_host_id')->nullable();
$table->index('database_host_id');
$table->foreign('database_host_id')->references('id')->on('database_hosts')->onDelete('set null');
});
}
@ -34,7 +34,7 @@ return new class () extends Migration {
Schema::table('database_hosts', function (Blueprint $table) {
$table->integer('node_id')->nullable()->unsigned()->after('max_databases');
$table->index('node_id')->nullable();
$table->index('node_id');
$table->foreign('node_id')->references('id')->on('nodes');
});
}

View File

@ -19,10 +19,10 @@ return new class () extends Migration {
Schema::table('nodes', function (Blueprint $table) {
$table->integer('listen_port_http')->unsigned()->default(8080)->after('fqdn')->change();
$table->integer('listen_port_sftp')->unsigned()->default(2022)->after('listen_port_sftp')->change();
$table->integer('listen_port_sftp')->unsigned()->default(2022)->after('listen_port_http')->change();
$table->integer('public_port_http')->unsigned()->default(8080)->after('listen_port_http');
$table->integer('public_port_sftp')->unsigned()->default(2022)->after('listen_port_sftp');
$table->integer('public_port_http')->unsigned()->default(8080)->after('listen_port_sftp');
$table->integer('public_port_sftp')->unsigned()->default(2022)->after('public_port_http');
});
DB::transaction(function () {

View File

@ -19,9 +19,6 @@ parameters:
# Ignore magic spatie calls
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder::allowed(\w+)\(\)#'
# This should be replaced with resources instead of a magic transformer factory, robots in disguise
- '#Method Pterodactyl\\Http\\Controllers\\Api\\Client\\ClientApiController::getTransformer\(\) should return T#'
excludePaths:
- app/Repositories