Skip to content

Reduce ProcessLogonTransaction complexity by extracting logon validation flow#1596

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue
Mar 12, 2026
Merged

Reduce ProcessLogonTransaction complexity by extracting logon validation flow#1596
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

TransactionDomainService.ProcessLogonTransaction exceeded the cyclomatic complexity threshold due to inline branching around logon validation, device enrollment, and response construction. This change keeps the transaction flow intact while moving the branch-heavy logic into focused private helpers.

  • Service refactor

    • Extracted logon validation handling into RecordLogonTransactionValidation(...)
    • Isolated success classification in IsSuccessfulLogonValidation(...)
    • Moved response DTO construction into CreateLogonTransactionResponse(...)
    • Kept the existing behavior for:
      • normal logon success
      • SuccessNeedToAddDevice
      • declined logon validation results
  • Behavior preserved

    • The SuccessNeedToAddDevice path still adds the device to the merchant before locally authorising the transaction.
    • Failure paths still decline locally using the validation response code/message.
  • Test coverage tightened

    • Extended the existing logon test for the device-add branch to assert that the merchant aggregate is fetched and saved when SuccessNeedToAddDevice is returned.
Result<TransactionValidationResult> validationResult =
    await this.TransactionValidationService.ValidateLogonTransaction(
        command.EstateId,
        command.MerchantId,
        command.DeviceIdentifier,
        cancellationToken);

stateResult = await this.RecordLogonTransactionValidation(
    command,
    transactionAggregate,
    validationResult,
    cancellationToken);

return Result.Success(this.CreateLogonTransactionResponse(command, transactionAggregate));

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 ProcessLogonTransaction --nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter ProcessLogonTransaction --nologo --ignore-failed-sources (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj -p:RestoreIgnoreFailedSources=true --nologo (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 TransactionDomainService::ProcessLogonTransaction has a cyclomatic complexity of 13 (limit is 8)</issue_title>
<issue_description>Codacy ID: 3a330c8a4757c4eeb925da8e0b9e2fec

File: TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs
Line: 92
Rule: Complexity (Warning)
Commit: 55441b42edffc1cfa912ad7a0bdb79297748cfa5

Message: Method TransactionDomainService::ProcessLogonTransaction has a cyclomatic complexity of 13 (limit is 8)

**Code Snippet:**
```csharp
        public async Task<Result<ProcessLogonTransactionResponse>> ProcessLogonTransaction(TransactionCommands.ProcessLogonTransactionCommand command, 
```

</issue_description>

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


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: StuartFerguson <[email protected]>
Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity for ProcessLogonTransaction method Reduce ProcessLogonTransaction complexity by extracting logon validation flow Mar 12, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review March 12, 2026 14:04
@StuartFerguson StuartFerguson merged commit 7966906 into master Mar 12, 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 TransactionDomainService::ProcessLogonTransaction has a cyclomatic complexity of 13 (limit is 8)

2 participants