zammad/zammad

View on GitHub
lib/telegram_helper.rb

Summary

Maintainability
F
6 days
Test Coverage

File telegram_helper.rb has 645 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'telegram/bot'

class TelegramHelper

  attr_accessor :client
Severity: Major
Found in lib/telegram_helper.rb - About 1 day to fix

    Method to_article has 199 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def to_article(params, user, ticket, channel, article = nil)
    
        if article
          Rails.logger.debug { 'Update article from message...' }
        else
    Severity: Major
    Found in lib/telegram_helper.rb - About 7 hrs to fix

      Method to_article has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

        def to_article(params, user, ticket, channel, article = nil)
      
          if article
            Rails.logger.debug { 'Update article from message...' }
          else
      Severity: Minor
      Found in lib/telegram_helper.rb - About 5 hrs to fix

      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 to_group has 125 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def to_group(params, group_id, channel)
          # begin import
          Rails.logger.debug { 'import message' }
      
          # map channel_post params to message
      Severity: Major
      Found in lib/telegram_helper.rb - About 5 hrs to fix

        Method to_ticket has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
        Open

          def to_ticket(params, user, group_id, channel)
            UserInfo.current_user_id = user.id
        
            Rails.logger.debug { 'Create ticket from message...' }
            Rails.logger.debug { params.inspect }
        Severity: Minor
        Found in lib/telegram_helper.rb - About 4 hrs to fix

        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 message_id has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.message_id(params)
            message_id = nil
            %i[message edited_message].each do |key|
              next if !params[key]
              next if !params[key][:message_id]
        Severity: Minor
        Found in lib/telegram_helper.rb - About 2 hrs to fix

        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 to_group has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          def to_group(params, group_id, channel)
            # begin import
            Rails.logger.debug { 'import message' }
        
            # map channel_post params to message
        Severity: Minor
        Found in lib/telegram_helper.rb - About 2 hrs to fix

        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 to_ticket has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def to_ticket(params, user, group_id, channel)
            UserInfo.current_user_id = user.id
        
            Rails.logger.debug { 'Create ticket from message...' }
            Rails.logger.debug { params.inspect }
        Severity: Major
        Found in lib/telegram_helper.rb - About 2 hrs to fix

          Method bot_duplicate? has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.bot_duplicate?(bot_id, channel_id = nil)
              Channel.where(area: 'Telegram::Bot').each do |channel|
                next if !channel.options
                next if !channel.options[:bot]
                next if !channel.options[:bot][:id]
          Severity: Minor
          Found in lib/telegram_helper.rb - About 1 hr to fix

          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 create_or_update_channel has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.create_or_update_channel(token, params, channel = nil)
          
              # verify token
              bot = check_token(token)
          
          
          Severity: Minor
          Found in lib/telegram_helper.rb - About 1 hr to fix

            Method to_user has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def to_user(params)
                Rails.logger.debug { 'Create user from message...' }
                Rails.logger.debug { params.inspect }
            
                # do message_user lookup
            Severity: Minor
            Found in lib/telegram_helper.rb - About 1 hr to fix

              Method bot_by_bot_id has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.bot_by_bot_id(bot_id)
                  Channel.where(area: 'Telegram::Bot').each do |channel|
                    next if !channel.options
                    next if !channel.options[:bot]
                    next if !channel.options[:bot][:id]
              Severity: Minor
              Found in lib/telegram_helper.rb - About 1 hr to fix

              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 create_or_update_channel has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.create_or_update_channel(token, params, channel = nil)
              
                  # verify token
                  bot = check_token(token)
              
              
              Severity: Minor
              Found in lib/telegram_helper.rb - About 55 mins to fix

              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 to_article has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def to_article(params, user, ticket, channel, article = nil)
              Severity: Minor
              Found in lib/telegram_helper.rb - About 35 mins to fix

                Method to_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def to_user(params)
                    Rails.logger.debug { 'Create user from message...' }
                    Rails.logger.debug { params.inspect }
                
                    # do message_user lookup
                Severity: Minor
                Found in lib/telegram_helper.rb - About 35 mins to fix

                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 too many return statements within this method.
                Open

                      return article
                Severity: Major
                Found in lib/telegram_helper.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                        return if !ticket
                  Severity: Major
                  Found in lib/telegram_helper.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                          return
                    Severity: Major
                    Found in lib/telegram_helper.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                            return if !channel.options[:goodbye]
                      Severity: Major
                      Found in lib/telegram_helper.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                              return article
                        Severity: Major
                        Found in lib/telegram_helper.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                return
                          Severity: Major
                          Found in lib/telegram_helper.rb - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status