Skip to content

Refactor ReportingManager.GetContracts to reduce method length below 50-line limit#463

Merged
StuartFerguson merged 3 commits intomainfrom
copilot/refactor-getcontracts-method
Feb 27, 2026
Merged

Refactor ReportingManager.GetContracts to reduce method length below 50-line limit#463
StuartFerguson merged 3 commits intomainfrom
copilot/refactor-getcontracts-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

GetContracts exceeded Codacy's 50-line complexity limit at 73+ lines, mixing query construction, execution, error handling, and model assembly inline.

Changes

  • Extracted 3 private helper methods to isolate the three data-loading and assembly concerns:

    • LoadProductsAsync — queries ContractProducts by contract IDs
    • LoadFeesAsync — queries ContractProductTransactionFees by product IDs
    • BuildContracts — assembles Contract model list from raw data in memory (preserves IsEnabled filter)
  • Added 3 private data classes to replace anonymous types, enabling the helpers to return typed results:

    • ContractBaseData, ContractProductData, ContractFeeData (all with correct nullable string annotations)

Result

GetContracts reduced from ~93 lines to 37 lines. Behavior is unchanged — same queries, same three-step loading pattern, same error propagation.

// Before: 3 inline anonymous-type queries + inline assembly = ~93 lines

// After: clean orchestration only
var contractIds = baseContracts.Select(b => b.ContractId).ToList();
var productsResult = await LoadProductsAsync(context, contractIds, cancellationToken, "...");
if (productsResult.IsFailed) return ResultHelpers.CreateFailure(productsResult);

var productIds = productsResult.Data.Select(p => p.ContractProductId).ToList();
var feesResult = await LoadFeesAsync(context, productIds, cancellationToken, "...");
if (feesResult.IsFailed) return ResultHelpers.CreateFailure(feesResult);

return Result.Success(BuildContracts(baseContracts, productsResult.Data, feesResult.Data));

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 restore /home/REDACTED/work/EstateReportingAPI/EstateReportingAPI/EstateReportingAPI.sln --verbosity quiet (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/EstateReportingAPI/EstateReportingAPI/EstateReportingAPI.sln --packages /tmp/codeql-scratch-f294ada2fef3658c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-f294ada2fef3658c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-f294ada2fef3658c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (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 ReportingManager::GetContracts has 81 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: 2a9f85e2d38ffa1931b633188ae05a0f

File: EstateReportingAPI.BusinessLogic/ReportingManager.cs
Line: 204
Rule: Complexity (Warning)
Commit: c6ec82b8138936189d33b99020db45b30d2d8343

Message: Method ReportingManager::GetContracts has 73 lines of code (limit is 50)

**Code Snippet:**
```csharp
    public async Task<Result<List<Contract>>> GetContracts(ContractQueries.GetContractsQuery request, 
```

</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.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor GetContracts method to reduce complexity Refactor ReportingManager.GetContracts to reduce method length below 50-line limit Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 18:02
@StuartFerguson StuartFerguson merged commit fdfbc22 into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-getcontracts-method branch April 29, 2026 03:36
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 ReportingManager::GetContracts has 81 lines of code (limit is 50)

2 participants