Skip to content

Reduce StatementBuilder.GetStatementHtml complexity with focused helper extraction#1678

Merged
StuartFerguson merged 4 commits intomasterfrom
copilot/complexity-fix-statementbuilder-html
Mar 18, 2026
Merged

Reduce StatementBuilder.GetStatementHtml complexity with focused helper extraction#1678
StuartFerguson merged 4 commits intomasterfrom
copilot/complexity-fix-statementbuilder-html

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

StatementBuilder.GetStatementHtml exceeded the repository’s line-count complexity threshold. This change trims the method by extracting repeated token-replacement and statement-line rendering logic without changing the public behavior.

  • Refactor GetStatementHtml

    • Moved generic placeholder replacement into a private ReplaceTokens(...) helper.
    • Moved statement row rendering into a private BuildStatementLinesHtml(...) helper.
    • Kept the existing flow intact: validate statement state, load templates, populate header/footer tokens, render lines, then inline CSS assets.
  • Preserve statement line rendering behavior

    • Continue using the cached line template for each row while generating a fresh populated string per statement line.
    • Keep header, footer, and line token replacement logic consistent across the HTML build path.
  • Strengthen focused coverage

    • Extended the existing happy-path StatementBuilderTests assertion set to verify that multiple statement line dates are rendered into the output HTML.

Example of the extracted rendering flow:

mainHtml = this.ReplaceTokens(mainHtml, new {
    StatementTotal = statementLines.Sum(sl => sl.statementLine.Amount),
    TransactionsValue = statementLines.Where(sl => sl.statementLine.LineType == 1).Sum(sl => sl.statementLine.Amount),
    TransactionFeesValue = statementLines.Where(sl => sl.statementLine.LineType == 2).Sum(sl => sl.statementLine.Amount)
});

mainHtml = mainHtml.Replace(
    "[StatementLinesData]",
    await this.BuildStatementLinesHtml(path, statementLines, cancellationToken));

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.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter StatementBuilderTests --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:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Complexity] Method StatementBuilder::GetStatementHtml has 53 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: f151792e9ec95719b92e84c23469105d

File: TransactionProcessor.BusinessLogic/Services/StatementBuilder.cs
Line: 54
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method StatementBuilder::GetStatementHtml has 53 lines of code (limit is 50)

**Code Snippet:**
```csharp
        public async Task<String> GetStatementHtml(MerchantStatementAggregate statementAggregate, 
```

</issue_description>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] [Complexity] Fix method StatementBuilder::GetStatementHtml line count Reduce StatementBuilder.GetStatementHtml complexity with focused helper extraction Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 09:59
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 10:45
@StuartFerguson StuartFerguson merged commit 229c563 into master Mar 18, 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 StatementBuilder::GetStatementHtml has 53 lines of code (limit is 50)

2 participants