Skip to content

Commit ea183fe

Browse files
refactor: extract GetApplicationDisplayAsync to reduce cyclomatic complexity
Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/120d7502-4b83-4516-9ee0-bec924353d8f Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
1 parent a99e6b6 commit ea183fe

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

SecurityService.BusinessLogic/RequestHandlers/GrantRequestHandler.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,34 @@ public async Task<Result<List<GrantDetails>>> Handle(SecurityServiceQueries.GetU
5151
}
5252

5353
var applicationId = await this._authorizationManager.GetApplicationIdAsync(authorization, cancellationToken);
54-
object? application = string.IsNullOrWhiteSpace(applicationId) ? null : await this._applicationManager.FindByIdAsync(applicationId, cancellationToken);
55-
var clientId = application is null ? string.Empty : await this._applicationManager.GetClientIdAsync(application, cancellationToken) ?? string.Empty;
56-
var displayName = application is null ? clientId : await this._applicationManager.GetDisplayNameAsync(application, cancellationToken) ?? clientId;
54+
var (clientId, displayName) = await this.GetApplicationDisplayAsync(applicationId, cancellationToken);
5755

5856
return new GrantDetails(
5957
authorizationId,
6058
clientId,
61-
string.IsNullOrWhiteSpace(displayName) ? clientId : displayName,
59+
displayName,
6260
await this._authorizationManager.GetScopesAsync(authorization, cancellationToken),
6361
await this._authorizationManager.GetCreationDateAsync(authorization, cancellationToken));
6462
}
6563

64+
private async Task<(string clientId, string displayName)> GetApplicationDisplayAsync(string? applicationId, CancellationToken cancellationToken)
65+
{
66+
if (string.IsNullOrWhiteSpace(applicationId))
67+
{
68+
return (string.Empty, string.Empty);
69+
}
70+
71+
var application = await this._applicationManager.FindByIdAsync(applicationId, cancellationToken);
72+
if (application is null)
73+
{
74+
return (string.Empty, string.Empty);
75+
}
76+
77+
var clientId = await this._applicationManager.GetClientIdAsync(application, cancellationToken) ?? string.Empty;
78+
var displayName = await this._applicationManager.GetDisplayNameAsync(application, cancellationToken) ?? clientId;
79+
return (clientId, string.IsNullOrWhiteSpace(displayName) ? clientId : displayName);
80+
}
81+
6682
public async Task<Result> Handle(SecurityServiceCommands.RevokeGrantCommand command, CancellationToken cancellationToken)
6783
{
6884
var authorization = await this._authorizationManager.FindByIdAsync(command.AuthorizationId, cancellationToken);

0 commit comments

Comments
 (0)