Skip to content

Reduce LogTemplate.Format cognitive complexity (#592)#604

Merged
ziagham merged 1 commit intoflowsynx:masterfrom
mohin-io:fix/reduce-logtemplate-complexity-592
Oct 29, 2025
Merged

Reduce LogTemplate.Format cognitive complexity (#592)#604
ziagham merged 1 commit intoflowsynx:masterfrom
mohin-io:fix/reduce-logtemplate-complexity-592

Conversation

@mohin-io
Copy link
Copy Markdown
Contributor

@mohin-io mohin-io commented Oct 29, 2025

Summary

  • Refactors LogTemplate.Format into focused helpers to cut the cognitive complexity below the 15 point threshold described in Refactor Method to Reduce Cognitive Complexity #592
  • Documents the new workflow with XML doc comments so maintainers can quickly understand the formatting pipeline
  • keeps the existing log level short-name mapping and localisation behaviour so downstream components remain untouched

Implementation Details

  • Rewrote the formatting loop to iterate characters using a state machine while delegating opening brace detection, closing brace resolution, and character routing to dedicated helpers
  • Introduced HandleOpeningBrace, HandleClosingBrace, AppendCharacter, and GetValueForTerm to encapsulate the responsibilities previously mixed inside Format
  • Added XML documentation summaries to the refactored methods to align with the guidance in CONTRIBUTING.md regarding maintainable, well-documented code
  • Preserved localisation-based error handling by raising the same FlowSynxException when an unknown token is encountered, ensuring compatibility with existing telemetry and alerts

Testing

  • dotnet test (blocked: dotnet CLI is not available in the current CLI environment)

Closes #592.

@mohin-io mohin-io requested review from a team as code owners October 29, 2025 09:33
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@Sakeeb91 Sakeeb91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I spot-checked the refactor in src/FlowSynx.Infrastructure/Logging/LogTemplate.cs and confirmed the helper extraction keeps the original behavior. dotnet build src/FlowSynx.Infrastructure/FlowSynx.Infrastructure.csproj still passes. Only lingering risk is that malformed-token scenarios remain untested, same as before. Merge when ready.

@ziagham ziagham merged commit c53ff9f into flowsynx:master Oct 29, 2025
4 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.

Refactor Method to Reduce Cognitive Complexity

3 participants