Skip to content

Refactor MerchantAggregate.GetMerchant to remove Codacy complexity warning#1685

Merged
StuartFerguson merged 5 commits intomasterfrom
copilot/fix-method-complexity-issue
Mar 18, 2026
Merged

Refactor MerchantAggregate.GetMerchant to remove Codacy complexity warning#1685
StuartFerguson merged 5 commits intomasterfrom
copilot/fix-method-complexity-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

MerchantAggregateExtensions.GetMerchant exceeded the repository's method length limit, making the projection logic harder to scan and maintain. This change reduces the method size without changing the Merchant model it builds.

  • Refactor projection flow

    • Keep GetMerchant focused on:
      • guarding on IsCreated
      • initializing the base Merchant model
      • delegating collection mapping to private helpers
  • Extract collection population helpers

    • Move each collection-specific mapping block into a dedicated private method:
      • addresses
      • contacts
      • operators
      • security users
      • devices
      • contracts
      • opening hours
  • Preserve existing projection behavior

    • Retain the same field assignments and child model construction logic
    • Keep empty collections unset unless corresponding aggregate data exists

Example of the updated shape:

public static Merchant GetMerchant(this MerchantAggregate aggregate) {
    if (aggregate.IsCreated == false) {
        return null;
    }

    Merchant merchantModel = new() {
        EstateId = aggregate.EstateId,
        MerchantId = aggregate.AggregateId,
        MerchantName = aggregate.Name,
        Reference = aggregate.MerchantReference,
        SettlementSchedule = aggregate.SettlementSchedule,
        NextSettlementDueDate = aggregate.NextSettlementDueDate
    };

    aggregate.PopulateAddresses(merchantModel);
    aggregate.PopulateContacts(merchantModel);
    aggregate.PopulateOperators(merchantModel);
    aggregate.PopulateSecurityUsers(merchantModel);
    aggregate.PopulateDevices(merchantModel);
    aggregate.PopulateContracts(merchantModel);
    aggregate.PopulateOpeningHours(merchantModel);

    return merchantModel;
}

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.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --filter MerchantAggregateTests --no-restore -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --filter MerchantAggregateTests -p:RestoreIgnoreFailedSources=true -nologo (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 MerchantAggregateExtensions::GetMerchant has 58 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: 8a464daf55870ac8ac1df0e73569f600

File: TransactionProcessor.Aggregates/MerchantAggregate.cs
Line: 358
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method MerchantAggregateExtensions::GetMerchant has 58 lines of code (limit is 50)

**Code Snippet:**
```csharp
        public static Merchant GetMerchant(this MerchantAggregate aggregate) 
```

</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits March 18, 2026 14:01
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Fix MerchantAggregateExtensions::GetMerchant method size Refactor MerchantAggregate.GetMerchant to remove Codacy complexity warning Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 14:07
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 14:27
@StuartFerguson StuartFerguson merged commit 8d59d0d 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 MerchantAggregateExtensions::GetMerchant has 58 lines of code (limit is 50)

2 participants