Skip to content

refactor: reduce cyclomatic complexity across multiple modules#1188

Merged
iammukeshm merged 3 commits into
developfrom
fix/complexity-reduction-batch2
Jan 26, 2026
Merged

refactor: reduce cyclomatic complexity across multiple modules#1188
iammukeshm merged 3 commits into
developfrom
fix/complexity-reduction-batch2

Conversation

@iammukeshm
Copy link
Copy Markdown
Member

Summary

Major complexity reduction across 7 files, eliminating all 'Very Complex' and 'Untestable' rated methods.

Changes

File Method Before After
TenantThemeState.cs MapFromDto 52 6
ThemeStateFactory.cs MapFromDto 52 6
TokenRefreshService.cs TryRefreshTokenAsync 39 8
AuditHttpMiddleware.cs InvokeAsync 30 6
EntityDiffBuilder.cs Build 25 5
SmtpMailService.cs SendAsync 19 4
IdentityService.cs ValidateCredentialsAsync 14 5
IdentityService.cs ValidateRefreshTokenAsync 14 5

Techniques Used

  • Extract method refactoring for logical groupings
  • Eliminate code duplication (IdentityService claims building)
  • Single responsibility per method
  • Early returns to reduce nesting

Build Status

0 warnings, 0 errors

jarvis added 3 commits January 26, 2026 01:52
- Extract helper methods in UserService.Lifecycle.cs
- Simplify SearchUsersQueryHandler with extracted methods
- Fixes CA1827 warnings (Count vs Any)
- AssignRolesAsync: 19 → extracted ValidateAdminRoleChangeAsync, ProcessRoleAssignmentsAsync
- GetOrCreateFromPrincipalAsync: 18 → extracted claim handling, user creation helpers
- RegisterAsync: 13 → extracted password validation, email sending, shared helpers

Average complexity: 4.7 → 3.5
High complexity methods: 3 → 0
## Changes

### TenantThemeState.cs & ThemeStateFactory.cs
- MapFromDto: 52 → 6 (extracted MapLightPalette, MapDarkPalette, etc.)

### TokenRefreshService.cs
- TryRefreshTokenAsync: 39 → 8 (extracted cache checks, token validation, claims building)

### AuditHttpMiddleware.cs
- InvokeAsync: 30 → 6 (extracted request/response capture, audit writing)

### EntityDiffBuilder.cs
- Build: 25 → 5 (extracted property change detection, operation determination)

### SmtpMailService.cs
- SendAsync: 19 → 4 (extracted sender/recipient config, attachments)

### IdentityService.cs
- ValidateCredentialsAsync: 14 → 5
- ValidateRefreshTokenAsync: 14 → 5
- Eliminated duplicated claims building logic

## Impact
- Eliminated 6 'Very Complex' and 'Untestable' rated methods
- All refactored methods now ≤10 complexity
- Better testability and maintainability
@iammukeshm iammukeshm merged commit ec25dbb into develop Jan 26, 2026
8 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.

1 participant