dysania/onebox

View on GitHub

Showing 55 of 55 total issues

Method data has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

      def data
        paras = []
        text = ""

        # Detect section Hash in the url and retrive the related paragraphs. if no hash provided the first few paragraphs will be used
Severity: Minor
Found in lib/onebox/engine/wikipedia_onebox.rb - About 6 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 fetch_response has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    def self.fetch_response(location, redirect_limit: 5, domain: nil, headers: nil, body_cacher: nil)
      redirect_limit = Onebox.options.redirect_limit if redirect_limit > Onebox.options.redirect_limit

      raise Net::HTTPError.new('HTTP redirect too deep', location) if redirect_limit == 0

Severity: Minor
Found in lib/onebox/helpers.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 data has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

      def data
        og = ::Onebox::OpenGraph.new(raw)

        if raw.at_css('#dp.book_mobile') # printed books
          title = raw.at("h1#title")&.inner_text
Severity: Minor
Found in lib/onebox/engine/amazon_onebox.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 resolve_url! has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

      def resolve_url!
        @streetview = false
        type, match = match_url

        # Resolve shortened URL, if necessary
Severity: Minor
Found in lib/onebox/engine/google_maps_onebox.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

Class AllowlistedGenericOnebox has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

    class AllowlistedGenericOnebox
      include Engine
      include StandardEmbed
      include LayoutSupport

Severity: Minor
Found in lib/onebox/engine/allowlisted_generic_onebox.rb - About 4 hrs to fix

    Method default_allowed_domains has 108 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def self.default_allowed_domains
            %w(
              23hq.com
              500px.com
              8tracks.com
    Severity: Major
    Found in lib/onebox/engine/allowlisted_generic_onebox.rb - About 4 hrs to fix

      File allowlisted_generic_onebox.rb has 335 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'htmlentities'
      
      module Onebox
        module Engine
          class AllowlistedGenericOnebox
      Severity: Minor
      Found in lib/onebox/engine/allowlisted_generic_onebox.rb - About 4 hrs to fix

        Method calc_range has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
        Open

                def calc_range(m, contents_lines_size)
                  truncated = false
                  from = /\d+/.match(m[:from])             #get numeric should only match a positive interger
                  to   = /\d+/.match(m[:to])               #get numeric should only match a positive interger
                  range_provided = !(from.nil? && to.nil?) #true if "from" or "to" provided in URL
        Severity: Minor
        Found in lib/onebox/mixins/git_blob_onebox.rb - About 3 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 data has 69 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def data
                og = ::Onebox::OpenGraph.new(raw)
        
                if raw.at_css('#dp.book_mobile') # printed books
                  title = raw.at("h1#title")&.inner_text
        Severity: Major
        Found in lib/onebox/engine/amazon_onebox.rb - About 2 hrs to fix

          Method resolve_url! has 66 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def resolve_url!
                  @streetview = false
                  type, match = match_url
          
                  # Resolve shortened URL, if necessary
          Severity: Major
          Found in lib/onebox/engine/google_maps_onebox.rb - About 2 hrs to fix

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

                  def raw
                    return @raw if defined?(@raw)
            
                    og = get_opengraph
                    twitter = get_twitter
            Severity: Minor
            Found in lib/onebox/engine/standard_embed.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 raw has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                    def raw
                      return @raw if defined?(@raw)
            
                      m = @url.match(self.raw_regexp)
            
            
            Severity: Minor
            Found in lib/onebox/mixins/git_blob_onebox.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 extract has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                def extract(doc)
                  return {} if Onebox::Helpers::blank?(doc)
            
                  data = {}
            
            
            Severity: Minor
            Found in lib/onebox/open_graph.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 data has 60 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def data
                    paras = []
                    text = ""
            
                    # Detect section Hash in the url and retrive the related paragraphs. if no hash provided the first few paragraphs will be used
            Severity: Major
            Found in lib/onebox/engine/wikipedia_onebox.rb - About 2 hrs to fix

              Class TwitterStatusOnebox has 21 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class TwitterStatusOnebox
                    include Engine
                    include LayoutSupport
                    include HTML
              
              
              Severity: Minor
              Found in lib/onebox/engine/twitter_status_onebox.rb - About 2 hrs to fix

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

                      def data
                        @data ||= begin
                          html_entities = HTMLEntities.new
                          d = { link: link }.merge(raw)
                
                
                Severity: Major
                Found in lib/onebox/engine/allowlisted_generic_onebox.rb - About 2 hrs to fix

                  Method fetch_response has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def self.fetch_response(location, redirect_limit: 5, domain: nil, headers: nil, body_cacher: nil)
                        redirect_limit = Onebox.options.redirect_limit if redirect_limit > Onebox.options.redirect_limit
                  
                        raise Net::HTTPError.new('HTTP redirect too deep', location) if redirect_limit == 0
                  
                  
                  Severity: Minor
                  Found in lib/onebox/helpers.rb - About 1 hr to fix

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

                          def get_oembed_url
                            oembed_url = nil
                    
                            StandardEmbed.oembed_providers.each do |regexp, endpoint|
                              if url =~ regexp
                    Severity: Minor
                    Found in lib/onebox/engine/standard_embed.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 calc_range has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            def calc_range(m, contents_lines_size)
                              truncated = false
                              from = /\d+/.match(m[:from])             #get numeric should only match a positive interger
                              to   = /\d+/.match(m[:to])               #get numeric should only match a positive interger
                              range_provided = !(from.nil? && to.nil?) #true if "from" or "to" provided in URL
                    Severity: Minor
                    Found in lib/onebox/mixins/git_blob_onebox.rb - About 1 hr to fix

                      Method fetch_html_doc has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def self.fetch_html_doc(url, headers = nil, body_cacher = nil)
                            response = (fetch_response(url, headers: headers, body_cacher: body_cacher) rescue nil)
                            doc = Nokogiri::HTML(response)
                            uri = Addressable::URI.parse(url)
                      
                      
                      Severity: Minor
                      Found in lib/onebox/helpers.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

                      Severity
                      Category
                      Status
                      Source
                      Language