Skip to content

Refactor GetTransactionDetailReport to reduce cyclomatic complexity below 50-line limit#473

Merged
StuartFerguson merged 3 commits intomainfrom
copilot/refactor-get-transaction-detail-report
Feb 27, 2026
Merged

Refactor GetTransactionDetailReport to reduce cyclomatic complexity below 50-line limit#473
StuartFerguson merged 3 commits intomainfrom
copilot/refactor-get-transaction-detail-report

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

ReportingManager.GetTransactionDetailReport had 85 lines, exceeding Codacy's 50-line complexity limit. The method mixed query construction, filter application, and result mapping inline.

Changes

  • TransactionDetailQueryResult — private sealed class replacing the anonymous LINQ projection type, enabling the query to be split across methods
  • BuildTransactionDetailBaseQuery — extracts the multi-join LINQ query and projection
  • ApplyTransactionDetailFilters — extracts the optional merchant/product/operator Where clauses
  • MapToTransactionDetailResponse — extracts the result-to-DTO mapping and summary computation

GetTransactionDetailReport is now 18 lines with identical behavior:

public async Task<Result<TransactionDetailReportResponse>> GetTransactionDetailReport(...) {
    using var resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
    await using EstateManagementContext context = resolvedContext.Context;

    var query = ApplyTransactionDetailFilters(BuildTransactionDetailBaseQuery(context, request.Request), request.Request);
    var queryResult = await ExecuteQuerySafeToList(query, cancellationToken, "Error retrieving transaction details report");

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

    var queryResults = queryResult.Data;

    if (queryResults.Any() == false)
        return new TransactionDetailReportResponse { Summary = new TransactionDetailSummary(), Transactions = new List<TransactionDetail>() };

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

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 essLogic/RequestHandlers/TransactionRequestHandler.cs essLogic/RequestHandlers/ContractRequestHandler.cs (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 port�� portingAPI.BusinessLogic/RequestHandlers/TransactionRequestHandler.cs portingAPI.BusinessLogic/RequestHandlers/ContractRequestHandler.cs (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::GetTransactionDetailReport has 85 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: 89133ed4f382bc12e1e9b446495e7c1f

File: EstateReportingAPI.BusinessLogic/ReportingManager.cs
Line: 666
Rule: Complexity (Warning)
Commit: 354e1eb5e549b0a7408c451d7868d2a3616b8682

Message: Method ReportingManager::GetTransactionDetailReport has 70 lines of code (limit is 50)

**Code Snippet:**
```csharp
    public async Task<Result<TransactionDetailReportResponse>> GetTransactionDetailReport(TransactionQueries.TransactionDetailReportQuery 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.

…o 18 lines

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor GetTransactionDetailReport method to reduce complexity Refactor GetTransactionDetailReport to reduce cyclomatic complexity below 50-line limit Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 20:15
@StuartFerguson StuartFerguson merged commit 4aa6a56 into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-get-transaction-detail-report 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::GetTransactionDetailReport has 85 lines of code (limit is 50)

2 participants