zammad/zammad

View on GitHub
lib/twitter_sync.rb

Summary

Maintainability
F
1 wk
Test Coverage

File twitter_sync.rb has 762 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'http/uri'

class TwitterSync

  STATUS_URL_TEMPLATE = 'https://twitter.com/_/status/%s'.freeze
Severity: Major
Found in lib/twitter_sync.rb - About 1 day to fix

    Method process_webhook has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
    Open

      def process_webhook(channel)
        Rails.logger.debug { 'import tweet' }
        ticket = nil
        if @payload['direct_message_events'].present? && channel.options[:sync][:direct_messages][:group_id].present?
          @payload['direct_message_events'].each do |item|
    Severity: Minor
    Found in lib/twitter_sync.rb - About 1 day 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_webhook has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
    Open

      def to_article_webhook(item, user, ticket, channel)
    
        Rails.logger.debug { 'Create article from tweet...' }
        Rails.logger.debug { item.inspect }
        Rails.logger.debug { user.inspect }
    Severity: Minor
    Found in lib/twitter_sync.rb - About 1 day 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_webhook has 155 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def to_article_webhook(item, user, ticket, channel)
    
        Rails.logger.debug { 'Create article from tweet...' }
        Rails.logger.debug { item.inspect }
        Rails.logger.debug { user.inspect }
    Severity: Major
    Found in lib/twitter_sync.rb - About 6 hrs to fix

      Method preferences_cleanup has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.preferences_cleanup(preferences)
      
          # replace Twitter::NullObject with nill to prevent elasticsearch index issue
          preferences.each do |key, value|
      
      
      Severity: Minor
      Found in lib/twitter_sync.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

      Class TwitterSync has 25 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class TwitterSync
      
        STATUS_URL_TEMPLATE = 'https://twitter.com/_/status/%s'.freeze
        DM_URL_TEMPLATE     = 'https://twitter.com/messages/%s'.freeze
      
      
      Severity: Minor
      Found in lib/twitter_sync.rb - About 2 hrs to fix

        Method to_ticket has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

          Method to_user_webhook has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

            def to_user_webhook(user_id, payload_user = nil)
              user_payload = if payload_user && payload_user['id'].to_s == user_id.to_s
                               payload_user
                             else
                               to_user_webhook_data(user_id)
          Severity: Minor
          Found in lib/twitter_sync.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_user_webhook has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def to_user_webhook(user_id, payload_user = nil)
              user_payload = if payload_user && payload_user['id'].to_s == user_id.to_s
                               payload_user
                             else
                               to_user_webhook_data(user_id)
          Severity: Major
          Found in lib/twitter_sync.rb - About 2 hrs to fix

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

              def to_article(tweet, user, ticket, channel)
            
                Rails.logger.debug { 'Create article from tweet...' }
                Rails.logger.debug { tweet.inspect }
                Rails.logger.debug { user.inspect }
            Severity: Major
            Found in lib/twitter_sync.rb - About 2 hrs to fix

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

                def to_user(tweet)
              
                  Rails.logger.debug { 'Create user from tweet...' }
                  Rails.logger.debug { tweet.inspect }
              
              
              Severity: Major
              Found in lib/twitter_sync.rb - About 2 hrs to fix

                Method process_webhook has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def process_webhook(channel)
                    Rails.logger.debug { 'import tweet' }
                    ticket = nil
                    if @payload['direct_message_events'].present? && channel.options[:sync][:direct_messages][:group_id].present?
                      @payload['direct_message_events'].each do |item|
                Severity: Major
                Found in lib/twitter_sync.rb - About 2 hrs to fix

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

                    def to_user(tweet)
                  
                      Rails.logger.debug { 'Create user from tweet...' }
                      Rails.logger.debug { tweet.inspect }
                  
                  
                  Severity: Minor
                  Found in lib/twitter_sync.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 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def to_group(tweet, group_id, channel)
                  
                      Rails.logger.debug { 'import tweet' }
                  
                      ticket = nil
                  Severity: Minor
                  Found in lib/twitter_sync.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 preferences_cleanup has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.preferences_cleanup(preferences)
                  
                      # replace Twitter::NullObject with nill to prevent elasticsearch index issue
                      preferences.each do |key, value|
                  
                  
                  Severity: Minor
                  Found in lib/twitter_sync.rb - About 1 hr to fix

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

                      def locale_sender?(tweet)
                        tweet_user = user(tweet)
                        Channel.where(area: 'Twitter::Account').each do |local_channel|
                          next if !local_channel.options
                          next if !local_channel.options[:user]
                    Severity: Minor
                    Found in lib/twitter_sync.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 get_state has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def get_state(channel, tweet, ticket = nil)
                    
                        user_id = if tweet.is_a?(Hash)
                                    if tweet['user'] && tweet['user']['id']
                                      tweet['user']['id']
                    Severity: Minor
                    Found in lib/twitter_sync.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 to_ticket has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def to_ticket(tweet, user, group_id, channel)
                        UserInfo.current_user_id = user.id
                    
                        Rails.logger.debug { 'Create ticket from tweet...' }
                        Rails.logger.debug { tweet.inspect }
                    Severity: Minor
                    Found in lib/twitter_sync.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

                    Avoid deeply nested control flow statements.
                    Open

                                if local_media['expanded_url'].present?
                                  text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
                                elsif local_media['display_url']
                                  text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
                                end
                    Severity: Major
                    Found in lib/twitter_sync.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  if local_media['expanded_url'].present?
                                    text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
                                  elsif local_media['display_url']
                                    text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
                                  end
                      Severity: Major
                      Found in lib/twitter_sync.rb - About 45 mins to fix

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

                            if user_data[:image_source]
                              avatar = Avatar.add(
                                object:        'User',
                                o_id:          user.id,
                                url:           user_data[:image_source],
                        Severity: Minor
                        Found in lib/twitter_sync.rb and 1 other location - About 50 mins to fix
                        lib/facebook.rb on lines 153..168

                        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 43.

                        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

                              user = User.find(auth.user_id)
                              map = {
                                note:    'description',
                                web:     'url',
                                address: 'location',
                        Severity: Minor
                        Found in lib/twitter_sync.rb and 1 other location - About 45 mins to fix
                        lib/twitter_sync.rb on lines 53..69

                        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 41.

                        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

                              user = User.find(auth.user_id)
                              map = {
                                note:    'description',
                                web:     'website',
                                address: 'location',
                        Severity: Minor
                        Found in lib/twitter_sync.rb and 1 other location - About 45 mins to fix
                        lib/twitter_sync.rb on lines 801..817

                        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 41.

                        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

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

                                  if local_media['url'].present?
                                    if local_media['expanded_url'].present?
                                      text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
                                    elsif local_media['display_url']
                                      text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
                        Severity: Minor
                        Found in lib/twitter_sync.rb and 1 other location - About 40 mins to fix
                        lib/twitter_sync.rb on lines 288..293

                        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 38.

                        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

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

                                  if local_media['url'].present?
                                    if local_media['expanded_url'].present?
                                      text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
                                    elsif local_media['display_url']
                                      text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
                        Severity: Minor
                        Found in lib/twitter_sync.rb and 1 other location - About 40 mins to fix
                        lib/twitter_sync.rb on lines 277..282

                        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 38.

                        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