Skip to content

Remove unused LINQ projections from GetMerchant to resolve Codacy complexity violation#464

Merged
StuartFerguson merged 3 commits into
mainfrom
copilot/refactor-reportingmanager-getmerchant
Feb 27, 2026
Merged

Remove unused LINQ projections from GetMerchant to resolve Codacy complexity violation#464
StuartFerguson merged 3 commits into
mainfrom
copilot/refactor-reportingmanager-getmerchant

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

ReportingManager.GetMerchant exceeded Codacy's 50-line method limit at 52 lines. Four fields were being fetched from the database in the LINQ Select projection but never referenced when constructing the returned Merchant object.

Changes

  • ReportingManager.cs — Drop unused fields from the GetMerchant query projection:
    • LastSaleDateTime
    • LastSale
    • LastStatement
    • EstateReportingId
// Before — selected but never used in the Merchant result mapping
var merchantQuery = context.Merchants.Select(m => new {
    LastSaleDateTime = m.LastSaleDateTime,   // unused
    LastSale = m.LastSaleDate,               // unused
    LastStatement = m.LastStatementGenerated, // unused
    EstateReportingId = context.Estates.Single(e => e.EstateId == m.EstateId).EstateReportingId, // unused
    // ...
});

// After — projection contains only fields consumed by the result
var merchantQuery = context.Merchants.Select(m => new {
    MerchantReportingId = m.MerchantReportingId,
    Name = m.Name,
    CreatedDateTime = m.CreatedDateTime,
    // ...
});

Method reduces from 52 → 48 lines with no change in returned 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: /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)
    • 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::GetMerchant has 53 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: a71ea2c68fb498894dd38d5048760ade

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

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

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

…d complexity

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor GetMerchant method to reduce complexity Remove unused LINQ projections from GetMerchant to resolve Codacy complexity violation Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 18:21
@StuartFerguson StuartFerguson merged commit 0262e7e into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-reportingmanager-getmerchant 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::GetMerchant has 53 lines of code (limit is 50)

2 participants