Skip to content

Commit

Permalink
[v0.3] PHPStan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ksroga committed Jan 11, 2025
1 parent 6153eca commit e8dc9a0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/Core/Controller/API/ServerConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

class ServerConfigurationController extends APIAbstractController
{
public function __construct(
private readonly ServerRepository $serverRepository,
private readonly ServerLogService $serverLogService,
private readonly TranslatorInterface $translator,
) {}

#[Route('/panel/api/server/{id}/startup/variable', name: 'server_startup_variable_update', methods: ['POST'])]
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Controller/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function server(
throw $this->createNotFoundException();
}

/** @var Server $server */
/** @var ?Server $server */
$server = current($serverRepository->findBy(['pterodactylServerIdentifier' => $serverId]));
if (empty($server)) {
throw $this->createNotFoundException();
Expand Down
6 changes: 2 additions & 4 deletions src/Core/Service/Pterodactyl/PterodactylAccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public function __construct(
{
}

public function createPterodactylAccount(User $user, string $plainPassword): ?PterodactylUser
public function createPterodactylAccount(User $user, string $plainPassword): PterodactylUser
{
$createdPterodactylUser = $this->pterodactylService->getApi()->users->create([
return $this->pterodactylService->getApi()->users->create([
'email' => $user->getEmail(),
'username' => $this->usernameService->generateUsername($user->getEmail()),
'first_name' => $user->getName(),
'last_name' => $user->getSurname(),
'password' => $plainPassword,
]);

return $createdPterodactylUser ?? null;
}

public function deletePterodactylAccount(User $user): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ protected function getServerDetails(Server $server, array $include = []): array
{
$serverDetails = $this->pterodactylService->getApi()->servers->get($server->getPterodactylServerId(), [
'include' => $include,
]);
])?->toArray();

if (empty($serverDetails)) {
throw new \Exception('Server not found');
}

return $serverDetails->toArray();
return $serverDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ private function validateVariable(Server $server, array $serverDetails, array $s
$constraints = [];

foreach ($rules as $rule) {
if (str_contains($rule, ':')) {
$partedRules = explode(':', $rule);
$rule = $partedRules[0];
}

if (isset($ruleMap[$rule])) {
if (in_array($rule, ['string', 'numeric', 'boolean'], true)) {
$constraints[] = new $ruleMap[$rule](['type' => $rule]);
} else {
$constraints[] = new $ruleMap[$rule]();
}
$constraints[] = match ($rule) {
'string', 'numeric', 'boolean' => new $ruleMap[$rule](['type' => $rule]),
'regex' => new $ruleMap[$rule](['pattern' => $partedRules[1] ?? '']),
default => new $ruleMap[$rule]([]),
};
}
}

Expand Down

0 comments on commit e8dc9a0

Please sign in to comment.