dysania/onebox

View on GitHub

Showing 57 of 57 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 data has a Cognitive Complexity of 37 (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

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

    def self.fetch_response(location, limit = nil, domain = nil, headers = nil)

      limit ||= 5
      limit = Onebox.options.redirect_limit if limit > Onebox.options.redirect_limit

Severity: Minor
Found in lib/onebox/helpers.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 default_allowed_domains has 116 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

    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

    Class AllowlistedGenericOnebox has 31 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 3 hrs to fix

      File allowlisted_generic_onebox.rb has 320 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 3 hrs to fix

        Method paste_key has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

              def paste_key
                if uri.path =~ /\/raw\//
                  match = uri.path.match(/\/raw\/([^\/]+)/)
                  return match[1] if match && match[1]
                elsif uri.path =~ /\/download\//
        Severity: Minor
        Found in lib/onebox/engine/pastebin_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 data has 67 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 67 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 @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 raw has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                  def raw
                    return @raw if @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 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 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 data has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

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

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

                        def process_html(html)
                          return "" unless html
                    
                          if @options[:max_width]
                            doc = Nokogiri::HTML::fragment(html)
                    Severity: Minor
                    Found in lib/onebox/preview.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