prismicio/ruby-kit

View on GitHub

Showing 44 of 44 total issues

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

    def submit_raw(ref = nil)
      self.ref(ref) if ref
      data['ref'] = @ref
      raise NoRefSetException unless @ref

Severity: Minor
Found in lib/prismic.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

File prismic.rb has 351 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'cgi'
require 'net/http'
require 'uri'

require 'json' unless defined?(JSON)
Severity: Minor
Found in lib/prismic.rb - About 4 hrs to fix

    File structured_text.rb has 313 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Prismic
      module Fragments
        class StructuredText < Fragment
    
          # Used during the call of {StructuredText#as_html} : blocks are first gathered by groups,
    Severity: Minor
    Found in lib/prismic/fragments/structured_text.rb - About 3 hrs to fix

      File json_parsers.rb has 310 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'cgi'
      require 'time'
      
      module Prismic
        module JsonParser
      Severity: Minor
      Found in lib/prismic/json_parsers.rb - About 3 hrs to fix

        Method structured_text_parser has 61 lines of code (exceeds 25 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: Major
        Found in lib/prismic/json_parsers.rb - About 2 hrs to fix

          Class API has 22 methods (exceeds 20 allowed). Consider refactoring.
          Open

            class API
              @@warned_create_search_form = false
              @@warned_oauth_initiate_url = false
              @@warned_oauth_check_token = false
              attr_reader :json
          Severity: Minor
          Found in lib/prismic/api.rb - About 2 hrs to fix

            Function generateTOC has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function generateTOC() {
              if ($('#filecontents').length === 0) return;
              var _toc = $('<ol class="top"></ol>');
              var show = false;
              var toc = _toc;
            Severity: Minor
            Found in docs/js/app.js - About 2 hrs to fix

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

                    id,
                    uid,
                    type,
                    href,
                    tags,
              Severity: Major
              Found in lib/prismic.rb - About 1 hr to fix

                Method as_html has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                      def as_html(link_resolver, html_serializer=nil)
                        # Defining blocks that deserve grouping, assigning them "group kind" names
                        block_group = ->(block){
                          case block
                          when Block::ListItem
                Severity: Minor
                Found in lib/prismic/fragments/structured_text.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 first_title has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    def first_title
                      # It is impossible to reuse the StructuredText.first_title method, since
                      # we need to test the highest title across the whole document
                      title = false
                      max_level = 6 # any title with a higher level kicks the current one out
                Severity: Minor
                Found in lib/prismic/with_fragments.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 document_parser has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def document_parser(json)
                        data_json = json['data'].values.first  # {"doc_type": data}
                
                        # Removing the unknown types + sending a warning, once
                        data_json.select!{ |_, fragment|
                Severity: Minor
                Found in lib/prismic/json_parsers.rb - About 1 hr to fix

                  Method submit_raw has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def submit_raw(ref = nil)
                        self.ref(ref) if ref
                        data['ref'] = @ref
                        raise NoRefSetException unless @ref
                  
                  
                  Severity: Minor
                  Found in lib/prismic.rb - About 1 hr to fix

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

                          def initialize(id, uid, type, tags, slug, lang, fragments, broken, target = nil)
                    Severity: Major
                    Found in lib/prismic/fragments/link.rb - About 1 hr to fix

                      Method as_html has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            def as_html(link_resolver, html_serializer=nil)
                              # Defining blocks that deserve grouping, assigning them "group kind" names
                              block_group = ->(block){
                                case block
                                when Block::ListItem
                      Severity: Minor
                      Found in lib/prismic/fragments/structured_text.rb - About 1 hr to fix

                        Method as_html has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                  def as_html(link_resolver=nil, html_serializer=nil)
                                    html = ''
                                    # Getting Hashes of spanning tags to insert, sorted by starting position, and by ending position
                                    start_spans, end_spans = prepare_spans
                                    # Open tags
                        Severity: Minor
                        Found in lib/prismic/fragments/structured_text.rb - About 1 hr to fix

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

                                    def as_html(link_resolver=nil, html_serializer=nil)
                                      html = ''
                                      # Getting Hashes of spanning tags to insert, sorted by starting position, and by ending position
                                      start_spans, end_spans = prepare_spans
                                      # Open tags
                          Severity: Minor
                          Found in lib/prismic/fragments/structured_text.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

                          Function summaryToggle has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function summaryToggle() {
                            $('.summary_toggle').click(function(e) {
                              e.preventDefault();
                              localStorage.summaryCollapsed = $(this).text();
                              $('.summary_toggle').each(function() {
                          Severity: Minor
                          Found in docs/js/app.js - About 1 hr to fix

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

                                def initialize(page, results_per_page, results_size, total_results_size, total_pages, next_page, prev_page, results)
                            Severity: Major
                            Found in lib/prismic.rb - About 1 hr to fix

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

                                  def initialize(api, name, fields, form_method, rel, enctype, action)
                              Severity: Major
                              Found in lib/prismic/form.rb - About 50 mins to fix

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

                                    $('.toggleSource').toggle(function() {
                                       $(this).parent().nextAll('.source_code').slideDown(100);
                                       $(this).text("Hide source");
                                    },
                                Severity: Minor
                                Found in docs/js/app.js and 1 other location - About 50 mins to fix
                                docs/js/app.js on lines 14..17

                                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

                                Severity
                                Category
                                Status
                                Source
                                Language