zammad/zammad

View on GitHub
lib/user_agent.rb

Summary

Maintainability
D
2 days
Test Coverage

File user_agent.rb has 463 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'net/http'
require 'net/https'
require 'net/ftp'

class UserAgent
Severity: Minor
Found in lib/user_agent.rb - About 7 hrs to fix

    Method get_http has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.get_http(uri, options)
    
        proxy = options['proxy'] || Setting.get('proxy')
        proxy_no = options['proxy_no'] || Setting.get('proxy_no') || ''
        proxy_no = proxy_no.split(',').map(&:strip) || []
    Severity: Minor
    Found in lib/user_agent.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 process has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.process(request, response, uri, count, params, options) # rubocop:disable Metrics/ParameterLists
        log(uri.to_s, request, response, options)
    
        if !response
          return Result.new(
    Severity: Minor
    Found in lib/user_agent.rb - About 2 hrs to fix

      Method log has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.log(url, request, response, options)
          return if !options[:log]
      
          # request
          request_data = {
      Severity: Minor
      Found in lib/user_agent.rb - About 1 hr to fix

        Method ftp has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.ftp(uri, options)
            host       = uri.host
            filename   = File.basename(uri.path)
            remote_dir = File.dirname(uri.path)
        
        
        Severity: Minor
        Found in lib/user_agent.rb - About 1 hr to fix

          Method get_http has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.get_http(uri, options)
          
              proxy = options['proxy'] || Setting.get('proxy')
              proxy_no = options['proxy_no'] || Setting.get('proxy_no') || ''
              proxy_no = proxy_no.split(',').map(&:strip) || []
          Severity: Minor
          Found in lib/user_agent.rb - About 1 hr to fix

            Method ftp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.ftp(uri, options)
                host       = uri.host
                filename   = File.basename(uri.path)
                remote_dir = File.dirname(uri.path)
            
            
            Severity: Minor
            Found in lib/user_agent.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 process has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def self.process(request, response, uri, count, params, options) # rubocop:disable Metrics/ParameterLists
            Severity: Minor
            Found in lib/user_agent.rb - About 45 mins to fix

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

                def self.set_params(request, params, options)
                  if options[:json]
                    if !request.is_a?(Net::HTTP::Get) # GET requests pass params in query, see 'parse_uri'.
                      request.add_field('Content-Type', 'application/json; charset=utf-8')
                      if params.present?
              Severity: Minor
              Found in lib/user_agent.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

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

                def self.process(request, response, uri, count, params, options) # rubocop:disable Metrics/ParameterLists
                  log(uri.to_s, request, response, options)
              
                  if !response
                    return Result.new(
              Severity: Minor
              Found in lib/user_agent.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 get(url, params, options, count - 1)
              Severity: Major
              Found in lib/user_agent.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                      return Result.new(
                        data:         data,
                        body:         response.body,
                        content_type: response['Content-Type'],
                        success:      true,
                Severity: Major
                Found in lib/user_agent.rb - About 30 mins to fix

                  Method log has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def self.log(url, request, response, options)
                      return if !options[:log]
                  
                      # request
                      request_data = {
                  Severity: Minor
                  Found in lib/user_agent.rb - About 25 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 handled_open_timeout has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def self.handled_open_timeout(tries)
                      tries ||= 1
                  
                      tries.times do |index|
                        yield
                  Severity: Minor
                  Found in lib/user_agent.rb - About 25 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

                  There are no issues that match your filters.

                  Category
                  Status