Promact/slack-erp-custom-integration-mvc

View on GitHub
Slack.Automation/Promact.Core.Repository/SlackRepository/SlackRepository.cs

Summary

Maintainability
F
1 wk
Test Coverage

Method LeaveApplyAsync has a Cognitive Complexity of 106 (exceeds 20 allowed). Consider refactoring.
Open

        private async Task<string> LeaveApplyAsync(List<string> slackRequest, SlashCommand leave, string accessToken, string userId)
        {
            try
            {
                LeaveType leaveType;

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

File SlackRepository.cs has 635 lines of code (exceeds 250 allowed). Consider refactoring.
Open

using Promact.Core.Repository.LeaveRequestRepository;
using Promact.Core.Repository.OauthCallsRepository;
using Promact.Erp.DomainModel.ApplicationClass;
using Promact.Erp.DomainModel.ApplicationClass.SlackRequestAndResponse;
using Promact.Erp.DomainModel.Models;

    Method LeaveApplyAsync has 144 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            private async Task<string> LeaveApplyAsync(List<string> slackRequest, SlashCommand leave, string accessToken, string userId)
            {
                try
                {
                    LeaveType leaveType;

      Method LeaveDateDuplicate has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
      Open

              private async Task<bool> LeaveDateDuplicate(string userId, DateTime startDate, DateTime? endDate)
              {
                  int valid = -1;
                  bool validIndicator = false;
                  LeaveRequest lastLeave = new LeaveRequest();

      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

      Method UpdateLeaveAsync has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public async Task UpdateLeaveAsync(SlashChatUpdateResponse leaveResponse)
              {
                  try
                  {
                      _logger.Debug("UpdateLeaveAsync Leave update method");

        Method LeaveRequestAsync has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public async Task LeaveRequestAsync(SlashCommand leave)
                {
                    SlackAction actionType;
                    // method to convert slash command to list of string
                    List<string> slackText = _attachmentRepository.SlackText(leave.Text);

          Method LeaveDateDuplicate has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  private async Task<bool> LeaveDateDuplicate(string userId, DateTime startDate, DateTime? endDate)
                  {
                      int valid = -1;
                      bool validIndicator = false;
                      LeaveRequest lastLeave = new LeaveRequest();

            Method UpdateSickLeaveAsync has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    private async Task<string> UpdateSickLeaveAsync(List<string> slackText, ApplicationUser user, string accessToken)
                    {
                        // checking from oAuth whether user is Admin or not
                        bool isAdmin = await _oauthCallsRepository.UserIsAdminAsync(user.Id, accessToken);
                        _logger.Debug("UpdateSickLeaveAsync user is admin : " + isAdmin);

              Method UpdateSickLeaveAsync has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
              Open

                      private async Task<string> UpdateSickLeaveAsync(List<string> slackText, ApplicationUser user, string accessToken)
                      {
                          // checking from oAuth whether user is Admin or not
                          bool isAdmin = await _oauthCallsRepository.UserIsAdminAsync(user.Id, accessToken);
                          _logger.Debug("UpdateSickLeaveAsync user is admin : " + isAdmin);

              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

              Method LeavesListBySlackUserIdAsync has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      private async Task<string> LeavesListBySlackUserIdAsync(string userId, string accessToken)
                      {
                          // get user details from oAuth server
                          User user = await _oauthCallsRepository.GetUserByUserIdAsync(userId, accessToken);
                          _logger.Debug("LeavesListBySlackUserIdAsync user name : " + user.UserName);

                Avoid deeply nested control flow statements.
                Open

                                                        if (endDateConvertorResult && reJoinDateConvertorResult)
                                                        {
                                                            // Method to check leave's end date is not beyond start date and re-join date is not beyond end date
                                                            bool validDate = ValidDateTimeForLeave(startDate, endDate, reJoinDate);
                                                            if (validDate)

                  Avoid deeply nested control flow statements.
                  Open

                                                          if (newUser.Id != null)
                                                          {
                                                              // Method to check more than one leave cannot be applied on that date
                                                              bool validDate = await LeaveDateDuplicate(newUser.Id, startDate, null);
                                                              if (!validDate)

                    Avoid deeply nested control flow statements.
                    Open

                                                            if (slackRequest.Count > 4)
                                                            {
                                                                isAdmin = await _oauthCallsRepository.UserIsAdminAsync(userId, accessToken);
                                                                _logger.Debug("LeaveApplyAsync User is admin : " + isAdmin);
                                                                if (isAdmin)

                      Avoid deeply nested control flow statements.
                      Open

                                                  if (validDate)
                                                  {
                                                      await _leaveRepository.UpdateLeaveAsync(leave);
                                                      _logger.Debug("UpdateSickLeaveAsync leave updated successfully");
                                                      replyText = string.Format(_stringConstant.ReplyTextForSickLeaveUpdate

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                private async Task<string> SlackLeaveStatusAsync(List<string> slackText, SlashCommand leave, string accessToken)
                                {
                                    // if slackText count is more then 1 then its means that user want to get leave list of someone else
                                    if (slackText.Count > 1)
                                    {
                        Slack.Automation/Promact.Core.Repository/SlackRepository/SlackRepository.cs on lines 514..539

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 258.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                private async Task<string> SlackLeaveListAsync(List<string> slackText, SlashCommand leave, string accessToken)
                                {
                                    // if slackText count is more then 1 then its means that user want to get leave list of someone else
                                    if (slackText.Count > 1)
                                    {
                        Slack.Automation/Promact.Core.Repository/SlackRepository/SlackRepository.cs on lines 573..598

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 258.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                {
                                    _oauthCallsRepository = oauthCallsRepository;
                                    _leaveRepository = leaveRepository;
                                    _clientRepository = clientRepository;
                                    _stringConstant = stringConstant;
                        Slack.Automation/Promact.Core.Repository/TaskMailReportRepository/TaskMailReportRepository.cs on lines 41..53

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 78.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status