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

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