ruby-oembed/ruby-oembed

View on GitHub

Showing 20 of 20 total issues

Method http_get has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def http_get(uri, options = {})
      found = false
      remaining_redirects = options[:max_redirects] ? options[:max_redirects].to_i : 4
      until found
        http = Net::HTTP.new(uri.host, uri.port)
Severity: Minor
Found in lib/oembed/http_helper.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 convert_json_to_yaml has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

            def convert_json_to_yaml(json) #:nodoc:
              require 'strscan' unless defined? ::StringScanner
              scanner, quoting, marks, pos = ::StringScanner.new(json), false, [], nil
              scanner.scan_until(/\{/)
              while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
Severity: Minor
Found in lib/oembed/formatter/json/backends/yaml.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 discover_provider has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def discover_provider(url, options = {})
      uri = URI.parse(url)

      res = http_get(uri, options)
      format = options[:format]
Severity: Minor
Found in lib/oembed/provider_discovery.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 convert_json_to_yaml has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

            def convert_json_to_yaml(json) #:nodoc:
              require 'strscan' unless defined? ::StringScanner
              scanner, quoting, marks, pos = ::StringScanner.new(json), false, [], nil
              scanner.scan_until(/\{/)
              while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
Severity: Minor
Found in lib/oembed/formatter/json/backends/yaml.rb - About 1 hr to fix

    Method http_get has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def http_get(uri, options = {})
          found = false
          remaining_redirects = options[:max_redirects] ? options[:max_redirects].to_i : 4
          until found
            http = Net::HTTP.new(uri.host, uri.port)
    Severity: Minor
    Found in lib/oembed/http_helper.rb - About 1 hr to fix

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

          def initialize(endpoint, positional_format = OEmbed::Formatter.default, format: nil, required_query_params: {})
            endpoint_uri = URI.parse(endpoint.gsub(/[\{\}]/,'')) rescue nil
            raise ArgumentError, "The given endpoint isn't a valid http(s) URI: #{endpoint.to_s}" unless endpoint_uri.is_a?(URI::HTTP)
      
            @required_query_params = {}
      Severity: Minor
      Found in lib/oembed/provider.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 test_backend has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def test_backend(backend_module)
              expected = {
                "version"=>1.0,
                "string"=>"test",
                "int"=>42,
      Severity: Minor
      Found in lib/oembed/formatter.rb - About 1 hr to fix

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

              def add_official_provider(provider_class, sub_type=nil, access_token: nil)
                raise TypeError, "Expected OEmbed::Provider instance but was #{provider_class.class}" \
                  unless provider_class.is_a?(OEmbed::Provider)
        
                @@to_register[sub_type.to_s] ||= []
        Severity: Minor
        Found in lib/oembed/providers.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

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

              class << self
                include ::OEmbed::Formatter::Base
                
                # Returns the current JSON backend.
                def backend
        Severity: Minor
        Found in lib/oembed/formatter/json.rb and 1 other location - About 50 mins to fix
        lib/oembed/formatter/xml.rb on lines 8..37

        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

              class << self
                include ::OEmbed::Formatter::Base
                
                # Returns the current XML backend.
                def backend
        Severity: Minor
        Found in lib/oembed/formatter/xml.rb and 1 other location - About 50 mins to fix
        lib/oembed/formatter/json.rb on lines 8..37

        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

              if format.nil? || format == :xml
                # {The specification}[http://oembed.com/#section4] says XML discovery should have
                # type="text/xml+oembed" but some providers use type="application/xml+oembed"
                provider_endpoint ||= /<link[^>]*href=['"]*([^\s'"]+)['"]*[^>]*(application|text)\/xml\+oembed[^>]*>/.match(res)[1] rescue nil
                provider_endpoint ||= /<link[^>]*(application|text)\/xml\+oembed[^>]*href=['"]*([^\s'"]+)['"]*[^>]*>/.match(res)[2] rescue nil
        Severity: Minor
        Found in lib/oembed/provider_discovery.rb and 1 other location - About 40 mins to fix
        lib/oembed/provider_discovery.rb on lines 39..43

        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

              if format.nil? || format == :json
                provider_endpoint ||= /<link[^>]*href=['"]*([^\s'"]+)['"]*[^>]*application\/json\+oembed[^>]*>/.match(res)[1] rescue nil
                provider_endpoint ||= /<link[^>]*application\/json\+oembed[^>]*href=['"]*([^\s'"]+)['"]*[^>]*>/.match(res)[1] rescue nil
                format ||= :json if provider_endpoint
              end
        Severity: Minor
        Found in lib/oembed/provider_discovery.rb and 1 other location - About 40 mins to fix
        lib/oembed/provider_discovery.rb on lines 44..50

        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 backend= has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def backend=(new_backend)
                new_backend_obj = case new_backend
                when String
                  unless already_loaded?(new_backend)
                    load "oembed/formatter/#{backend_path}/#{new_backend.downcase}.rb"
        Severity: Minor
        Found in lib/oembed/formatter/base.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 unregister has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def unregister(*providers)
                providers.each do |provider|
                  provider.urls.each do |url|
                    if @@urls[url].is_a?(Array)
                      @@urls[url].delete(provider)
        Severity: Minor
        Found in lib/oembed/providers.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 test_backend has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def test_backend(new_backend)
                raise LoadError, "The given backend must respond to the decode method: #{new_backend.inspect}" unless new_backend.respond_to?(:decode)
        
                expected = {
                  "version"=>1.0,
        Severity: Minor
        Found in lib/oembed/formatter/base.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

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

              def raw(url, options = {})
                provider = find(url)
                if provider
                  provider.raw(url, options)
                else
        Severity: Minor
        Found in lib/oembed/providers.rb and 1 other location - About 25 mins to fix
        lib/oembed/providers.rb on lines 112..120

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

        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 get(url, options = {})
                provider = find(url)
                if provider
                  provider.get(url, options)
                else
        Severity: Minor
        Found in lib/oembed/providers.rb and 1 other location - About 25 mins to fix
        lib/oembed/providers.rb on lines 98..106

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

        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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def build(url, query = {})
              raise OEmbed::NotFound, url unless include?(url)
        
              query.delete(:timeout)
              query.delete(:max_redirects)
        Severity: Minor
        Found in lib/oembed/provider.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 decode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def decode(format, value)
                supported?(format)
                
                begin
                  case format.to_s
        Severity: Minor
        Found in lib/oembed/formatter.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 find has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def find(url)
                @@urls.keys.each do |url_regexp|
                  next unless url_regexp.match?(url)
        
                  matching_provider = @@urls[url_regexp].detect { |p| p.include?(url) }
        Severity: Minor
        Found in lib/oembed/providers.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