Skip to content

Reduce EstateDomainService.CreateEstateUser complexity by extracting user creation helpers#1691

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-estate-user-complexity
Mar 18, 2026
Merged

Reduce EstateDomainService.CreateEstateUser complexity by extracting user creation helpers#1691
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-estate-user-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

EstateDomainService.CreateEstateUser exceeded the configured cyclomatic complexity limit due to inline request construction and security-user lookup flow. This change keeps the behavior intact while splitting those branches into focused private helpers.

  • Service refactor

    • Extract BuildEstateUserRequest(...) to isolate request assembly, role override handling, and estate claim assignment.
    • Extract CreateEstateSecurityUser(...) to encapsulate the CreateUser + GetUsers sequence and null-user failure path.
    • Keep CreateEstateUser(...) focused on orchestration: build request, create/fetch user, load aggregate, attach user, save aggregate.
  • Behavior preserved

    • EstateRoleName environment override continues to drive the assigned role.
    • The estateId claim is still added to the security user request.
    • Existing failure handling remains unchanged for user creation, user lookup, aggregate load, aggregate state changes, and save operations.
  • Focused coverage

    • Add a targeted estate-domain-service test that captures the outbound CreateUserRequest and verifies the role override and estateId claim are still present after the refactor.
CreateUserRequest createUserRequest = this.BuildEstateUserRequest(command);

Result<UserDetails> getUserResult = await this.CreateEstateSecurityUser(createUserRequest, cancellationToken);
if (getUserResult.IsFailed)
    return ResultHelpers.CreateFailure(getUserResult);

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.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter EstateDomainService_ --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)

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 EstateDomainService::CreateEstateUser has a cyclomatic complexity of 9 (limit is 8)</issue_title>
<issue_description>Codacy ID: 3c8f61353ad57c3379fe216c3486ad3b

File: TransactionProcessor.BusinessLogic/Services/EstateDomainService.cs
Line: 110
Rule: Complexity (Warning)
Commit: bb0ac18ecf66806b85ca2df08d1633ceaae9e508

Message: Method EstateDomainService::CreateEstateUser has a cyclomatic complexity of 9 (limit is 8)

**Code Snippet:**
```csharp
        public async Task<Result> CreateEstateUser(EstateCommands.CreateEstateUserCommand command, CancellationToken cancellationToken) 
```

</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity of CreateEstateUser method Reduce EstateDomainService.CreateEstateUser complexity by extracting user creation helpers Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 18:27
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 18:27
@StuartFerguson StuartFerguson merged commit 98b4b49 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Complexity] Method EstateDomainService::CreateEstateUser has a cyclomatic complexity of 9 (limit is 8)

2 participants