Use more standardized phpcs
This commit is contained in:
parent
a043071e3c
commit
c449ca5155
493 changed files with 1116 additions and 3903 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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')],
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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')],
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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') {
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
|
|
|
@ -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'])
|
||||
|
|
Reference in a new issue