chore: add phpstan static analysis minimum (#4511)
This commit is contained in:
parent
3f7e2a565f
commit
a1a52754ad
67 changed files with 561 additions and 279 deletions
|
@ -40,23 +40,24 @@ class AssignmentService
|
|||
*/
|
||||
public function handle(Node $node, array $data): void
|
||||
{
|
||||
$explode = explode('/', $data['allocation_ip']);
|
||||
$allocationIp = $data['allocation_ip'];
|
||||
$explode = explode('/', $allocationIp);
|
||||
if (count($explode) !== 1) {
|
||||
if (!ctype_digit($explode[1]) || ($explode[1] > self::CIDR_MIN_BITS || $explode[1] < self::CIDR_MAX_BITS)) {
|
||||
throw new CidrOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
$underlying = 'Unknown IP';
|
||||
try {
|
||||
// TODO: how should we approach supporting IPv6 with this?
|
||||
// gethostbyname only supports IPv4, but the alternative (dns_get_record) returns
|
||||
// an array of records, which is not ideal for this use case, we need a SINGLE
|
||||
// IP to use, not multiple.
|
||||
$underlying = gethostbyname($data['allocation_ip']);
|
||||
$underlying = gethostbyname($allocationIp);
|
||||
$parsed = Network::parse($underlying);
|
||||
} catch (Exception $exception) {
|
||||
/* @noinspection PhpUndefinedVariableInspection */
|
||||
throw new DisplayException("Could not parse provided allocation IP address ({$underlying}): {$exception->getMessage()}", $exception);
|
||||
throw new DisplayException("Could not parse provided allocation IP address for $allocationIp ($underlying): {$exception->getMessage()}", $exception);
|
||||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
|
|
|
@ -73,7 +73,10 @@ class DeleteBackupService
|
|||
/** @var \Pterodactyl\Extensions\Filesystem\S3Filesystem $adapter */
|
||||
$adapter = $this->manager->adapter(Backup::ADAPTER_AWS_S3);
|
||||
|
||||
$adapter->getClient()->deleteObject([
|
||||
/** @var \Aws\S3\S3Client $client */
|
||||
$client = $adapter->getClient();
|
||||
|
||||
$client->deleteObject([
|
||||
'Bucket' => $adapter->getBucket(),
|
||||
'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid),
|
||||
]);
|
||||
|
|
|
@ -98,17 +98,17 @@ class InitiateBackupService
|
|||
// Get the oldest backup the server has that is not "locked" (indicating a backup that should
|
||||
// never be automatically purged). If we find a backup we will delete it and then continue with
|
||||
// this process. If no backup is found that can be used an exception is thrown.
|
||||
/** @var \Pterodactyl\Models\Backup $oldest */
|
||||
$oldest = $successful->where('is_locked', false)->orderBy('created_at')->first();
|
||||
if (!$oldest) {
|
||||
throw new TooManyBackupsException($server->backup_limit);
|
||||
}
|
||||
|
||||
/* @var Backup $oldest */
|
||||
$this->deleteBackupService->handle($oldest);
|
||||
}
|
||||
|
||||
return $this->connection->transaction(function () use ($server, $name) {
|
||||
/** @var \Pterodactyl\Models\Backup $backup */
|
||||
/** @var Backup $backup */
|
||||
$backup = $this->repository->create([
|
||||
'server_id' => $server->id,
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
|
|
|
@ -119,6 +119,7 @@ class DatabaseManagementService
|
|||
});
|
||||
} catch (Exception $exception) {
|
||||
try {
|
||||
/** @var ?Database $database */
|
||||
if ($database instanceof Database) {
|
||||
$this->repository->dropDatabase($database->database);
|
||||
$this->repository->dropUser($database->username, $database->remote);
|
||||
|
|
|
@ -78,7 +78,7 @@ class FindViableNodesService
|
|||
->where('nodes.public', 1);
|
||||
|
||||
if (!empty($this->locations)) {
|
||||
$query = $query->whereIn('nodes.location_id', $this->locations);
|
||||
$query = $query->whereIn('location_id', $this->locations);
|
||||
}
|
||||
|
||||
$results = $query->groupBy('nodes.id')
|
||||
|
|
|
@ -27,13 +27,13 @@ class ProcessScheduleService
|
|||
*/
|
||||
public function handle(Schedule $schedule, bool $now = false): void
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Task $task */
|
||||
$task = $schedule->tasks()->orderBy('sequence_id')->first();
|
||||
|
||||
if (is_null($task)) {
|
||||
throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.');
|
||||
}
|
||||
|
||||
/* @var \Pterodactyl\Models\Task $task */
|
||||
$this->connection->transaction(function () use ($schedule, $task) {
|
||||
$schedule->forceFill([
|
||||
'is_processing' => true,
|
||||
|
|
|
@ -88,14 +88,13 @@ class BuildModificationService
|
|||
// Handle the addition of allocations to this server. Only assign allocations that are not currently
|
||||
// assigned to a different server, and only allocations on the same node as the server.
|
||||
if (!empty($data['add_allocations'])) {
|
||||
$query = Allocation::query()
|
||||
->where('node_id', $server->node_id)
|
||||
$query = $server->node->allocations()
|
||||
->whereIn('id', $data['add_allocations'])
|
||||
->whereNull('server_id');
|
||||
|
||||
// Keep track of all the allocations we're just now adding so that we can use the first
|
||||
// one to reset the default allocation to.
|
||||
$freshlyAllocated = $query->pluck('id')->first();
|
||||
$freshlyAllocated = $query->first()->id ?? null;
|
||||
|
||||
$query->update(['server_id' => $server->id, 'notes' => null]);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class ServerCreationService
|
|||
//
|
||||
// If that connection fails out we will attempt to perform a cleanup by just
|
||||
// deleting the server itself from the system.
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
/** @var Server $server */
|
||||
$server = $this->connection->transaction(function () use ($data, $eggVariableData) {
|
||||
// Create the server and assign any additional allocations to it.
|
||||
$server = $this->createModel($data);
|
||||
|
@ -115,7 +115,7 @@ class ServerCreationService
|
|||
*/
|
||||
private function configureDeployment(array $data, DeploymentObject $deployment): Allocation
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection $nodes */
|
||||
/** @var Collection $nodes */
|
||||
$nodes = $this->findViableNodesService->setLocations($deployment->getLocations())
|
||||
->setDisk(Arr::get($data, 'disk'))
|
||||
->setMemory(Arr::get($data, 'memory'))
|
||||
|
@ -136,7 +136,7 @@ class ServerCreationService
|
|||
{
|
||||
$uuid = $this->generateUniqueUuidCombo();
|
||||
|
||||
/** @var \Pterodactyl\Models\Server $model */
|
||||
/** @var Server $model */
|
||||
$model = $this->repository->create([
|
||||
'external_id' => Arr::get($data, 'external_id'),
|
||||
'uuid' => $uuid,
|
||||
|
|
|
@ -25,7 +25,7 @@ class UserDeletionService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function handle(int|User $user): ?bool
|
||||
public function handle(int|User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$user = $user->id;
|
||||
|
@ -36,6 +36,6 @@ class UserDeletionService
|
|||
throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($user);
|
||||
$this->repository->delete($user);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue