Skip to content

Reduce GetStatement complexity in MerchantStatementForDateAggregateExtensions#1669

Merged
StuartFerguson merged 4 commits intomasterfrom
copilot/complexity-fix-get-statement
Mar 17, 2026
Merged

Reduce GetStatement complexity in MerchantStatementForDateAggregateExtensions#1669
StuartFerguson merged 4 commits intomasterfrom
copilot/complexity-fix-get-statement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Codacy flagged MerchantStatementForDateAggregateExtensions.GetStatement for exceeding the method line limit. This change keeps the existing statement projection behavior intact while reducing the method to a small coordinator.

  • Refactor statement line projection

    • Extract the repeated line-building loops from GetStatement into a private generic helper.
    • Centralize MerchantStatementLine construction in a single factory method.
  • Replace implicit line type literals

    • Introduce private named constants for transaction, settled fee, deposit, and withdrawal line types.
    • Keep the existing serialized values unchanged while making the mapping easier to scan.
  • Add focused regression coverage

    • Add a test that exercises GetStatement(true) with all four line sources and asserts the expected line types, amounts, and timestamps.

Example of the refactored shape:

if (includeStatementLines)
{
    merchantStatement.AddStatementLines(aggregate.Transactions, transaction => transaction.Amount, transaction => transaction.DateTime, TransactionLineType);
    merchantStatement.AddStatementLines(aggregate.SettledFees, settledFee => settledFee.Amount, settledFee => settledFee.DateTime, SettledFeeLineType);
    merchantStatement.AddStatementLines(aggregate.Deposits, deposit => deposit.Amount, deposit => deposit.DepositDateTime, DepositLineType);
    merchantStatement.AddStatementLines(aggregate.Withdrawals, withdrawal => withdrawal.Amount, withdrawal => withdrawal.WithdrawalDateTime, WithdrawalLineType);
}

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 /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --filter MerchantStatementForDateAggregateTests -nologo (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/TransactionProcessor/TransactionProcessor/TransactionProcessor.sln --packages /tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-7ae8d40573b4aa77/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 MerchantStatementForDateAggregateExtensions::GetStatement has 57 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: 88759db3bac3fc19812580332a838109

File: TransactionProcessor.Aggregates/MerchantStatementForDateAggregate.cs
Line: 163
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method MerchantStatementForDateAggregateExtensions::GetStatement has 57 lines of code (limit is 50)

**Code Snippet:**
```csharp
    public static MerchantStatementForDate GetStatement(this MerchantStatementForDateAggregate aggregate, Boolean includeStatementLines = false) 
```

</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 and others added 2 commits March 17, 2026 14:48
Copilot AI changed the title [WIP] [Complexity] Fix method length in GetStatement for MerchantStatementForDate Reduce GetStatement complexity in MerchantStatementForDateAggregateExtensions Mar 17, 2026
Copilot AI requested a review from StuartFerguson March 17, 2026 14:53
@StuartFerguson StuartFerguson marked this pull request as ready for review March 17, 2026 15:02
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot build failed can you have a look please

Co-authored-by: StuartFerguson <[email protected]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 17, 2026

@copilot build failed can you have a look please

Fixed in 3d63a8c. The PR build was failing because the new test referenced TestData.EventId2, EventId3, and EventId4, which do not exist. I replaced those with locally generated event IDs in the test so the project compiles again.

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 /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --no-restore -nologo (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/TransactionProcessor/TransactionProcessor/TransactionProcessor.sln --packages /tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-7ae8d40573b4aa77/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:

@StuartFerguson StuartFerguson merged commit f6f2a1e into master Mar 17, 2026
7 checks passed
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 MerchantStatementForDateAggregateExtensions::GetStatement has 57 lines of code (limit is 50)

2 participants