Skip to content

Refactor GetRecentMerchants to reduce method LOC below Codacy's 50-line limit#472

Merged
StuartFerguson merged 2 commits intomainfrom
copilot/refactor-get-recent-merchants
Feb 27, 2026
Merged

Refactor GetRecentMerchants to reduce method LOC below Codacy's 50-line limit#472
StuartFerguson merged 2 commits intomainfrom
copilot/refactor-get-recent-merchants

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

ReportingManager.GetRecentMerchants exceeded Codacy's 50-line complexity threshold at ~54 lines of code.

Changes

  • Removed unused query projectionsLastSaleDateTime, LastSale, LastStatement, and EstateReportingId were selected from the DB but never referenced in the mapping logic; removing EstateReportingId also eliminates an unnecessary Estates subquery join
  • Compacted sub-queries — Reformatted AddressInfo from a 9-line expanded anonymous type block and ContactInfo from a single overlong line to consistent 4-line chained expressions
  • Simplified merchant list construction — Replaced foreach + List.Add with a LINQ .Select().ToList(), removing the intermediate recentMerchants variable
// Before: foreach loop with separate Add
var recentMerchants = recentMerchantsResult.Data;
List<Merchant> merchantList = new();
foreach (var merchant in recentMerchants) {
    ...
    merchantList.Add(model);
}

// After: LINQ projection
List<Merchant> merchantList = recentMerchantsResult.Data.Select(merchant => {
    ...
    return model;
}).ToList();

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: /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 EnableCommentTool=true;EnablePlanTool=true] (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/EstateReportingAPI/EstateReportingAPI/EstateReportingAPI/EstateReportingAPI.csproj --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::GetRecentMerchants has 61 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: 6eb82319b7afc2b22ee9b8cd03edb227

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

Message: Method ReportingManager::GetRecentMerchants has 54 lines of code (limit is 50)

**Code Snippet:**
```csharp
    public async Task<Result<List<Merchant>>> GetRecentMerchants(MerchantQueries.GetRecentMerchantsQuery 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.

Copilot AI changed the title [WIP] Refactor GetRecentMerchants method to reduce complexity Refactor GetRecentMerchants to reduce method LOC below Codacy's 50-line limit Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 19:24
@StuartFerguson StuartFerguson merged commit 1472cee into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-get-recent-merchants 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::GetRecentMerchants has 61 lines of code (limit is 50)

2 participants