From fcb1a2f9267c998b5d4e0114c49e020c8a13a91a Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 10:35:20 +0000 Subject: [PATCH 1/2] refactor: remove redundant else blocks This PR refactors code by removing redundant `else` clauses that follow `return` statements, improving code clarity and reducing unnecessary nesting. - Redundant `else` due to `return`: Several code paths contained `else` blocks immediately after a `return`, making those branches unreachable. This commit eliminates those redundant `else` statements in both the status switch and the cache retrieval logic, flattening control flow and enhancing readability. > This Autofix was generated by AI. Please review the change before merging. --- .../Aggregate/AggregateService.cs | 26 +++++++++---------- Shared.Tests/ResultHelpersTests.cs | 21 +++++++-------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Shared.EventStore/Aggregate/AggregateService.cs b/Shared.EventStore/Aggregate/AggregateService.cs index 9bbd1fe8..1d8fa2dd 100644 --- a/Shared.EventStore/Aggregate/AggregateService.cs +++ b/Shared.EventStore/Aggregate/AggregateService.cs @@ -136,22 +136,20 @@ public async Task> Get(Guid aggregateId, { return Result.Success(cachedAggregate); } + + // Not found in cache so call GetLatest + SimpleResults.Result aggregateResult = this.GetLatest(aggregateId, cancellationToken).Result; + + if (aggregateResult.IsSuccess) + { + aggregate = aggregateResult.Data; + this.SetCache(at, aggregateResult.Data); + return Result.Success(aggregate); + } else { - // Not found in cache so call GetLatest - SimpleResults.Result aggregateResult = this.GetLatest(aggregateId, cancellationToken).Result; - - if (aggregateResult.IsSuccess) - { - aggregate = aggregateResult.Data; - this.SetCache(at, aggregateResult.Data); - return Result.Success(aggregate); - } - else - { - Logger.Logger.LogWarning($"aggregateResult failed {aggregateResult.Message}"); - return aggregateResult; - } + Logger.Logger.LogWarning($"aggregateResult failed {aggregateResult.Message}"); + return aggregateResult; } } finally diff --git a/Shared.Tests/ResultHelpersTests.cs b/Shared.Tests/ResultHelpersTests.cs index f66174e5..c8a5db51 100644 --- a/Shared.Tests/ResultHelpersTests.cs +++ b/Shared.Tests/ResultHelpersTests.cs @@ -185,16 +185,15 @@ private Result CreateTestResult(ResultStatus status, ResultStatus.Forbidden => Result.Forbidden(message), }; } - else { - return status switch { - ResultStatus.Invalid => Result.Invalid(errors), - ResultStatus.NotFound => Result.NotFound(errors), - ResultStatus.Unauthorized => Result.Unauthorized(errors), - ResultStatus.Conflict => Result.Conflict(errors), - ResultStatus.Failure => Result.Failure(errors), - ResultStatus.CriticalError => Result.CriticalError(errors), - ResultStatus.Forbidden => Result.Forbidden(errors) - }; - } + + return status switch { + ResultStatus.Invalid => Result.Invalid(errors), + ResultStatus.NotFound => Result.NotFound(errors), + ResultStatus.Unauthorized => Result.Unauthorized(errors), + ResultStatus.Conflict => Result.Conflict(errors), + ResultStatus.Failure => Result.Failure(errors), + ResultStatus.CriticalError => Result.CriticalError(errors), + ResultStatus.Forbidden => Result.Forbidden(errors) + }; } } \ No newline at end of file From fb726a97a9882f3567d0304c896278fb2b1bed9d Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 10:47:40 +0000 Subject: [PATCH 2/2] refactor: remove redundant else due to return This PR refactors the conditional logic to eliminate an unnecessary `else` block following a `return`, improving readability and reducing code nesting. - Redundant `else` due to `return`: The original code used an `else` block immediately after a `return`, creating redundant indentation and nesting. We removed the `else` keyword and dedented the warning log and return statement so they execute directly. This simplification clarifies the control flow and makes the code more maintainable. > This Autofix was generated by AI. Please review the change before merging. --- Shared.EventStore/Aggregate/AggregateService.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Shared.EventStore/Aggregate/AggregateService.cs b/Shared.EventStore/Aggregate/AggregateService.cs index 1d8fa2dd..7b6b44a7 100644 --- a/Shared.EventStore/Aggregate/AggregateService.cs +++ b/Shared.EventStore/Aggregate/AggregateService.cs @@ -146,11 +146,9 @@ public async Task> Get(Guid aggregateId, this.SetCache(at, aggregateResult.Data); return Result.Success(aggregate); } - else - { - Logger.Logger.LogWarning($"aggregateResult failed {aggregateResult.Message}"); - return aggregateResult; - } + + Logger.Logger.LogWarning($"aggregateResult failed {aggregateResult.Message}"); + return aggregateResult; } finally {