Slack.Automation/Promact.Core.Repository/ExternalLoginRepository/OAuthLoginRepository.cs
Method AddSlackUserInformationAsync
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public async Task AddSlackUserInformationAsync(string code)
{
string slackOAuthRequest = string.Format(_stringConstant.SlackOauthRequestUrl, _envVariableRepository.SlackOAuthClientId, _envVariableRepository.SlackOAuthClientSecret, code);
string slackOAuthResponse = await _httpClientService.GetAsync(_stringConstant.OAuthAcessUrl, slackOAuthRequest, null, _stringConstant.Bearer);
SlackOAuthResponse slackOAuth = JsonConvert.DeserializeObject<SlackOAuthResponse>(slackOAuthResponse);
Method AddSlackUserInformationAsync
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
Open
public async Task AddSlackUserInformationAsync(string code)
{
string slackOAuthRequest = string.Format(_stringConstant.SlackOauthRequestUrl, _envVariableRepository.SlackOAuthClientId, _envVariableRepository.SlackOAuthClientSecret, code);
string slackOAuthResponse = await _httpClientService.GetAsync(_stringConstant.OAuthAcessUrl, slackOAuthRequest, null, _stringConstant.Bearer);
SlackOAuthResponse slackOAuth = JsonConvert.DeserializeObject<SlackOAuthResponse>(slackOAuthResponse);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
Open
foreach (var channel in groups.Groups)
{
_logger.Info("Group:" + channel);
await AddChannelGroupAsync(channel);
_logger.Debug("Slack User Id : " + (await _userManager.FindByEmailAsync(applicationUser.Email)).SlackUserId);
Avoid deeply nested control flow statements. Open
Open
foreach (var channel in channels.Channels)
{
_logger.Info("Channel:" + channel);
await AddChannelGroupAsync(channel);
}