prawnpdf/prawn

View on GitHub

Showing 79 of 81 total issues

Method parse_afm has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_afm(file_name)
        data = {
          glyph_widths: {},
          bounding_boxes: {},
          kern_pairs: {},
Severity: Minor
Found in lib/prawn/font/afm.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 to_string has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def self.to_string(array)
          prefixes = {
            bold: '<b>',
            italic: '<i>',
            underline: '<u>',
Severity: Major
Found in lib/prawn/text/formatted/parser.rb - About 2 hrs to fix

    Method embed has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def embed(reference, subset)
            font_content = @subsets[subset].encode
    
            # FIXME: we need postscript_name and glyph widths from the font
            # subset. Perhaps this could be done by querying the subset,
    Severity: Major
    Found in lib/prawn/font/ttf.rb - About 2 hrs to fix

      Method create_gradient_pattern has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def create_gradient_pattern(gradient)
              if gradient.apply_transformations.nil? &&
                  current_transformation_matrix_with_translation(0, 0) !=
                      [1, 0, 0, 1, 0, 0]
                warn 'Gradients in Prawn 2.x and lower are not correctly positioned '\
      Severity: Minor
      Found in lib/prawn/graphics/patterns.rb - About 1 hr to fix

        Method array_paragraphs has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

                def self.array_paragraphs(array) #:nodoc:
                  paragraphs = []
                  paragraph = []
                  previous_string = "\n"
                  scan_pattern = /[^\n]+|\n/
        Severity: Minor
        Found in lib/prawn/text/formatted/parser.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 stroke_axis has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def stroke_axis(options = {})
              options = {
                at: [0, 0],
                height: bounds.height.to_i - (options[:at] || [0, 0])[1],
                width: bounds.width.to_i - (options[:at] || [0, 0])[0],
        Severity: Minor
        Found in lib/prawn/graphics.rb - About 1 hr to fix

          Method parse_afm has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def parse_afm(file_name)
                  data = {
                    glyph_widths: {},
                    bounding_boxes: {},
                    kern_pairs: {},
          Severity: Minor
          Found in lib/prawn/font/afm.rb - About 1 hr to fix

            Method initialize has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def initialize(formatted_text, options = {})
                      @inked = false
                      Prawn.verify_options(valid_options, options)
                      options = options.dup
            
            
            Severity: Minor
            Found in lib/prawn/text/formatted/box.rb - About 1 hr to fix

              Method soft_mask has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def soft_mask(&block)
                    renderer.min_version(1.4)
              
                    group_attrs = ref!(
                      Type: :Group,
              Severity: Minor
              Found in lib/prawn/soft_mask.rb - About 1 hr to fix

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

                      def parse_gradient_arguments(
                        *arguments, from: nil, to: nil, r1: nil, r2: nil, stops: nil,
                        apply_transformations: nil
                      )
                        case arguments.length
                Severity: Minor
                Found in lib/prawn/graphics/patterns.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 encrypted_pdf_object has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def encrypted_pdf_object(obj, key, id, gen, in_content_stream = false)
                      case obj
                      when Array
                        '[' + obj.map do |e|
                          encrypted_pdf_object(e, key, id, gen, in_content_stream)
                Severity: Minor
                Found in lib/prawn/security.rb - About 1 hr to fix

                  Method parse_gradient_arguments has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def parse_gradient_arguments(
                          *arguments, from: nil, to: nil, r1: nil, r2: nil, stops: nil,
                          apply_transformations: nil
                        )
                          case arguments.length
                  Severity: Minor
                  Found in lib/prawn/graphics/patterns.rb - About 1 hr to fix

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

                          def initialize(data)
                            data = StringIO.new(data.dup)
                    
                            data.read(8) # Skip the default header
                    
                    
                    Severity: Minor
                    Found in lib/prawn/images/png.rb - About 1 hr to fix

                      Method start_new_page has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def start_new_page(options = {})
                            last_page = state.page
                            if last_page
                              last_page_size = last_page.size
                              last_page_layout = last_page.layout
                      Severity: Minor
                      Found in lib/prawn/document.rb - About 1 hr to fix

                        Method draw_fragment has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                def draw_fragment(
                                  fragment, accumulated_width = 0, line_width = 0, word_spacing = 0
                                ) #:nodoc:
                                  case @align
                                  when :left
                        Severity: Minor
                        Found in lib/prawn/text/formatted/box.rb - About 1 hr to fix

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

                              def start_new_page(options = {})
                                last_page = state.page
                                if last_page
                                  last_page_size = last_page.size
                                  last_page_layout = last_page.layout
                          Severity: Minor
                          Found in lib/prawn/document.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 number_pages has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              def number_pages(string, options = {})
                                opts = options.dup
                                start_count_at = opts.delete(:start_count_at).to_i
                          
                                page_filter = if opts.key?(:page_filter)
                          Severity: Minor
                          Found in lib/prawn/document.rb - About 1 hr to fix

                            Method add_fragment_to_line has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                    def add_fragment_to_line(fragment)
                                      if fragment == ''
                                        true
                                      elsif fragment == "\n"
                                        @newline_encountered = true
                            Severity: Minor
                            Found in lib/prawn/text/formatted/line_wrap.rb - About 1 hr to fix

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

                                      def shrink_to_fit(text)
                                        loop do
                                          if @disable_wrap_by_char && @font_size > @min_font_size
                                            begin
                                              wrap(text)
                              Severity: Minor
                              Found in lib/prawn/text/formatted/box.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 apply_font_settings has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                              Open

                                      def apply_font_settings(fragment = nil, &block)
                                        if fragment.nil?
                                          font = current_format_state[:font]
                                          size = current_format_state[:size]
                                          character_spacing = current_format_state[:character_spacing] ||
                              Severity: Minor
                              Found in lib/prawn/text/formatted/arranger.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