Skip to content

Refactor GetProductPerformanceReport to satisfy 50-line complexity limit#476

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

Refactor GetProductPerformanceReport to satisfy 50-line complexity limit#476
StuartFerguson merged 3 commits intomainfrom
copilot/refactor-getproductperformancereport

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

GetProductPerformanceReport exceeded Codacy's 50-line method limit at 52 lines. Extracted the LINQ query construction and response mapping into dedicated private helpers.

Changes

  • ProductPerformanceItemData — new private sealed class replacing the anonymous type in the LINQ projection, allowing the query to be extracted into a separate method
  • BuildProductPerformanceQuery — static method encapsulating the transaction/contract join, grouping, and projection logic
  • BuildProductPerformanceResponse — instance method encapsulating the ProductPerformanceResponse + ProductPerformanceSummary mapping

Result

GetProductPerformanceReport reduced from 52 → 18 non-blank lines:

public async Task<Result<ProductPerformanceResponse>> GetProductPerformanceReport(...) {
    using ResolvedDbContext<EstateManagementContext>? resolvedContext = ...;
    await using EstateManagementContext context = resolvedContext.Context;

    var grandTotalAmountQuery = (...);
    var grandTotalAmountResult = await ExecuteQuerySafeSum<decimal>(grandTotalAmountQuery, cancellationToken);
    if (grandTotalAmountResult.IsFailed)
        return ResultHelpers.CreateFailure(grandTotalAmountResult);
    var grandTotalAmount = grandTotalAmountResult.Data;

    var query = BuildProductPerformanceQuery(context, request.StartDate, request.EndDate, grandTotalAmount);
    var queryResult = await ExecuteQuerySafeToList(query, cancellationToken);
    if (queryResult.IsFailed)
        return ResultHelpers.CreateFailure(queryResult);
    var queryResults = queryResult.Data;
    if (queryResults.Any() == false)
        return Result.Success(new ProductPerformanceResponse() { ... });

    return Result.Success(BuildProductPerformanceResponse(queryResults));
}

No behavioural changes.

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 build EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj --configfile EstateReportingAPI/NuGet.Config (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 tcp -m owner --uid-owner 0 -j ACCEPT (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::GetProductPerformanceReport has 81 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: f06650655a3977feb4403779c24efb4c

File: EstateReportingAPI.BusinessLogic/ReportingManager.cs
Line: 1150
Rule: Complexity (Warning)
Commit: 785059dbcdc71b92cbcf8e3aa1c57b8c17b2d2fe

Message: Method ReportingManager::GetProductPerformanceReport has 52 lines of code (limit is 50)

**Code Snippet:**
```csharp
    public async Task<Result<ProductPerformanceResponse>> GetProductPerformanceReport(TransactionQueries.ProductPerformanceQuery request, 
```

</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…-line limit

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor method GetProductPerformanceReport to reduce complexity Refactor GetProductPerformanceReport to satisfy 50-line complexity limit Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 20:11
@StuartFerguson StuartFerguson merged commit 5a76654 into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-getproductperformancereport 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::GetProductPerformanceReport has 81 lines of code (limit is 50)

2 participants