Skip to content

Reduce StartTransaction complexity in TransactionAggregateExtensions#1690

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue-one-more-time
Mar 18, 2026
Merged

Reduce StartTransaction complexity in TransactionAggregateExtensions#1690
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue-one-more-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

TransactionAggregateExtensions.StartTransaction exceeded the configured cyclomatic complexity limit due to inline validation and state guard logic. This change keeps behavior intact while separating the method into smaller, purpose-specific helpers.

  • What changed

    • Extracted request validation into a dedicated ValidateStartTransactionArguments(...) helper
    • Extracted aggregate state preconditions into CheckCanStartTransaction(...)
    • Left event creation and append flow in StartTransaction(...) so the main path stays linear and easy to follow
  • Why this matters

    • Brings StartTransaction under the complexity threshold without changing domain behavior
    • Makes the method read as: validate input → validate state → emit TransactionHasStartedEvent
  • Resulting shape

    Result result = ValidateStartTransactionArguments(
        transactionDateTime,
        transactionNumber,
        transactionType,
        transactionReference,
        estateId,
        merchantId,
        deviceIdentifier);
    
    if (result.IsFailed)
        return result;
    
    result = CheckCanStartTransaction(aggregate);
    if (result.IsFailed)
        return result;
  • Behavior preserved

    • Existing validation rules for transaction date/time, number, reference, type, estate, merchant, and device identifier remain unchanged
    • Existing guards preventing a transaction from being started twice or after completion remain unchanged
    • Event payload and append behavior are unchanged

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.Tests/TransactionProcessor.Tests.csproj --filter VerifyBootstrapperIsValid --no-restore -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --filter TransactionAggregate_StartTransaction -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.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 TransactionAggregateExtensions::StartTransaction has a cyclomatic complexity of 11 (limit is 8)</issue_title>
<issue_description>Codacy ID: f0db1afda6b8079e9c3b8b89a6d68765

File: TransactionProcessor.Aggregates/TransactionAggregate.cs
Line: 495
Rule: Complexity (Warning)
Commit: d86ddd7f1bcabe1f21d4be000e4eda81d82ca1d5

Message: Method TransactionAggregateExtensions::StartTransaction has a cyclomatic complexity of 11 (limit is 8)

**Code Snippet:**
```csharp
        public static Result StartTransaction(this TransactionAggregate aggregate, 
```

</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.

Copilot AI and others added 2 commits March 18, 2026 17:39
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity of StartTransaction method Reduce StartTransaction complexity in TransactionAggregateExtensions Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 17:44
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 17:46
@StuartFerguson StuartFerguson merged commit 405bc47 into master Mar 18, 2026
6 of 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 TransactionAggregateExtensions::StartTransaction has a cyclomatic complexity of 11 (limit is 8)

2 participants