From 41c3f1336a3db120bd850bf8673bf6a31e9c7ea1 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sat, 16 Mar 2024 14:26:08 -0400 Subject: [PATCH] More static analysis --- app/Console/Commands/Server/BulkPowerActionCommand.php | 2 +- app/Http/Controllers/Auth/LoginCheckpointController.php | 6 ++---- app/Http/Controllers/Auth/LoginController.php | 9 +++------ app/Models/Node.php | 3 +++ app/Services/Allocations/AssignmentService.php | 3 +-- phpstan.neon | 2 +- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/Server/BulkPowerActionCommand.php b/app/Console/Commands/Server/BulkPowerActionCommand.php index 62399b4ee..6d463d196 100644 --- a/app/Console/Commands/Server/BulkPowerActionCommand.php +++ b/app/Console/Commands/Server/BulkPowerActionCommand.php @@ -97,7 +97,7 @@ class BulkPowerActionCommand extends Command $instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes); } elseif (empty($nodes) && !empty($servers)) { $instance->whereIn('id', $servers); - } elseif (!empty($nodes) && empty($servers)) { + } elseif (!empty($nodes)) { $instance->whereIn('node_id', $nodes); } diff --git a/app/Http/Controllers/Auth/LoginCheckpointController.php b/app/Http/Controllers/Auth/LoginCheckpointController.php index 6c57b7201..75bab4fd0 100644 --- a/app/Http/Controllers/Auth/LoginCheckpointController.php +++ b/app/Http/Controllers/Auth/LoginCheckpointController.php @@ -55,10 +55,8 @@ class LoginCheckpointController extends AbstractLoginController $this->sendFailedLoginResponse($request); } - try { - /** @var \App\Models\User $user */ - $user = User::query()->findOrFail($details['user_id']); - } catch (ModelNotFoundException) { + $user = User::query()->find($details['user_id']); + if (!$user) { $this->sendFailedLoginResponse($request, null, self::TOKEN_EXPIRED_MESSAGE); } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index e90854572..173955001 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -45,12 +45,9 @@ class LoginController extends AbstractLoginController $this->sendLockoutResponse($request); } - try { - $username = $request->input('user'); - - /** @var \App\Models\User $user */ - $user = User::query()->where($this->getField($username), $username)->firstOrFail(); - } catch (ModelNotFoundException) { + $username = $request->input('user'); + $user = User::query()->where($this->getField($username), $username)->first(); + if (!$user) { $this->sendFailedLoginResponse($request); } diff --git a/app/Models/Node.php b/app/Models/Node.php index a7785228a..d57800723 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -60,6 +60,9 @@ class Node extends Model */ protected $hidden = ['daemon_token_id', 'daemon_token']; + private int $sum_memory; + private int $sum_disk; + /** * Cast values to correct type. */ diff --git a/app/Services/Allocations/AssignmentService.php b/app/Services/Allocations/AssignmentService.php index e6fe805a3..8d103e482 100644 --- a/app/Services/Allocations/AssignmentService.php +++ b/app/Services/Allocations/AssignmentService.php @@ -54,8 +54,7 @@ class AssignmentService $underlying = gethostbyname($data['allocation_ip']); $parsed = Network::parse($underlying); } catch (\Exception $exception) { - /* @noinspection PhpUndefinedVariableInspection */ - throw new DisplayException("Could not parse provided allocation IP address ({$underlying}): {$exception->getMessage()}", $exception); + throw new DisplayException("Could not parse provided allocation IP address ({$data['allocation_ip']}): {$exception->getMessage()}", $exception); } $this->connection->beginTransaction(); diff --git a/phpstan.neon b/phpstan.neon index ea669629c..6096d6449 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,7 @@ parameters: - app/ # Level 9 is the highest level - level: 0 + level: 1 # ignoreErrors: # - '#PHPDoc tag @var#'