Use more standardized phpcs

This commit is contained in:
Dane Everitt 2021-01-23 12:33:34 -08:00
parent a043071e3c
commit c449ca5155
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
493 changed files with 1116 additions and 3903 deletions

View file

@ -11,35 +11,33 @@ class AdminAcl
* Resource permission columns in the api_keys table begin
* with this identifier.
*/
const COLUMN_IDENTIFIER = 'r_';
public const COLUMN_IDENTIFIER = 'r_';
/**
* The different types of permissions available for API keys. This
* implements a read/write/none permissions scheme for all endpoints.
*/
const NONE = 0;
const READ = 1;
const WRITE = 2;
public const NONE = 0;
public const READ = 1;
public const WRITE = 2;
/**
* Resources that are available on the API and can contain a permissions
* set for each key. These are stored in the database as r_{resource}.
*/
const RESOURCE_SERVERS = 'servers';
const RESOURCE_NODES = 'nodes';
const RESOURCE_ALLOCATIONS = 'allocations';
const RESOURCE_USERS = 'users';
const RESOURCE_LOCATIONS = 'locations';
const RESOURCE_NESTS = 'nests';
const RESOURCE_EGGS = 'eggs';
const RESOURCE_DATABASE_HOSTS = 'database_hosts';
const RESOURCE_SERVER_DATABASES = 'server_databases';
public const RESOURCE_SERVERS = 'servers';
public const RESOURCE_NODES = 'nodes';
public const RESOURCE_ALLOCATIONS = 'allocations';
public const RESOURCE_USERS = 'users';
public const RESOURCE_LOCATIONS = 'locations';
public const RESOURCE_NESTS = 'nests';
public const RESOURCE_EGGS = 'eggs';
public const RESOURCE_DATABASE_HOSTS = 'database_hosts';
public const RESOURCE_SERVER_DATABASES = 'server_databases';
/**
* Determine if an API key has permission to perform a specific read/write operation.
*
* @param int $permission
* @param int $action
* @return bool
*/
public static function can(int $permission, int $action = self::READ)
@ -55,9 +53,6 @@ class AdminAcl
* Determine if an API Key model has permission to access a given resource
* at a specific action level.
*
* @param \Pterodactyl\Models\ApiKey $key
* @param string $resource
* @param int $action
* @return bool
*/
public static function check(ApiKey $key, string $resource, int $action = self::READ)
@ -68,7 +63,6 @@ class AdminAcl
/**
* Return a list of all resource constants defined in this ACL.
*
* @return array
* @throws \ReflectionException
*/
public static function getResourceList(): array

View file

@ -15,8 +15,6 @@ class AllocationDeletionService
/**
* AllocationDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
*/
public function __construct(AllocationRepositoryInterface $repository)
{
@ -27,14 +25,13 @@ class AllocationDeletionService
* Delete an allocation from the database only if it does not have a server
* that is actively attached to it.
*
* @param \Pterodactyl\Models\Allocation $allocation
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function handle(Allocation $allocation)
{
if (! is_null($allocation->server_id)) {
if (!is_null($allocation->server_id)) {
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
}

View file

@ -13,12 +13,12 @@ use Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException;
class AssignmentService
{
const CIDR_MAX_BITS = 27;
const CIDR_MIN_BITS = 32;
const PORT_FLOOR = 1024;
const PORT_CEIL = 65535;
const PORT_RANGE_LIMIT = 1000;
const PORT_RANGE_REGEX = '/^(\d{4,5})-(\d{4,5})$/';
public const CIDR_MAX_BITS = 27;
public const CIDR_MIN_BITS = 32;
public const PORT_FLOOR = 1024;
public const PORT_CEIL = 65535;
public const PORT_RANGE_LIMIT = 1000;
public const PORT_RANGE_REGEX = '/^(\d{4,5})-(\d{4,5})$/';
/**
* @var \Illuminate\Database\ConnectionInterface
@ -32,9 +32,6 @@ class AssignmentService
/**
* AssignmentService constructor.
*
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
* @param \Illuminate\Database\ConnectionInterface $connection
*/
public function __construct(AllocationRepositoryInterface $repository, ConnectionInterface $connection)
{
@ -45,9 +42,6 @@ class AssignmentService
/**
* Insert allocations into the database and link them to a specific node.
*
* @param \Pterodactyl\Models\Node $node
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
@ -57,15 +51,15 @@ class AssignmentService
{
$explode = explode('/', $data['allocation_ip']);
if (count($explode) !== 1) {
if (! ctype_digit($explode[1]) || ($explode[1] > self::CIDR_MIN_BITS || $explode[1] < self::CIDR_MAX_BITS)) {
throw new CidrOutOfRangeException;
if (!ctype_digit($explode[1]) || ($explode[1] > self::CIDR_MIN_BITS || $explode[1] < self::CIDR_MAX_BITS)) {
throw new CidrOutOfRangeException();
}
}
$this->connection->beginTransaction();
foreach (Network::parse(gethostbyname($data['allocation_ip'])) as $ip) {
foreach ($data['allocation_ports'] as $port) {
if (! is_digit($port) && ! preg_match(self::PORT_RANGE_REGEX, $port)) {
if (!is_digit($port) && !preg_match(self::PORT_RANGE_REGEX, $port)) {
throw new InvalidPortMappingException($port);
}
@ -74,11 +68,11 @@ class AssignmentService
$block = range($matches[1], $matches[2]);
if (count($block) > self::PORT_RANGE_LIMIT) {
throw new TooManyPortsInRangeException;
throw new TooManyPortsInRangeException();
}
if ((int) $matches[1] <= self::PORT_FLOOR || (int) $matches[2] > self::PORT_CEIL) {
throw new PortOutOfRangeException;
throw new PortOutOfRangeException();
}
foreach ($block as $unit) {
@ -92,7 +86,7 @@ class AssignmentService
}
} else {
if ((int) $port <= self::PORT_FLOOR || (int) $port > self::PORT_CEIL) {
throw new PortOutOfRangeException;
throw new PortOutOfRangeException();
}
$insertData[] = [

View file

@ -30,7 +30,6 @@ class FindAssignableAllocationService
* no allocation can be found, a new one will be created with a random port between the defined
* range from the configuration.
*
* @param \Pterodactyl\Models\Server $server
* @return \Pterodactyl\Models\Allocation
*
* @throws \Pterodactyl\Exceptions\DisplayException
@ -41,8 +40,8 @@ class FindAssignableAllocationService
*/
public function handle(Server $server)
{
if (! config('pterodactyl.client_features.allocations.enabled')) {
throw new AutoAllocationNotEnabledException;
if (!config('pterodactyl.client_features.allocations.enabled')) {
throw new AutoAllocationNotEnabledException();
}
// Attempt to find a given available allocation for a server. If one cannot be found
@ -67,9 +66,6 @@ class FindAssignableAllocationService
* in the settings. If there are no matches in that range, or something is wrong with the
* range information provided an exception will be raised.
*
* @param \Pterodactyl\Models\Server $server
* @return \Pterodactyl\Models\Allocation
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
@ -81,8 +77,8 @@ class FindAssignableAllocationService
$start = config('pterodactyl.client_features.allocations.range_start', null);
$end = config('pterodactyl.client_features.allocations.range_end', null);
if (! $start || ! $end) {
throw new NoAutoAllocationSpaceAvailableException;
if (!$start || !$end) {
throw new NoAutoAllocationSpaceAvailableException();
}
Assert::integerish($start);
@ -102,7 +98,7 @@ class FindAssignableAllocationService
// If we've already allocated all of the ports, just abort.
if (empty($available)) {
throw new NoAutoAllocationSpaceAvailableException;
throw new NoAutoAllocationSpaceAvailableException();
}
// Pick a random port out of the remaining available ports.

View file

@ -25,9 +25,6 @@ class KeyCreationService
/**
* ApiKeyService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface $repository
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(ApiKeyRepositoryInterface $repository, Encrypter $encrypter)
{
@ -39,7 +36,6 @@ class KeyCreationService
* Set the type of key that should be created. By default an orphaned key will be
* created. These keys cannot be used for anything, and will not render in the UI.
*
* @param int $type
* @return \Pterodactyl\Services\Api\KeyCreationService
*/
public function setKeyType(int $type)
@ -54,10 +50,6 @@ class KeyCreationService
* This will automatically generate an identifier and an encrypted token that are
* stored in the database.
*
* @param array $data
* @param array $permissions
* @return \Pterodactyl\Models\ApiKey
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(array $data, array $permissions = []): ApiKey

View file

@ -35,11 +35,6 @@ class DeleteBackupService
/**
* DeleteBackupService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Pterodactyl\Extensions\Backups\BackupManager $manager
* @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $daemonBackupRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -56,7 +51,6 @@ class DeleteBackupService
/**
* Deletes a backup from the system.
*
* @param \Pterodactyl\Models\Backup $backup
* @throws \Throwable
*/
public function handle(Backup $backup)
@ -74,7 +68,7 @@ class DeleteBackupService
$previous = $exception->getPrevious();
// Don't fail the request if the Daemon responds with a 404, just assume the backup
// doesn't actually exist and remove it's reference from the Panel as well.
if (! $previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
if (!$previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exception;
}
}
@ -86,7 +80,6 @@ class DeleteBackupService
/**
* Deletes a backup from an S3 disk.
*
* @param \Pterodactyl\Models\Backup $backup
* @throws \Throwable
*/
protected function deleteFromS3(Backup $backup)

View file

@ -49,11 +49,7 @@ class InitiateBackupService
/**
* InitiateBackupService constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $daemonBackupRepository
* @param \Pterodactyl\Services\Backups\DeleteBackupService $deleteBackupService
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
*/
public function __construct(
BackupRepository $repository,
@ -73,6 +69,7 @@ class InitiateBackupService
* Sets the files to be ignored by this backup.
*
* @param string[]|null $ignored
*
* @return $this
*/
public function setIgnoredFiles(?array $ignored)
@ -96,12 +93,6 @@ class InitiateBackupService
/**
* Initiates the backup process for a server on the daemon.
*
* @param \Pterodactyl\Models\Server $server
* @param string|null $name
* @param bool $override
*
* @return \Pterodactyl\Models\Backup
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException
* @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
@ -113,17 +104,14 @@ class InitiateBackupService
if ($period > 0) {
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, $period);
if ($previous->count() >= $limit) {
throw new TooManyRequestsHttpException(
CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addSeconds($period)),
sprintf('Only %d backups may be generated within a %d second span of time.', $limit, $period)
);
throw new TooManyRequestsHttpException(CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addSeconds($period)), sprintf('Only %d backups may be generated within a %d second span of time.', $limit, $period));
}
}
// Check if the server has reached or exceeded it's backup limit
if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) {
if (!$server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) {
// Do not allow the user to continue if this server is already at its limit and can't override.
if (! $override || $server->backup_limit <= 0) {
if (!$override || $server->backup_limit <= 0) {
throw new TooManyBackupsException($server->backup_limit);
}

View file

@ -57,11 +57,6 @@ class DatabaseManagementService
/**
* CreationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
* @param \Pterodactyl\Repositories\Eloquent\DatabaseRepository $repository
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(
ConnectionInterface $connection,
@ -79,10 +74,6 @@ class DatabaseManagementService
* Generates a unique database name for the given server. This name should be passed through when
* calling this handle function for this service, otherwise the database will be created with
* whatever name is provided.
*
* @param string $name
* @param int $serverId
* @return string
*/
public static function generateUniqueDatabaseName(string $name, int $serverId): string
{
@ -94,7 +85,6 @@ class DatabaseManagementService
* Set wether or not this class should validate that the server has enough slots
* left before creating the new database.
*
* @param bool $validate
* @return $this
*/
public function setValidateDatabaseLimit(bool $validate): self
@ -107,8 +97,6 @@ class DatabaseManagementService
/**
* Create a new database that is linked to a specific host.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @return \Pterodactyl\Models\Database
*
* @throws \Throwable
@ -117,23 +105,21 @@ class DatabaseManagementService
*/
public function create(Server $server, array $data)
{
if (! config('pterodactyl.client_features.databases.enabled')) {
throw new DatabaseClientFeatureNotEnabledException;
if (!config('pterodactyl.client_features.databases.enabled')) {
throw new DatabaseClientFeatureNotEnabledException();
}
if ($this->validateDatabaseLimit) {
// If the server has a limit assigned and we've already reached that limit, throw back
// an exception and kill the process.
if (! is_null($server->database_limit) && $server->databases()->count() >= $server->database_limit) {
throw new TooManyDatabasesException;
if (!is_null($server->database_limit) && $server->databases()->count() >= $server->database_limit) {
throw new TooManyDatabasesException();
}
}
// Protect against developer mistakes...
if (empty($data['database']) || ! preg_match(self::MATCH_NAME_REGEX, $data['database'])) {
throw new InvalidArgumentException(
'The database name passed to DatabaseManagementService::handle MUST be prefixed with "s{server_id}_".'
);
if (empty($data['database']) || !preg_match(self::MATCH_NAME_REGEX, $data['database'])) {
throw new InvalidArgumentException('The database name passed to DatabaseManagementService::handle MUST be prefixed with "s{server_id}_".');
}
$data = array_merge($data, [
@ -154,7 +140,10 @@ class DatabaseManagementService
$this->repository->createDatabase($database->database);
$this->repository->createUser(
$database->username, $database->remote, $this->encrypter->decrypt($database->password), $database->max_connections
$database->username,
$database->remote,
$this->encrypter->decrypt($database->password),
$database->max_connections
);
$this->repository->assignUserToDatabase($database->database, $database->username, $database->remote);
$this->repository->flush();
@ -180,7 +169,6 @@ class DatabaseManagementService
/**
* Delete a database from the given host server.
*
* @param \Pterodactyl\Models\Database $database
* @return bool|null
*
* @throws \Exception
@ -201,9 +189,6 @@ class DatabaseManagementService
* have the same name across multiple hosts, for the sake of keeping this logic easy to understand
* and avoiding user confusion we will ignore the specific host and just look across all hosts.
*
* @param array $data
* @return \Pterodactyl\Models\Database
*
* @throws \Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException
* @throws \Throwable
*/
@ -214,12 +199,10 @@ class DatabaseManagementService
->exists();
if ($exists) {
throw new DuplicateDatabaseNameException(
'A database with that name already exists for this server.'
);
throw new DuplicateDatabaseNameException('A database with that name already exists for this server.');
}
$database = (new Database)->forceFill($data);
$database = (new Database())->forceFill($data);
$database->saveOrFail();
return $database;

View file

@ -33,11 +33,6 @@ class DatabasePasswordService
/**
* DatabasePasswordService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $repository
* @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(
ConnectionInterface $connection,
@ -55,7 +50,6 @@ class DatabasePasswordService
* Updates a password for a given database.
*
* @param \Pterodactyl\Models\Database|int $database
* @return string
*
* @throws \Throwable
*/

View file

@ -26,10 +26,6 @@ class DeployServerDatabaseService
}
/**
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @return \Pterodactyl\Models\Database
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\Service\Database\TooManyDatabasesException
* @throws \Pterodactyl\Exceptions\Service\Database\DatabaseClientFeatureNotEnabledException
@ -41,12 +37,12 @@ class DeployServerDatabaseService
$hosts = DatabaseHost::query()->get()->toBase();
if ($hosts->isEmpty()) {
throw new NoSuitableDatabaseHostException;
throw new NoSuitableDatabaseHostException();
} else {
$nodeHosts = $hosts->where('node_id', $server->node_id)->toBase();
if ($nodeHosts->isEmpty() && ! config('pterodactyl.client_features.databases.allow_random')) {
throw new NoSuitableDatabaseHostException;
if ($nodeHosts->isEmpty() && !config('pterodactyl.client_features.databases.allow_random')) {
throw new NoSuitableDatabaseHostException();
}
}

View file

@ -38,12 +38,6 @@ class HostCreationService
/**
* HostCreationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\DatabaseManager $databaseManager
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
* @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(
ConnectionInterface $connection,
@ -62,9 +56,6 @@ class HostCreationService
/**
* Create a new database host on the Panel.
*
* @param array $data
* @return \Pterodactyl\Models\DatabaseHost
*
* @throws \Throwable
*/
public function handle(array $data): DatabaseHost

View file

@ -20,9 +20,6 @@ class HostDeletionService
/**
* HostDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
*/
public function __construct(
DatabaseRepositoryInterface $databaseRepository,
@ -36,9 +33,6 @@ class HostDeletionService
* Delete a specified host from the Panel if no databases are
* attached to it.
*
* @param int $host
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/
public function handle(int $host): int

View file

@ -45,12 +45,6 @@ class HostUpdateService
/**
* DatabaseHostService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\DatabaseManager $databaseManager
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
* @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
*/
public function __construct(
ConnectionInterface $connection,
@ -69,15 +63,11 @@ class HostUpdateService
/**
* Update a database host and persist to the database.
*
* @param int $hostId
* @param array $data
* @return \Pterodactyl\Models\DatabaseHost
*
* @throws \Throwable
*/
public function handle(int $hostId, array $data): DatabaseHost
{
if (! empty(array_get($data, 'password'))) {
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->encrypter->encrypt($data['password']);
} else {
unset($data['password']);

View file

@ -32,8 +32,6 @@ class AllocationSelectionService
/**
* AllocationSelectionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
*/
public function __construct(AllocationRepositoryInterface $repository)
{
@ -45,7 +43,6 @@ class AllocationSelectionService
* to the given IP address. If true an allocation will not be selected if an IP
* already has another server set to use on if its allocations.
*
* @param bool $dedicated
* @return $this
*/
public function setDedicated(bool $dedicated)
@ -59,7 +56,6 @@ class AllocationSelectionService
* A list of node IDs that should be used when selecting an allocation. If empty, all
* nodes will be used to filter with.
*
* @param array $nodes
* @return $this
*/
public function setNodes(array $nodes)
@ -74,7 +70,6 @@ class AllocationSelectionService
* empty, all ports will be considered when finding an allocation. If set, only ports appearing
* in the array or range will be used.
*
* @param array $ports
* @return $this
*
* @throws \Pterodactyl\Exceptions\DisplayException
@ -106,8 +101,6 @@ class AllocationSelectionService
/**
* Return a single allocation that should be used as the default allocation for a server.
*
* @return \Pterodactyl\Models\Allocation
*
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
*/
public function handle(): Allocation

View file

@ -26,7 +26,6 @@ class FindViableNodesService
/**
* Set the locations that should be searched through to locate available nodes.
*
* @param array $locations
* @return $this
*/
public function setLocations(array $locations): self
@ -43,7 +42,6 @@ class FindViableNodesService
* filtered out if they do not have enough available free disk space for this server
* to be placed on.
*
* @param int $disk
* @return $this
*/
public function setDisk(int $disk): self
@ -57,7 +55,6 @@ class FindViableNodesService
* Set the amount of memory that this server will be using. As with disk space, nodes that
* do not have enough free memory will be filtered out.
*
* @param int $memory
* @return $this
*/
public function setMemory(int $memory): self
@ -81,6 +78,7 @@ class FindViableNodesService
* up to 50 nodes at a time starting at the provided page.
* If "null" is provided as the value no pagination will
* be used.
*
* @return \Illuminate\Support\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
*
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
@ -96,7 +94,7 @@ class FindViableNodesService
->leftJoin('servers', 'servers.node_id', '=', 'nodes.id')
->where('nodes.public', 1);
if (! empty($this->locations)) {
if (!empty($this->locations)) {
$query = $query->whereIn('nodes.location_id', $this->locations);
}
@ -104,7 +102,7 @@ class FindViableNodesService
->havingRaw('(IFNULL(SUM(servers.memory), 0) + ?) <= (nodes.memory * (1 + (nodes.memory_overallocate / 100)))', [$this->memory])
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk]);
if (! is_null($page)) {
if (!is_null($page)) {
$results = $results->paginate(50, ['*'], 'page', $page);
} else {
$results = $results->get()->toBase();

View file

@ -16,8 +16,6 @@ class EggConfigurationService
/**
* EggConfigurationService constructor.
*
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
*/
public function __construct(ServerConfigurationStructureService $configurationStructureService)
{
@ -26,14 +24,12 @@ class EggConfigurationService
/**
* Return an Egg file to be used by the Daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function handle(Server $server): array
{
$configs = $this->replacePlaceholders(
$server, json_decode($server->egg->inherit_config_files)
$server,
json_decode($server->egg->inherit_config_files)
);
return [
@ -46,7 +42,6 @@ class EggConfigurationService
/**
* Convert the "done" variable into an array if it is not currently one.
*
* @param array $startup
* @return array
*/
protected function convertStartupToNewFormat(array $startup)
@ -66,13 +61,10 @@ class EggConfigurationService
* For most eggs, this ends up just being a command sent to the server console, but
* if the stop command is something starting with a caret (^), it will be converted
* into the associated kill signal for the instance.
*
* @param string $stop
* @return array
*/
protected function convertStopToNewFormat(string $stop): array
{
if (! Str::startsWith($stop, '^')) {
if (!Str::startsWith($stop, '^')) {
return [
'type' => 'command',
'value' => $stop,
@ -94,8 +86,6 @@ class EggConfigurationService
}
/**
* @param \Pterodactyl\Models\Server $server
* @param object $configs
* @return array
*/
protected function replacePlaceholders(Server $server, object $configs)
@ -142,10 +132,6 @@ class EggConfigurationService
* set SERVER_MEMORY, SERVER_IP, and SERVER_PORT with their respective values on the Daemon
* side. Ensure that anything referencing those properly replaces them with the matching config
* value.
*
* @param string $key
* @param string $value
* @return string
*/
protected function replaceLegacyModifiers(string $key, string $value): string
{
@ -175,7 +161,7 @@ class EggConfigurationService
/**
* @param mixed $value
* @param array $structure
*
* @return mixed|null
*/
protected function matchAndReplaceKeys($value, array $structure)
@ -187,13 +173,13 @@ class EggConfigurationService
// value from the server properties.
//
// The Daemon supports server.X, env.X, and config.X placeholders.
if (! Str::startsWith($key, ['server.', 'env.', 'config.'])) {
if (!Str::startsWith($key, ['server.', 'env.', 'config.'])) {
continue;
}
// Don't do a replacement on anything that is not a string, we don't want to unintentionally
// modify the resulting output.
if (! is_string($value)) {
if (!is_string($value)) {
continue;
}
@ -218,7 +204,9 @@ class EggConfigurationService
// Finally, replace anything starting with env. with the expected environment
// variable from the server configuration.
$plucked = Arr::get(
$structure, preg_replace('/^env\./', 'build.env.', $key), ''
$structure,
preg_replace('/^env\./', 'build.env.', $key),
''
);
$value = str_replace("{{{$key}}}", $plucked, $value);
@ -233,12 +221,12 @@ class EggConfigurationService
* a match & replace.
*
* @param mixed $data
* @param array $structure
*
* @return mixed
*/
private function iterate($data, array $structure)
{
if (! is_iterable($data) && ! is_object($data)) {
if (!is_iterable($data) && !is_object($data)) {
return $data;
}

View file

@ -30,9 +30,6 @@ class EggCreationService
/**
* EggCreationService constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(ConfigRepository $config, EggRepositoryInterface $repository)
{
@ -43,16 +40,13 @@ class EggCreationService
/**
* Create a new service option and assign it to the given service.
*
* @param array $data
* @return \Pterodactyl\Models\Egg
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
$data['config_from'] = array_get($data, 'config_from');
if (! is_null($data['config_from'])) {
if (!is_null($data['config_from'])) {
$results = $this->repository->findCountWhere([
['nest_id', '=', array_get($data, 'nest_id')],
['id', '=', array_get($data, 'config_from')],

View file

@ -28,9 +28,6 @@ class EggDeletionService
/**
* EggDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
@ -43,9 +40,6 @@ class EggDeletionService
/**
* Delete an Egg from the database if it has no active servers attached to it.
*
* @param int $egg
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
*/

View file

@ -22,8 +22,6 @@ class EggUpdateService
/**
* EggUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(EggRepositoryInterface $repository)
{
@ -33,16 +31,13 @@ class EggUpdateService
/**
* Update a service option.
*
* @param \Pterodactyl\Models\Egg $egg
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle(Egg $egg, array $data)
{
if (! is_null(array_get($data, 'config_from'))) {
if (!is_null(array_get($data, 'config_from'))) {
$results = $this->repository->findCountWhere([
['nest_id', '=', $egg->nest_id],
['id', '=', array_get($data, 'config_from')],

View file

@ -15,8 +15,6 @@ class InstallScriptService
/**
* InstallScriptService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(EggRepositoryInterface $repository)
{
@ -27,7 +25,6 @@ class InstallScriptService
* Modify the install script for a given Egg.
*
* @param int|\Pterodactyl\Models\Egg $egg
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -35,8 +32,8 @@ class InstallScriptService
*/
public function handle(Egg $egg, array $data)
{
if (! is_null(array_get($data, 'copy_script_from'))) {
if (! $this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
if (!is_null(array_get($data, 'copy_script_from'))) {
if (!$this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
}
}

View file

@ -14,8 +14,6 @@ class EggExporterService
/**
* EggExporterService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(EggRepositoryInterface $repository)
{
@ -25,9 +23,6 @@ class EggExporterService
/**
* Return a JSON representation of an egg and its variables.
*
* @param int $egg
* @return string
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle(int $egg): string

View file

@ -36,11 +36,6 @@ class EggImporterService
/**
* EggImporterService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $eggVariableRepository
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $nestRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -57,10 +52,6 @@ class EggImporterService
/**
* Take an uploaded JSON file and parse it into a new egg.
*
* @param \Illuminate\Http\UploadedFile $file
* @param int $nest
* @return \Pterodactyl\Models\Egg
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
@ -68,24 +59,13 @@ class EggImporterService
*/
public function handle(UploadedFile $file, int $nest): Egg
{
if ($file->getError() !== UPLOAD_ERR_OK || ! $file->isFile()) {
throw new InvalidFileUploadException(
sprintf(
'The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)',
$file->getFilename(),
$file->isFile() ? 'true' : 'false',
$file->isValid() ? 'true' : 'false',
$file->getError(),
$file->getErrorMessage()
)
);
if ($file->getError() !== UPLOAD_ERR_OK || !$file->isFile()) {
throw new InvalidFileUploadException(sprintf('The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)', $file->getFilename(), $file->isFile() ? 'true' : 'false', $file->isValid() ? 'true' : 'false', $file->getError(), $file->getErrorMessage()));
}
$parsed = json_decode($file->openFile()->fread($file->getSize()));
if (json_last_error() !== 0) {
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', [
'error' => json_last_error_msg(),
]));
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', ['error' => json_last_error_msg()]));
}
if (object_get($parsed, 'meta.version') !== 'PTDL_v1') {

View file

@ -29,10 +29,6 @@ class EggUpdateImporterService
/**
* EggUpdateImporterService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $variableRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -47,9 +43,6 @@ class EggUpdateImporterService
/**
* Update an existing Egg using an uploaded JSON file.
*
* @param \Pterodactyl\Models\Egg $egg
* @param \Illuminate\Http\UploadedFile $file
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
@ -57,24 +50,13 @@ class EggUpdateImporterService
*/
public function handle(Egg $egg, UploadedFile $file)
{
if ($file->getError() !== UPLOAD_ERR_OK || ! $file->isFile()) {
throw new InvalidFileUploadException(
sprintf(
'The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)',
$file->getFilename(),
$file->isFile() ? 'true' : 'false',
$file->isValid() ? 'true' : 'false',
$file->getError(),
$file->getErrorMessage()
)
);
if ($file->getError() !== UPLOAD_ERR_OK || !$file->isFile()) {
throw new InvalidFileUploadException(sprintf('The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)', $file->getFilename(), $file->isFile() ? 'true' : 'false', $file->isValid() ? 'true' : 'false', $file->getError(), $file->getErrorMessage()));
}
$parsed = json_decode($file->openFile()->fread($file->getSize()));
if (json_last_error() !== 0) {
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', [
'error' => json_last_error_msg(),
]));
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', ['error' => json_last_error_msg()]));
}
if (object_get($parsed, 'meta.version') !== 'PTDL_v1') {
@ -113,7 +95,7 @@ class EggUpdateImporterService
// Delete variables not present in the import.
collect($existing)->each(function ($variable) use ($egg, $imported) {
if (! in_array($variable->env_variable, $imported)) {
if (!in_array($variable->env_variable, $imported)) {
$this->variableRepository->deleteWhere([
['egg_id', '=', $egg->id],
['env_variable', '=', $variable->env_variable],

View file

@ -24,9 +24,6 @@ class VariableCreationService
/**
* VariableCreationService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $repository
* @param \Illuminate\Contracts\Validation\Factory $validator
*/
public function __construct(EggVariableRepositoryInterface $repository, Factory $validator)
{
@ -37,8 +34,6 @@ class VariableCreationService
/**
* Return the validation factory instance to be used by rule validation
* checking in the trait.
*
* @return \Illuminate\Contracts\Validation\Factory
*/
protected function getValidator(): Factory
{
@ -48,10 +43,6 @@ class VariableCreationService
/**
* Create a new variable for a given Egg.
*
* @param int $egg
* @param array $data
* @return \Pterodactyl\Models\EggVariable
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
@ -59,13 +50,10 @@ class VariableCreationService
public function handle(int $egg, array $data): EggVariable
{
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {
throw new ReservedVariableNameException(sprintf(
'Cannot use the protected name %s for this environment variable.',
array_get($data, 'env_variable')
));
throw new ReservedVariableNameException(sprintf('Cannot use the protected name %s for this environment variable.', array_get($data, 'env_variable')));
}
if (! empty($data['rules'] ?? '')) {
if (!empty($data['rules'] ?? '')) {
$this->validateRules($data['rules']);
}

View file

@ -26,9 +26,6 @@ class VariableUpdateService
/**
* VariableUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $repository
* @param \Illuminate\Contracts\Validation\Factory $validator
*/
public function __construct(EggVariableRepositoryInterface $repository, Factory $validator)
{
@ -39,8 +36,6 @@ class VariableUpdateService
/**
* Return the validation factory instance to be used by rule validation
* checking in the trait.
*
* @return \Illuminate\Contracts\Validation\Factory
*/
protected function getValidator(): Factory
{
@ -50,8 +45,6 @@ class VariableUpdateService
/**
* Update a specific egg variable.
*
* @param \Pterodactyl\Models\EggVariable $variable
* @param array $data
* @return mixed
*
* @throws \Pterodactyl\Exceptions\DisplayException
@ -61,11 +54,9 @@ class VariableUpdateService
*/
public function handle(EggVariable $variable, array $data)
{
if (! is_null(array_get($data, 'env_variable'))) {
if (!is_null(array_get($data, 'env_variable'))) {
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', [
'name' => array_get($data, 'env_variable'),
]));
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', ['name' => array_get($data, 'env_variable')]));
}
$search = $this->repository->setColumns('id')->findCountWhere([
@ -75,13 +66,11 @@ class VariableUpdateService
]);
if ($search > 0) {
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', [
'name' => array_get($data, 'env_variable'),
]));
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', ['name' => array_get($data, 'env_variable')]));
}
}
if (! empty($data['rules'] ?? '')) {
if (!empty($data['rules'] ?? '')) {
$this->validateRules(
(is_string($data['rules']) && Str::contains($data['rules'], ';;'))
? explode(';;', $data['rules'])

View file

@ -30,9 +30,6 @@ class AssetHashService
/**
* AssetHashService constructor.
*
* @param \Illuminate\Contracts\Foundation\Application $application
* @param \Illuminate\Filesystem\FilesystemManager $filesystem
*/
public function __construct(Application $application, FilesystemManager $filesystem)
{
@ -43,9 +40,6 @@ class AssetHashService
/**
* Modify a URL to append the asset hash.
*
* @param string $resource
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function url(string $resource): string
@ -59,9 +53,6 @@ class AssetHashService
/**
* Return the data integrity hash for a resource.
*
* @param string $resource
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function integrity(string $resource): string
@ -75,9 +66,6 @@ class AssetHashService
/**
* Return a built CSS import using the provided URL.
*
* @param string $resource
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function css(string $resource): string
@ -105,9 +93,6 @@ class AssetHashService
/**
* Return a built JS import using the provided URL.
*
* @param string $resource
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function js(string $resource): string
@ -132,14 +117,13 @@ class AssetHashService
/**
* Get the asset manifest and store it in the cache for quicker lookups.
*
* @return array
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function manifest(): array
{
return self::$manifest ?: self::$manifest = json_decode(
$this->filesystem->get(self::MANIFEST_PATH), true
$this->filesystem->get(self::MANIFEST_PATH),
true
);
}
}

View file

@ -11,7 +11,7 @@ use Pterodactyl\Exceptions\Service\Helper\CdnVersionFetchingException;
class SoftwareVersionService
{
const VERSION_CACHE_KEY = 'pterodactyl:versioning_data';
public const VERSION_CACHE_KEY = 'pterodactyl:versioning_data';
/**
* @var array
@ -30,9 +30,6 @@ class SoftwareVersionService
/**
* SoftwareVersionService constructor.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @param \GuzzleHttp\Client $client
*/
public function __construct(
CacheRepository $cache,
@ -102,6 +99,7 @@ class SoftwareVersionService
* Determine if a passed daemon version string is the latest.
*
* @param string $version
*
* @return bool
*/
public function isLatestDaemon($version)
@ -128,7 +126,7 @@ class SoftwareVersionService
return json_decode($response->getBody(), true);
}
throw new CdnVersionFetchingException;
throw new CdnVersionFetchingException();
} catch (Exception $exception) {
return [];
}

View file

@ -20,8 +20,6 @@ class LocationCreationService
/**
* LocationCreationService constructor.
*
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
*/
public function __construct(LocationRepositoryInterface $repository)
{
@ -31,7 +29,6 @@ class LocationCreationService
/**
* Create a new location.
*
* @param array $data
* @return \Pterodactyl\Models\Location
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException

View file

@ -29,9 +29,6 @@ class LocationDeletionService
/**
* LocationDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $nodeRepository
*/
public function __construct(
LocationRepositoryInterface $repository,
@ -45,6 +42,7 @@ class LocationDeletionService
* Delete an existing location.
*
* @param int|\Pterodactyl\Models\Location $location
*
* @return int|null
*
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException

View file

@ -21,8 +21,6 @@ class LocationUpdateService
/**
* LocationUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
*/
public function __construct(LocationRepositoryInterface $repository)
{
@ -33,7 +31,7 @@ class LocationUpdateService
* Update an existing location.
*
* @param int|\Pterodactyl\Models\Location $location
* @param array $data
*
* @return \Pterodactyl\Models\Location
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException

View file

@ -21,9 +21,6 @@ class NestCreationService
/**
* NestCreationService constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
*/
public function __construct(ConfigRepository $config, NestRepositoryInterface $repository)
{
@ -34,9 +31,6 @@ class NestCreationService
/**
* Create a new nest on the system.
*
* @param array $data
* @param string|null $author
* @return \Pterodactyl\Models\Nest
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function handle(array $data, string $author = null): Nest

View file

@ -27,9 +27,6 @@ class NestDeletionService
/**
* NestDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
@ -42,9 +39,6 @@ class NestDeletionService
/**
* Delete a nest from the system only if there are no servers attached to it.
*
* @param int $nest
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/
public function handle(int $nest): int

View file

@ -20,8 +20,6 @@ class NestUpdateService
/**
* NestUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
*/
public function __construct(NestRepositoryInterface $repository)
{
@ -31,14 +29,12 @@ class NestUpdateService
/**
* Update a nest and prevent changing the author once it is set.
*
* @param int $nest
* @param array $data
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle(int $nest, array $data)
{
if (! is_null(array_get($data, 'author'))) {
if (!is_null(array_get($data, 'author'))) {
unset($data['author']);
}

View file

@ -22,9 +22,6 @@ class NodeCreationService
/**
* CreationService constructor.
*
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
*/
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)
{
@ -35,7 +32,6 @@ class NodeCreationService
/**
* Create a new node on the panel.
*
* @param array $data
* @return \Pterodactyl\Models\Node
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException

View file

@ -34,10 +34,6 @@ class NodeDeletionService
/**
* DeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
* @param \Illuminate\Contracts\Translation\Translator $translator
*/
public function __construct(
NodeRepositoryInterface $repository,
@ -53,6 +49,7 @@ class NodeDeletionService
* Delete a node from the panel if no servers are attached to it.
*
* @param int|\Pterodactyl\Models\Node $node
*
* @return bool|null
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException

View file

@ -31,7 +31,6 @@ class NodeJWTService
/**
* Set the claims to include in this JWT.
*
* @param array $claims
* @return $this
*/
public function setClaims(array $claims)
@ -42,7 +41,6 @@ class NodeJWTService
}
/**
* @param \DateTimeImmutable $date
* @return $this
*/
public function setExpiresAt(DateTimeImmutable $date)
@ -53,7 +51,6 @@ class NodeJWTService
}
/**
* @param string $subject
* @return $this
*/
public function setSubject(string $subject)
@ -66,17 +63,16 @@ class NodeJWTService
/**
* Generate a new JWT for a given node.
*
* @param \Pterodactyl\Models\Node $node
* @param string|null $identifiedBy
* @param string $algo
*
* @return \Lcobucci\JWT\Token\Plain
*/
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
{
$identifier = hash($algo, $identifiedBy);
$config = Configuration::forSymmetricSigner(new Sha256, InMemory::plainText($node->getDecryptedKey()));
$config = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($node->getDecryptedKey()));
$builder = $config->builder(new TimestampDates)
$builder = $config->builder(new TimestampDates())
->issuedBy(config('app.url'))
->permittedFor($node->getConnectionAddress())
->identifiedBy($identifier)
@ -88,7 +84,7 @@ class NodeJWTService
$builder = $builder->expiresAt($this->expiresAt);
}
if (! empty($this->subject)) {
if (!empty($this->subject)) {
$builder = $builder->relatedTo($this->subject)->withHeader('sub', $this->subject);
}

View file

@ -36,11 +36,6 @@ class NodeUpdateService
/**
* UpdateService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository $configurationRepository
* @param \Pterodactyl\Repositories\Eloquent\NodeRepository $repository
*/
public function __construct(
ConnectionInterface $connection,
@ -57,11 +52,8 @@ class NodeUpdateService
/**
* Update the configuration values for a given node on the machine.
*
* @param \Pterodactyl\Models\Node $node
* @param array $data
* @param bool $resetToken
*
* @return \Pterodactyl\Models\Node
*
* @throws \Throwable
*/
public function handle(Node $node, array $data, bool $resetToken = false)

View file

@ -23,9 +23,6 @@ class ProcessScheduleService
/**
* ProcessScheduleService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
*/
public function __construct(ConnectionInterface $connection, Dispatcher $dispatcher)
{
@ -36,9 +33,6 @@ class ProcessScheduleService
/**
* Process a schedule and push the first task onto the queue worker.
*
* @param \Pterodactyl\Models\Schedule $schedule
* @param bool $now
*
* @throws \Throwable
*/
public function handle(Schedule $schedule, bool $now = false)
@ -47,9 +41,7 @@ class ProcessScheduleService
$task = $schedule->tasks()->orderBy('sequence_id', 'asc')->first();
if (is_null($task)) {
throw new DisplayException(
'Cannot process schedule for task execution: no tasks are registered.'
);
throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.');
}
$this->connection->transaction(function () use ($schedule, $task) {
@ -63,7 +55,7 @@ class ProcessScheduleService
$job = new RunTaskJob($task);
if (! $now) {
if (!$now) {
$this->dispatcher->dispatch($job->delay($task->time_offset));
} else {
// When using dispatchNow the RunTaskJob::failed() function is not called automatically

View file

@ -31,8 +31,6 @@ class BuildModificationService
* BuildModificationService constructor.
*
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
*/
public function __construct(
ServerConfigurationStructureService $structureService,
@ -47,8 +45,6 @@ class BuildModificationService
/**
* Change the build details for a specified server.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
@ -82,7 +78,7 @@ class BuildModificationService
$updateData = $this->structureService->handle($server);
if (! empty($updateData['build'])) {
if (!empty($updateData['build'])) {
$this->daemonServerRepository->setServer($server)->update([
'build' => $updateData['build'],
]);
@ -96,9 +92,6 @@ class BuildModificationService
/**
* Process the allocations being assigned in the data and ensure they are available for a server.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
private function processAllocations(Server $server, array &$data)
@ -109,7 +102,7 @@ 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'])) {
if (!empty($data['add_allocations'])) {
$query = Allocation::query()
->where('node_id', $server->node_id)
->whereIn('id', $data['add_allocations'])
@ -122,16 +115,14 @@ class BuildModificationService
$query->update(['server_id' => $server->id, 'notes' => null]);
}
if (! empty($data['remove_allocations'])) {
if (!empty($data['remove_allocations'])) {
foreach ($data['remove_allocations'] as $allocation) {
// If we are attempting to remove the default allocation for the server, see if we can reassign
// to the first provided value in add_allocations. If there is no new first allocation then we
// will throw an exception back.
if ($allocation === ($data['allocation_id'] ?? $server->allocation_id)) {
if (empty($freshlyAllocated)) {
throw new DisplayException(
'You are attempting to delete the default allocation for this server but there is no fallback allocation to use.'
);
throw new DisplayException('You are attempting to delete the default allocation for this server but there is no fallback allocation to use.');
}
// Update the default allocation to be the first allocation that we are creating.

View file

@ -25,9 +25,6 @@ class DetailsModificationService
/**
* DetailsModificationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $serverRepository
*/
public function __construct(ConnectionInterface $connection, DaemonServerRepository $serverRepository)
{
@ -38,10 +35,6 @@ class DetailsModificationService
/**
* Update the details for a single server instance.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
*/
public function handle(Server $server, array $data): Server

View file

@ -15,9 +15,6 @@ class EnvironmentService
/**
* Dynamically configure additional environment variables to be assigned
* with a specific server.
*
* @param string $key
* @param callable $closure
*/
public function setEnvironmentKey(string $key, callable $closure)
{
@ -26,8 +23,6 @@ class EnvironmentService
/**
* Return the dynamically added additional keys.
*
* @return array
*/
public function getEnvironmentKeys(): array
{
@ -37,9 +32,6 @@ class EnvironmentService
/**
* Take all of the environment variables configured for this server and return
* them in an easy to process format.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function handle(Server $server): array
{
@ -57,7 +49,8 @@ class EnvironmentService
// Process variables set in the configuration file.
foreach (config('pterodactyl.environment_variables', []) as $key => $object) {
$variables->put(
$key, is_callable($object) ? call_user_func($object, $server) : object_get($server, $object)
$key,
is_callable($object) ? call_user_func($object, $server) : object_get($server, $object)
);
}
@ -71,8 +64,6 @@ class EnvironmentService
/**
* Return a mapping of Panel default environment variables.
*
* @return array
*/
private function getEnvironmentMappings(): array
{

View file

@ -12,8 +12,6 @@ class GetUserPermissionsService
* if they are an admin or a subuser for the server. If no permissions are
* found, an empty array is returned.
*
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\User $user
* @return string[]
*/
public function handle(Server $server, User $user)

View file

@ -20,9 +20,6 @@ class ReinstallServerService
/**
* ReinstallService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -35,7 +32,6 @@ class ReinstallServerService
/**
* Reinstall a server on the remote daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable

View file

@ -28,17 +28,14 @@ class ServerConfigurationStructureService
* DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new Wings
* daemon, if you modify the structure eggs will break unexpectedly.
*
* @param \Pterodactyl\Models\Server $server
* @param array $override
* @param bool $legacy deprecated
* @return array
*/
public function handle(Server $server, array $override = [], bool $legacy = false): array
{
$clone = $server;
// If any overrides have been set on this call make sure to update them on the
// cloned instance so that the configuration generated uses them.
if (! empty($override)) {
if (!empty($override)) {
$clone = $server->fresh();
foreach ($override as $key => $value) {
$clone->setAttribute($key, $value);
@ -53,7 +50,6 @@ class ServerConfigurationStructureService
/**
* Returns the new data format used for the Wings daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*/
protected function returnCurrentFormat(Server $server)
@ -106,8 +102,8 @@ class ServerConfigurationStructureService
* Returns the legacy server data format to continue support for old egg configurations
* that have not yet been updated.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*
* @deprecated
*/
protected function returnLegacyFormat(Server $server)

View file

@ -75,16 +75,9 @@ class ServerCreationService
/**
* CreationService constructor.
*
* @param \Pterodactyl\Services\Deployment\AllocationSelectionService $allocationSelectionService
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
* @param \Pterodactyl\Repositories\Eloquent\EggRepository $eggRepository
* @param \Pterodactyl\Services\Deployment\FindViableNodesService $findViableNodesService
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
* @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $serverVariableRepository
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
*/
public function __construct(
AllocationSelectionService $allocationSelectionService,
@ -116,10 +109,6 @@ class ServerCreationService
* as possible given the input data. For example, if an allocation_id is passed with
* no node_id the node_is will be picked from the allocation.
*
* @param array $data
* @param \Pterodactyl\Models\Objects\DeploymentObject|null $deployment
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Illuminate\Validation\ValidationException
@ -187,10 +176,6 @@ class ServerCreationService
/**
* Gets an allocation to use for automatic deployment.
*
* @param array $data
* @param \Pterodactyl\Models\Objects\DeploymentObject $deployment
*
* @return \Pterodactyl\Models\Allocation
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
@ -212,9 +197,6 @@ class ServerCreationService
/**
* Store the server in the database and return the model.
*
* @param array $data
* @return \Pterodactyl\Models\Server
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
private function createModel(array $data): Server
@ -254,9 +236,6 @@ class ServerCreationService
/**
* Configure the allocations assigned to this server.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
*/
private function storeAssignedAllocations(Server $server, array $data)
{
@ -272,9 +251,6 @@ class ServerCreationService
/**
* Process environment variables passed for this server and store them in the database.
*
* @param \Pterodactyl\Models\Server $server
* @param \Illuminate\Support\Collection $variables
*/
private function storeEggVariables(Server $server, Collection $variables)
{
@ -286,21 +262,19 @@ class ServerCreationService
];
})->toArray();
if (! empty($records)) {
if (!empty($records)) {
$this->serverVariableRepository->insert($records);
}
}
/**
* Create a unique UUID and UUID-Short combo for a server.
*
* @return string
*/
private function generateUniqueUuidCombo(): string
{
$uuid = Uuid::uuid4()->toString();
if (! $this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
if (!$this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
return $this->generateUniqueUuidCombo();
}

View file

@ -35,10 +35,6 @@ class ServerDeletionService
/**
* DeletionService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
*/
public function __construct(
ConnectionInterface $connection,
@ -54,6 +50,7 @@ class ServerDeletionService
* Set if the server should be forcibly deleted from the panel (ignoring daemon errors) or not.
*
* @param bool $bool
*
* @return $this
*/
public function withForce($bool = true)
@ -66,8 +63,6 @@ class ServerDeletionService
/**
* Delete a server from the panel and remove any associated databases from hosts.
*
* @param \Pterodactyl\Models\Server $server
*
* @throws \Throwable
* @throws \Pterodactyl\Exceptions\DisplayException
*/
@ -80,7 +75,7 @@ class ServerDeletionService
// go ahead and bail out. We specifically ignore a 404 since that can be assumed
// to be a safe error, meaning the server doesn't exist at all on Wings so there
// is no reason we need to bail out from that.
if (! $this->force && $exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
if (!$this->force && $exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exception;
}
@ -92,7 +87,7 @@ class ServerDeletionService
try {
$this->databaseManagementService->delete($database);
} catch (Exception $exception) {
if (! $this->force) {
if (!$this->force) {
throw $exception;
}

View file

@ -8,10 +8,6 @@ class StartupCommandService
{
/**
* Generates a startup command for a given server instance.
*
* @param \Pterodactyl\Models\Server $server
* @param bool $hideAllValues
* @return string
*/
public function handle(Server $server, bool $hideAllValues = false): string
{
@ -20,7 +16,7 @@ class StartupCommandService
foreach ($server->variables as $variable) {
$find[] = '{{' . $variable->env_variable . '}}';
$replace[] = ($variable->user_viewable && ! $hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
$replace[] = ($variable->user_viewable && !$hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
}
return str_replace($find, $replace, $server->startup);

View file

@ -27,7 +27,6 @@ class StartupModificationService
/**
* StartupModificationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
*/
public function __construct(ConnectionInterface $connection, VariableValidatorService $validatorService)
@ -39,16 +38,12 @@ class StartupModificationService
/**
* Process startup modification for a server.
*
* @param \Pterodactyl\Models\Server $server
* @param array $data
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
*/
public function handle(Server $server, array $data): Server
{
return $this->connection->transaction(function () use ($server, $data) {
if (! empty($data['environment'])) {
if (!empty($data['environment'])) {
$egg = $this->isUserLevel(User::USER_LEVEL_ADMIN) ? ($data['egg_id'] ?? $server->egg_id) : $server->egg_id;
$results = $this->validatorService
@ -83,9 +78,6 @@ class StartupModificationService
/**
* Update certain administrative settings for a server in the DB.
*
* @param array $data
* @param \Pterodactyl\Models\Server $server
*/
protected function updateAdministrativeSettings(array $data, Server &$server)
{

View file

@ -10,8 +10,8 @@ use Pterodactyl\Exceptions\Http\Server\ServerTransferringException;
class SuspensionService
{
const ACTION_SUSPEND = 'suspend';
const ACTION_UNSUSPEND = 'unsuspend';
public const ACTION_SUSPEND = 'suspend';
public const ACTION_UNSUSPEND = 'unsuspend';
/**
* @var \Illuminate\Database\ConnectionInterface
@ -25,9 +25,6 @@ class SuspensionService
/**
* SuspensionService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -40,7 +37,6 @@ class SuspensionService
/**
* Suspends a server on the system.
*
* @param \Pterodactyl\Models\Server $server
* @param string $action
*
* @throws \Throwable
@ -58,8 +54,8 @@ class SuspensionService
}
// Check if the server is currently being transferred.
if (! is_null($server->transfer)) {
throw new ServerTransferringException;
if (!is_null($server->transfer)) {
throw new ServerTransferringException();
}
$this->connection->transaction(function () use ($action, $server) {

View file

@ -20,9 +20,6 @@ class TransferService
/**
* TransferService constructor.
*
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(
DaemonServerRepository $daemonServerRepository,

View file

@ -27,8 +27,6 @@ class VariableValidatorService
/**
* VariableValidatorService constructor.
*
* @param \Illuminate\Contracts\Validation\Factory $validator
*/
public function __construct(ValidationFactory $validator)
{
@ -38,15 +36,12 @@ class VariableValidatorService
/**
* Validate all of the passed data against the given service option variables.
*
* @param int $egg
* @param array $fields
* @return \Illuminate\Support\Collection
* @throws \Illuminate\Validation\ValidationException
*/
public function handle(int $egg, array $fields = []): Collection
{
$query = EggVariable::query()->where('egg_id', $egg);
if (! $this->isUserLevel(User::USER_LEVEL_ADMIN)) {
if (!$this->isUserLevel(User::USER_LEVEL_ADMIN)) {
// Don't attempt to validate variables if they aren't user editable
// and we're not running this at an admin level.
$query = $query->where('user_editable', true)->where('user_viewable', true);

View file

@ -37,11 +37,6 @@ class SubuserCreationService
/**
* SubuserCreationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Eloquent\SubuserRepository $subuserRepository
* @param \Pterodactyl\Services\Users\UserCreationService $userCreationService
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
*/
public function __construct(
ConnectionInterface $connection,
@ -60,11 +55,6 @@ class SubuserCreationService
* If the email address already belongs to a user on the system a new user will not
* be created.
*
* @param \Pterodactyl\Models\Server $server
* @param string $email
* @param array $permissions
* @return \Pterodactyl\Models\Subuser
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException
* @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException

View file

@ -41,12 +41,6 @@ class ToggleTwoFactorService
/**
* ToggleTwoFactorService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param \PragmaRX\Google2FA\Google2FA $google2FA
* @param \Pterodactyl\Repositories\Eloquent\RecoveryTokenRepository $recoveryTokenRepository
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
ConnectionInterface $connection,
@ -65,9 +59,6 @@ class ToggleTwoFactorService
/**
* Toggle 2FA on an account only if the token provided is valid.
*
* @param \Pterodactyl\Models\User $user
* @param string $token
* @param bool|null $toggleState
* @return string[]
*
* @throws \Throwable
@ -82,7 +73,7 @@ class ToggleTwoFactorService
$isValidToken = $this->google2FA->verifyKey($secret, $token, config()->get('pterodactyl.auth.2fa.window'));
if (! $isValidToken) {
if (!$isValidToken) {
throw new TwoFactorAuthenticationTokenInvalid('The token provided is not valid.');
}
@ -95,9 +86,9 @@ class ToggleTwoFactorService
// which will then be marked as deleted from the database and will also bypass 2FA protections
// on their account.
$tokens = [];
if ((! $toggleState && ! $user->use_totp) || $toggleState) {
if ((!$toggleState && !$user->use_totp) || $toggleState) {
$inserts = [];
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; ++$i) {
$token = Str::random(10);
$inserts[] = [
@ -118,7 +109,7 @@ class ToggleTwoFactorService
$this->repository->withoutFreshModel()->update($user->id, [
'totp_authenticated_at' => Carbon::now(),
'use_totp' => (is_null($toggleState) ? ! $user->use_totp : $toggleState),
'use_totp' => (is_null($toggleState) ? !$user->use_totp : $toggleState),
]);
return $tokens;

View file

@ -11,7 +11,7 @@ use Illuminate\Contracts\Config\Repository as ConfigRepository;
class TwoFactorSetupService
{
const VALID_BASE32_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
public const VALID_BASE32_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
/**
* @var \Illuminate\Contracts\Config\Repository
@ -30,10 +30,6 @@ class TwoFactorSetupService
/**
* TwoFactorSetupService constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
ConfigRepository $config,
@ -50,9 +46,6 @@ class TwoFactorSetupService
* QR code URL. This URL will need to be attached to a QR generating service in
* order to function.
*
* @param \Pterodactyl\Models\User $user
* @return string
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
@ -60,7 +53,7 @@ class TwoFactorSetupService
{
$secret = '';
try {
for ($i = 0; $i < $this->config->get('pterodactyl.auth.2fa.bytes', 16); $i++) {
for ($i = 0; $i < $this->config->get('pterodactyl.auth.2fa.bytes', 16); ++$i) {
$secret .= substr(self::VALID_BASE32_CHARACTERS, random_int(0, 31), 1);
}
} catch (Exception $exception) {

View file

@ -33,11 +33,6 @@ class UserCreationService
/**
* CreationService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Illuminate\Contracts\Auth\PasswordBroker $passwordBroker
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
ConnectionInterface $connection,
@ -54,7 +49,6 @@ class UserCreationService
/**
* Create a new user on the system.
*
* @param array $data
* @return \Pterodactyl\Models\User
*
* @throws \Exception
@ -62,12 +56,12 @@ class UserCreationService
*/
public function handle(array $data)
{
if (array_key_exists('password', $data) && ! empty($data['password'])) {
if (array_key_exists('password', $data) && !empty($data['password'])) {
$data['password'] = $this->hasher->make($data['password']);
}
$this->connection->beginTransaction();
if (! isset($data['password']) || empty($data['password'])) {
if (!isset($data['password']) || empty($data['password'])) {
$generateResetToken = true;
$data['password'] = $this->hasher->make(str_random(30));
}

View file

@ -34,10 +34,6 @@ class UserDeletionService
/**
* DeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
* @param \Illuminate\Contracts\Translation\Translator $translator
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
ServerRepositoryInterface $serverRepository,
@ -53,6 +49,7 @@ class UserDeletionService
* Delete a user from the panel only if they have no servers attached to their account.
*
* @param int|\Pterodactyl\Models\User $user
*
* @return bool|null
*
* @throws \Pterodactyl\Exceptions\DisplayException

View file

@ -23,9 +23,6 @@ class UserUpdateService
/**
* UpdateService constructor.
*
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $repository
*/
public function __construct(Hasher $hasher, UserRepository $repository)
{
@ -36,8 +33,6 @@ class UserUpdateService
/**
* Update the user model instance.
*
* @param \Pterodactyl\Models\User $user
* @param array $data
* @return \Pterodactyl\Models\User
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
@ -45,7 +40,7 @@ class UserUpdateService
*/
public function handle(User $user, array $data)
{
if (! empty(array_get($data, 'password'))) {
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
} else {
unset($data['password']);