prismicio/ruby-kit

View on GitHub

Showing 34 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

                                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

                                Severity
                                Category
                                Status
                                Source
                                Language