prawnpdf/prawn

View on GitHub

Showing 86 of 90 total issues

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 print_line has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def print_line
          @nothing_printed = false
          printed_fragments = []
          fragments_this_line = []

Severity: Minor
Found in lib/prawn/text/formatted/wrap.rb - About 1 hr to fix

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

          def calc_image_dimensions(options)
            w = options[:width] || width
            h = options[:height] || height
    
            if options[:width] && !options[:height]
    Severity: Minor
    Found in lib/prawn/images/image.rb - About 1 hr to fix

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

              def wrap_line(options)
                initialize_line(options)
      
                # rubocop: disable Lint/AssignmentInCondition
                while fragment = @arranger.next_string
      Severity: Minor
      Found in lib/prawn/text/formatted/line_wrap.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 calc_image_dimensions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def calc_image_dimensions(options)
              w = options[:width] || width
              h = options[:height] || height
      
              if options[:width] && !options[:height]
      Severity: Minor
      Found in lib/prawn/images/image.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 a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def encrypted_pdf_object(obj, key, id, gen, in_content_stream = false)
            case obj
            when Array
              array_content = obj.map { |e|
                encrypted_pdf_object(e, key, id, gen, in_content_stream)
      Severity: Minor
      Found in lib/prawn/security.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 font_style has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

              def font_style(styles)
                if styles
                  if styles.include?(:bold)
                    styles.include?(:italic) ? :bold_italic : :bold
                  elsif styles.include?(:italic)
      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 mapping_spans has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def mapping_spans(mapping)
              mapping
                .sort
                .slice_when { |a, b| (b[0] - a[0]) != 1 } # Slice at key discontinuity
                .flat_map { |slice|
      Severity: Minor
      Found in lib/prawn/fonts/to_unicode_cmap.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 10 (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

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

            def embed_composite_font(reference, font)
              if font_type(font) == :unknown
                raise Error, %(Composite font embedding is not uspported for font "#{font.name}.")
              end
      
      
      Severity: Minor
      Found in lib/prawn/fonts/ttf.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 span has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def span(width, options = {})
            Prawn.verify_options([:position], options)
            original_position = y
      
            # FIXME: Any way to move this upstream?
      Severity: Minor
      Found in lib/prawn/document/span.rb - About 1 hr to fix

        Method encode_text has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def encode_text(text, options = {})
                text = text.chomp
        
                if options[:kerning]
                  last_subset = nil
        Severity: Minor
        Found in lib/prawn/fonts/ttf.rb - About 1 hr to fix

          Method analyze_glyphs_for_fallback_font_support has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def analyze_glyphs_for_fallback_font_support(hash)
                    font_glyph_pairs = []
          
                    original_font = @document.font.family
                    fragment_font = hash[:font] || original_font
          Severity: Minor
          Found in lib/prawn/text/formatted/box.rb - About 1 hr to fix

            Method image_position has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def image_position(width, height, options)
                  options[:position] ||= :left
            
                  y =
                    case options[:vposition]
            Severity: Minor
            Found in lib/prawn/images.rb - About 1 hr to fix

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

                    def initialize(document, name, options = {})
                      name ||= options[:family]
                      unless BUILT_INS.include?(name)
                        raise Prawn::Errors::UnknownFont,
                          "#{name} (#{options[:style] || 'normal'}) is not a known font."
              Severity: Minor
              Found in lib/prawn/fonts/afm.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

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

                    def build_pdf_object(document)
                      if compression_method != 0
                        raise Errors::UnsupportedImageType,
                          'PNG uses an unsupported compression method'
                      end
              Severity: Minor
              Found in lib/prawn/images/png.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

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

                    def kern(string)
                      kerned = [[]]
                      last_byte = nil
              
                      string.each_byte do |byte|
              Severity: Minor
              Found in lib/prawn/fonts/afm.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

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

                    def embed_simple_font(reference, font, unicode_mapping)
                      if font_type(font) == :unknown
                        raise Error, %(Simple font embedding is not uspported for font "#{font.name}.")
                      end
              
              
              Severity: Minor
              Found in lib/prawn/fonts/ttf.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

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

                      def draw_fragment(
                        fragment, accumulated_width = 0, line_width = 0, word_spacing = 0
                      )
                        case @align
                        when :left
              Severity: Minor
              Found in lib/prawn/text/formatted/box.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

              Method dash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def dash(length = nil, options = {})
                      return current_dash_state if length.nil?
              
                      length = Array(length)
              
              
              Severity: Minor
              Found in lib/prawn/graphics/dash.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