prismicio/ruby-kit

View on GitHub

Showing 46 of 46 total issues

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

    function() {
        $(this).parent().nextAll('.source_code').slideUp(100);
        $(this).text("View source");
    });
Severity: Minor
Found in docs/js/app.js and 1 other location - About 50 mins to fix
docs/js/app.js on lines 10..13

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

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 initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        def initialize(url, width, height, alt, copyright, link_to)
Severity: Minor
Found in lib/prismic/fragments/image.rb - About 45 mins to fix

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

      $('#toc .hide_toc').toggle(function() {
        $('#toc .top').slideUp('fast');
        $('#toc').toggleClass('hidden');
        $('#toc .title small').toggle();
      }, function() {
    Severity: Minor
    Found in docs/js/app.js and 1 other location - About 45 mins to fix
    docs/js/app.js on lines 169..173

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

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

        def self.get(url, access_token=nil, http_client=Prismic::DefaultHTTPClient, api_cache=Prismic::DefaultCache)
          data = {}
          data['access_token'] = access_token if access_token
          cache_key = url + (access_token ? ('#' + access_token) : '')
          api_cache.get_or_set(cache_key, nil, 5) {
    Severity: Minor
    Found in lib/prismic/api.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 document_link_parser has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def document_link_parser(json)
            doc = json['value']['document']
            type = doc['type']
            fragments = {}
            if doc['data'] and doc['data'][type]
    Severity: Minor
    Found in lib/prismic/json_parsers.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 set has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def set(field_name, value)
          field = @form.fields[field_name]
          unless value == nil
            if value == ""
              data[field_name] = nil
    Severity: Minor
    Found in lib/prismic.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

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

      }, function() {
        $('#toc .top').slideDown('fast');
        $('#toc').toggleClass('hidden');
        $('#toc .title small').toggle();
      });
    Severity: Minor
    Found in docs/js/app.js and 1 other location - About 45 mins to fix
    docs/js/app.js on lines 165..169

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

    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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def initialize(url, name, kind, size, target = nil)
    Severity: Minor
    Found in lib/prismic/fragments/link.rb - About 35 mins to fix

      Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def initialize(embed_type, provider, url, html, o_embed_json)
      Severity: Minor
      Found in lib/prismic/fragments/embed.rb - About 35 mins to fix

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def initialize(id, ref, label, is_master = false, scheduled_at = nil)
        Severity: Minor
        Found in lib/prismic.rb - About 35 mins to fix

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

                  $(this).parent().prev().height($(this).parent().height());
          Severity: Minor
          Found in docs/js/app.js and 1 other location - About 35 mins to fix
          docs/js/app.js on lines 42..42

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

          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

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

                  $(this).parent().prev().height($(this).parent().height());
          Severity: Minor
          Found in docs/js/app.js and 1 other location - About 35 mins to fix
          docs/js/app.js on lines 26..26

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

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

                    def as_html(link_resolver, html_serializer = nil)
                      custom = nil
                      unless html_serializer.nil?
                        custom = html_serializer.serialize(self, '')
                      end
          Severity: Minor
          Found in lib/prismic/fragments/structured_text.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 ref_from_cookie has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def ref_from_cookie(cookie)
                if cookie == nil
                  return nil
                end
                splitted = cookie.strip.split('%20')
          Severity: Minor
          Found in lib/prismic/experiments.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 structured_text_parser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def structured_text_parser(json)
                  def self.span_parser(span)
                    case span['type']
                    when 'em'
                      Prismic::Fragments::StructuredText::Span::Em.new(span['start'], span['end'])
          Severity: Minor
          Found in lib/prismic/json_parsers.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 full_trace has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def full_trace(e=self)
                first, *backtrace = e.backtrace
                msg = e == self ? "" : "Caused by "
                msg += "#{first}: #{e.message} (#{e.class})"
                stack = backtrace.map{|s| "\tfrom #{s}" }.join("\n")
          Severity: Minor
          Found in lib/prismic.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 q has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def q(*query)
                def serialize(field)
                  if field.kind_of?(String) and not (field.start_with?('my.') or field.start_with?('document'))
                    %("#{field}")
                  elsif field.kind_of?(Array)
          Severity: Minor
          Found in lib/prismic.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(json, access_token, http_client, cache)
                @json = json
                @access_token = access_token
                @http_client = http_client
                yield self if block_given?
          Severity: Minor
          Found in lib/prismic/api.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 get_or_set has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_or_set(key, value = nil, expired_in = nil)
                if include?(key) && !expired?(key)
                  return get(key)
                else
                  set(key, block_given? ? yield : value, expired_in)
          Severity: Minor
          Found in lib/prismic/cache/lru.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 serialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def serialize(field)
                  if field.kind_of?(String) and not (field.start_with?('my.') or field.start_with?('document'))
                    %("#{field}")
                  elsif field.kind_of?(Array)
                    %([#{field.map{ |arg| serialize(arg) }.join(', ')}])
          Severity: Minor
          Found in lib/prismic.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