Skip to content

Refactor GetContracts to reduce method length and isolate contract/product mapping#1664

Merged
StuartFerguson merged 4 commits intomasterfrom
copilot/fix-complexity-transactionprocessorgetcontracts
Mar 17, 2026
Merged

Refactor GetContracts to reduce method length and isolate contract/product mapping#1664
StuartFerguson merged 4 commits intomasterfrom
copilot/fix-complexity-transactionprocessorgetcontracts

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

TransactionProcessorReadModelRepository.GetContracts exceeded the configured complexity threshold due to inline contract aggregation and product mapping logic. This change narrows the method to query orchestration and moves the row-to-model assembly into focused private helpers.

  • Reduce GetContracts method size

    • Extracted contract lookup/creation into GetOrCreateContract(...)
    • Extracted product attachment logic into AddProductIfRequired(...)
    • Left the query shape and returned model structure unchanged
  • Isolate contract assembly concerns

    • Centralized creation of ContractModel from joined estate/contract/operator data
    • Kept product de-duplication logic in a single place instead of embedding it in the main loop
  • Harden left-join handling

    • The method already uses a left join for contract products; the new helper exits early when the joined product is absent, so product handling no longer depends on inline null-sensitive access
foreach (var contractData in query)
{
    ContractModel contract = this.GetOrCreateContract(
        contracts,
        contractData.Estate,
        contractData.Contract,
        contractData.Operator);

    this.AddProductIfRequired(contract, contractData.Product);
}

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 TransactionProcessorManager_GetContracts_ContractAreReturned -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Repository/TransactionProcessor.Repository.csproj --no-restore -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 TransactionProcessorReadModelRepository::GetContracts has 55 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: 215b21761a36ae893b8ff641012d2672

File: TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs
Line: 842
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method TransactionProcessorReadModelRepository::GetContracts has 55 lines of code (limit is 50)

**Code Snippet:**
```csharp
        public async Task<Result<List<ContractModel>>> GetContracts(Guid estateId, 
```

</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 17, 2026 13:17
Copilot AI changed the title [WIP] [Complexity] Fix method length of GetContracts in TransactionProcessorReadModelRepository Refactor GetContracts to reduce method length and isolate contract/product mapping Mar 17, 2026
Copilot AI requested a review from StuartFerguson March 17, 2026 13:22
@StuartFerguson StuartFerguson marked this pull request as ready for review March 17, 2026 13:27
@StuartFerguson StuartFerguson merged commit 585822b into master Mar 17, 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 TransactionProcessorReadModelRepository::GetContracts has 55 lines of code (limit is 50)

2 participants