Skip to content

Reduce GetTodaysFailedSales cyclomatic complexity by extracting failed-sales query builders#513

Merged
StuartFerguson merged 2 commits intomainfrom
copilot/fix-reportingmanager-cyclomatic-complexity
Mar 17, 2026
Merged

Reduce GetTodaysFailedSales cyclomatic complexity by extracting failed-sales query builders#513
StuartFerguson merged 2 commits intomainfrom
copilot/fix-reportingmanager-cyclomatic-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Codacy flagged ReportingManager.GetTodaysFailedSales for exceeding the cyclomatic complexity limit. This change reduces branching in that method without changing its query flow or response shaping.

  • What changed

    • Extracted the inline failed-sales LINQ queries into dedicated private helpers:
      • BuildTodaysFailedSalesQuery(...)
      • BuildComparisonFailedSalesQuery(...)
    • Kept GetTodaysFailedSales(...) focused on orchestration:
      • resolve context
      • execute today/comparison queries
      • propagate query failures
      • map results into TodaysSales
  • Why this helps

    • Moves predicate-heavy query construction out of the method Codacy analyzes.
    • Aligns the failed-sales path more closely with the existing pattern already used by GetTodaysSales(...).
  • Behavior preserved

    • Same filters:
      • unauthorised transactions only
      • Sale transaction type
      • matching response code
      • comparison date/time window logic unchanged
    • Same error messages and TodaysSales response fields.
  • Example

    IQueryable<Decimal> todaysSalesQuery = this.BuildTodaysFailedSalesQuery(context, request.ResponseCode);
    IQueryable<Decimal> comparisonSalesQuery = this.BuildComparisonFailedSalesQuery(context, request.ComparisonDate, request.ResponseCode);

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 EstateReportingAPI.sln -v minimal (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/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::GetTodaysFailedSales has a cyclomatic complexity of 10 (limit is 8)</issue_title>
<issue_description>

Codacy ID: 77a5a754171d301fd36cca4ab658d193

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

Message: Method ReportingManager::GetTodaysFailedSales has a cyclomatic complexity of 10 (limit is 8)

**Code Snippet:**
```csharp
    public async Task<Result<TodaysSales>> GetTodaysFailedSales(TransactionQueries.TodaysFailedSales request, 
```

</issue_description>

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


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity in GetTodaysFailedSales method Reduce GetTodaysFailedSales cyclomatic complexity by extracting failed-sales query builders Mar 17, 2026
Copilot AI requested a review from StuartFerguson March 17, 2026 14:50
@StuartFerguson StuartFerguson marked this pull request as ready for review March 17, 2026 15:01
@StuartFerguson StuartFerguson merged commit 4498fca into main Mar 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Complexity] Method ReportingManager::GetTodaysFailedSales has a cyclomatic complexity of 10 (limit is 8)

2 participants