From 374c704607f72bd49e7b8cad153f36b6e151e600 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sun, 29 Dec 2024 09:16:55 +0100 Subject: [PATCH] Simplify if-else branches --- src/Concerns/ParallelCommand.php | 18 +++++++++++------- src/Controllers/TenantAssetController.php | 10 +++++----- src/Listeners/QueueableListener.php | 12 ++++++------ src/Middleware/InitializeTenancyByPath.php | 4 ++-- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Concerns/ParallelCommand.php b/src/Concerns/ParallelCommand.php index aad7a1ec..e3feb228 100644 --- a/src/Concerns/ParallelCommand.php +++ b/src/Concerns/ParallelCommand.php @@ -48,15 +48,17 @@ trait ParallelCommand if ($pid === -1) { return -1; - } elseif ($pid) { + } + + if ($pid) { // Parent return $pid; - } else { - // Child - DB::reconnect(); - - exit($this->childHandle(...$args) ? 0 : 1); } + + // Child + DB::reconnect(); + + exit($this->childHandle(...$args) ? 0 : 1); } protected function sysctlGetLogicalCoreCount(bool $darwin): int @@ -70,7 +72,9 @@ trait ParallelCommand // perflevel0 refers to P-cores on M-series, and the entire CPU on Intel Macs if ($darwin && $ffi->sysctlbyname('hw.perflevel0.logicalcpu', FFI::addr($cores), FFI::addr($size), null, 0) === 0) { return $cores->cdata; - } else if ($darwin) { + } + + if ($darwin) { // Reset the size in case the pointer got written to (likely shouldn't happen) $size->cdata = FFI::sizeof($cores); } diff --git a/src/Controllers/TenantAssetController.php b/src/Controllers/TenantAssetController.php index 6133c4ce..243135ed 100644 --- a/src/Controllers/TenantAssetController.php +++ b/src/Controllers/TenantAssetController.php @@ -88,12 +88,12 @@ class TenantAssetController implements HasMiddleware if (app()->runningUnitTests()) { // Makes testing the cause of the failure in validatePath() easier throw new Exception($exceptionMessage); - } else { - // We always use 404 to avoid leaking information about the cause of the error - // e.g. when someone is trying to access a nonexistent file outside of the allowed - // root folder, we don't want to let the user know whether such a file exists or not. - abort(404); } + + // We always use 404 to avoid leaking information about the cause of the error + // e.g. when someone is trying to access a nonexistent file outside of the allowed + // root folder, we don't want to let the user know whether such a file exists or not. + abort(404); } } } diff --git a/src/Listeners/QueueableListener.php b/src/Listeners/QueueableListener.php index f486873d..22ad1f1f 100644 --- a/src/Listeners/QueueableListener.php +++ b/src/Listeners/QueueableListener.php @@ -17,12 +17,12 @@ abstract class QueueableListener implements ShouldQueue { if (static::$shouldQueue) { return true; - } else { - // The listener is not queued so we manually - // pass the event to the handle() method. - $this->handle($event); - - return false; } + + // The listener is not queued so we manually + // pass the event to the handle() method. + $this->handle($event); + + return false; } } diff --git a/src/Middleware/InitializeTenancyByPath.php b/src/Middleware/InitializeTenancyByPath.php index bcf27dd2..e11094eb 100644 --- a/src/Middleware/InitializeTenancyByPath.php +++ b/src/Middleware/InitializeTenancyByPath.php @@ -43,9 +43,9 @@ class InitializeTenancyByPath extends IdentificationMiddleware $next, $route ); - } else { - throw new RouteIsMissingTenantParameterException; } + + throw new RouteIsMissingTenantParameterException; } /**