Skip to content

Reduce MerchantDomainService.MakeMerchantDeposit complexity#1676

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-merchant-deposit-complexity
Mar 18, 2026
Merged

Reduce MerchantDomainService.MakeMerchantDeposit complexity#1676
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-merchant-deposit-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

MerchantDomainService.MakeMerchantDeposit exceeded the configured cyclomatic complexity limit due to inline deposit-list retrieval and initialization logic. This change trims the method back under the threshold without changing the deposit flow.

  • Refactor

    • Extracted deposit-list loading and first-use initialization into a private helper: GetOrCreateMerchantDepositList(...)
    • Kept MakeMerchantDeposit(...) focused on the core deposit workflow: validate, make deposit, persist
  • Behavior preservation

    • Preserved existing failure handling by returning the same ResultHelpers.CreateFailure(...) paths from the extracted logic
    • Left deposit creation, duplicate detection, and save behavior unchanged
  • Resulting shape

    • Reduced branching in MakeMerchantDeposit(...)
    • Consolidated the deposit-list precondition logic in one place for reuse and readability
Result<MerchantDepositListAggregate> depositListResult =
    await this.GetOrCreateMerchantDepositList(command, merchantAggregate, cancellationToken);

if (depositListResult.IsFailed)
    return ResultHelpers.CreateFailure(depositListResult);

Result stateResult = depositListResult.Data.MakeDeposit(
    depositSource,
    command.RequestDto.Reference,
    command.RequestDto.DepositDateTime,
    amount);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj --filter VerifyBootstrapperIsValid --no-restore -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter MakeMerchantDeposit --no-restore -nologo (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Complexity] Method MerchantDomainService::MakeMerchantDeposit has a cyclomatic complexity of 9 (limit is 8)</issue_title>
<issue_description>

Codacy ID: 5f170bf1dd1375e8d28d0b69d344c0f8

File: TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs
Line: 342
Rule: Complexity (Warning)
Commit: e1d3fc7ec688a60b6ee82d27f7d53046ba2cdd7f

Message: Method MerchantDomainService::MakeMerchantDeposit has a cyclomatic complexity of 9 (limit is 8)

**Code Snippet:**
```csharp
        public async Task<Result> MakeMerchantDeposit(MerchantCommands.MakeMerchantDepositCommand command, CancellationToken cancellationToken) 
```

</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity in MakeMerchantDeposit method Reduce MerchantDomainService.MakeMerchantDeposit complexity Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 09:59
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 10:08
@StuartFerguson StuartFerguson merged commit f135207 into master Mar 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Complexity] Method MerchantDomainService::MakeMerchantDeposit has a cyclomatic complexity of 9 (limit is 8)

2 participants