mobiledefense/google_safe_browsing

View on GitHub

Showing 14 of 14 total issues

Method receive_data has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

    def self.receive_data(url, list)
      urls = url.split(',')
      url = urls[0]
      mac = urls[1]

Severity: Minor
Found in lib/google_safe_browsing/response_helper.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 receive_data has 101 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.receive_data(url, list)
      urls = url.split(',')
      url = urls[0]
      mac = urls[1]

Severity: Major
Found in lib/google_safe_browsing/response_helper.rb - About 4 hrs to fix

    Method parse_data_response has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.parse_data_response(response)
          ret = {}
    
          ret[:lists] = []
          ret[:data_urls] = {}
    Severity: Minor
    Found in lib/google_safe_browsing/response_helper.rb - About 1 hr to fix

      Method generate_path_strings has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.generate_path_strings(raw_path)
            return ['/', ''] if raw_path == ''
      
            path_split = raw_path.split('?')
            path = path_split[0] || ''
      Severity: Minor
      Found in lib/google_safe_browsing/canonicalize.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 fix_path has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.fix_path(path)
            # remove leading slash
            path = path[1..-1] if path[0..0] == '/'
      
            preserve_trailing_slash = (path[-1..-1] == '/')
      Severity: Minor
      Found in lib/google_safe_browsing/canonicalize.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 squish_number_list has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.squish_number_list(chunks)
            num_strings = []
            streak_begin = last_num = chunks.shift
      
            chunks.each do |c|
      Severity: Minor
      Found in lib/google_safe_browsing/chunk_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 with_keys has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.with_keys(uri)
              begin
                get_keys unless GoogleSafeBrowsing.config.have_keys?
                response = yield uri
              end while self.please_rekey?(response.body)
      Severity: Minor
      Found in lib/google_safe_browsing/http_helper.rb - About 45 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 build_chunk_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.build_chunk_list(*lists)
            lists = if lists.any?
                      lists.to_a
                    else
                      GoogleSafeBrowsing.config.current_lists
      Severity: Minor
      Found in lib/google_safe_browsing/chunk_helper.rb - About 45 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 fix_host has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.fix_host(host)
            # remove leading and trailing dots, multiple dots to one
            host.gsub!(/\A\.+|\.+\Z/, '')
            host.gsub!(/\.+/, '.')
      
      
      Severity: Minor
      Found in lib/google_safe_browsing/canonicalize.rb - About 45 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 deeply nested control flow statements.
      Open

                        if count > 0
                          count.times do |i|
                            sub_attrs[:add_chunk_number] = BinaryHelper.unpack_add_chunk_num(BinaryHelper.read_bytes_from(chunk_iterator, 4))
                            sub_attrs[:prefix] = BinaryHelper.read_bytes_as_hex(chunk_iterator, line_actions[:hash_length])
                            record_sub_shavar_to_insert(sub_attrs)
      Severity: Major
      Found in lib/google_safe_browsing/response_helper.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                          if count > 0
                            count.times do |i|
                              add_attrs[:prefix] = BinaryHelper.read_bytes_as_hex(chunk_iterator, line_actions[:hash_length])
                              record_add_shavar_to_insert(add_attrs)
                            end
        Severity: Major
        Found in lib/google_safe_browsing/response_helper.rb - About 45 mins to fix

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

              def self.split_username_and_password(host_string)
                un_sep = host_string.index('@')
                result = {}
                if un_sep
                  splits = host_string.split('@')
          Severity: Minor
          Found in lib/google_safe_browsing/canonicalize.rb and 1 other location - About 40 mins to fix
          lib/google_safe_browsing/canonicalize.rb on lines 305..316

          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

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

              def self.split_port(host_string)
                port_sep = host_string.rindex(':')
                result = {}
                if port_sep
                  splits = host_string.split(':')
          Severity: Minor
          Found in lib/google_safe_browsing/canonicalize.rb and 1 other location - About 40 mins to fix
          lib/google_safe_browsing/canonicalize.rb on lines 287..298

          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

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

              def self.lookup(url)
                urls = Canonicalize.urls_for_lookup(url.force_encoding('ASCII-8BIT'))
                return nil if urls.empty?
          
                hashes = HashHelper.urls_to_hashes(urls)
          Severity: Minor
          Found in lib/google_safe_browsing/api_v2.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

          Severity
          Category
          Status
          Source
          Language