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

@ -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);