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

@ -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.