mileszs/wicked_pdf

View on GitHub

Showing 22 of 22 total issues

Method parse_header_footer has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def parse_header_footer(options)
      r = []
      unless options.blank?
        %i[header footer].collect do |hf|
          next if options[hf].blank?
Severity: Minor
Found in lib/wicked_pdf/option_parser.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 pdf_from_url has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

  def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
    # merge in global config options
    options.merge!(WickedPdf.config) { |_key, option, _config| option }
    generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
    command = [@binary.path]
Severity: Minor
Found in lib/wicked_pdf.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

File assets.rb has 266 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'net/http'
require 'delegate'
require 'stringio'

class WickedPdf
Severity: Minor
Found in lib/wicked_pdf/wicked_pdf_helper/assets.rb - About 2 hrs to fix

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

        def make_and_send_pdf(pdf_name, options = {})
          options[:wkhtmltopdf] ||= nil
          options[:layout] ||= false
          options[:template] ||= File.join(controller_path, action_name)
          options[:disposition] ||= 'inline'
    Severity: Minor
    Found in lib/wicked_pdf/pdf_helper.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

    Class WickedPdf has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class WickedPdf
      module WickedPdfHelper
        module Assets
          ASSET_URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/
    
    
    Severity: Minor
    Found in lib/wicked_pdf/wicked_pdf_helper/assets.rb - About 2 hrs to fix

      Method render_as_pdf? has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def render_as_pdf?
            request_path_is_pdf = @request.path.match(%r{\.pdf$})
      
            if request_path_is_pdf && @conditions[:only]
              rules = [@conditions[:only]].flatten
      Severity: Minor
      Found in lib/wicked_pdf/middleware.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 call has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def call(env)
            @request = Rack::Request.new(env)
            @render_pdf = false
      
            set_request_to_render_as_pdf(env) if render_as_pdf?
      Severity: Minor
      Found in lib/wicked_pdf/middleware.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 prerender_header_and_footer has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def prerender_header_and_footer(options)
            %i[header footer].each do |hf|
              next unless options[hf] && options[hf][:html] && options[hf][:html][:template]
      
              @hf_tempfiles = [] unless defined?(@hf_tempfiles)
      Severity: Minor
      Found in lib/wicked_pdf/pdf_helper.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 asset_pathname has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

            def asset_pathname(source)
              if precompiled_or_absolute_asset?(source)
                asset = asset_path(source)
                pathname = prepend_protocol(asset)
                if pathname =~ URI_REGEXP
      Severity: Minor
      Found in lib/wicked_pdf/wicked_pdf_helper/assets.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 parse_others has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def parse_others(options)
            r = []
            unless options.blank?
              r += make_options(options, %i[proxy
                                            username
      Severity: Minor
      Found in lib/wicked_pdf/option_parser.rb - About 1 hr to fix

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

            def parse_toc(options)
              return [] if options.nil?
        
              r = [valid_option('toc')]
              unless options.blank?
        Severity: Minor
        Found in lib/wicked_pdf/option_parser.rb - About 1 hr to fix

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

                def find_asset(path)
                  if Rails.application.assets.respond_to?(:find_asset)
                    Rails.application.assets.find_asset(path, :base_path => Rails.application.root.to_s)
                  elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly)
                    PropshaftAsset.new(Rails.application.assets.load_path.find(path))
          Severity: Minor
          Found in lib/wicked_pdf/wicked_pdf_helper/assets.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 read_asset has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def read_asset(source)
                  asset = find_asset(source)
                  return asset.to_s.force_encoding('UTF-8') if asset
          
                  unless precompiled_or_absolute_asset?(source)
          Severity: Minor
          Found in lib/wicked_pdf/wicked_pdf_helper/assets.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 pdf_from_url has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
              # merge in global config options
              options.merge!(WickedPdf.config) { |_key, option, _config| option }
              generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
              command = [@binary.path]
          Severity: Minor
          Found in lib/wicked_pdf.rb - About 1 hr to fix

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

                def invoke_with_progress(command, options)
                  output = []
                  begin
                    PTY.spawn(command.join(' ')) do |stdout, _stdin, pid|
                      begin
            Severity: Minor
            Found in lib/wicked_pdf/progress.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 make_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def make_options(options, names, prefix = '', type = :string)
                  return [] if options.nil?
            
                  names.collect do |o|
                    if options[o].blank?
            Severity: Minor
            Found in lib/wicked_pdf/option_parser.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 make_option has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def make_option(name, value, type = :string)
                  return value.collect { |v| make_option(name, v, type) } if value.is_a?(Array)
            
                  if type == :name_value
                    parts = value.to_s.split(' ')
            Severity: Minor
            Found in lib/wicked_pdf/option_parser.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 wicked_pdf_stylesheet_pack_tag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def wicked_pdf_stylesheet_pack_tag(*sources)
                    return unless defined?(Webpacker)
            
                    if running_in_development?
                      stylesheet_pack_tag(*sources)
            Severity: Minor
            Found in lib/wicked_pdf/wicked_pdf_helper/assets.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 webpacker_source_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def webpacker_source_url(source)
                    return unless webpacker_version
            
                    # In Webpacker 3.2.0 asset_pack_url is introduced
                    if webpacker_version >= '3.2.0'
            Severity: Minor
            Found in lib/wicked_pdf/wicked_pdf_helper/assets.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 read_from_uri has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def read_from_uri(uri)
                    response = Net::HTTP.get_response(URI(uri))
            
                    unless response.is_a?(Net::HTTPSuccess)
                      raise MissingRemoteAsset.new(uri, response) if WickedPdf.config[:raise_on_missing_assets]
            Severity: Minor
            Found in lib/wicked_pdf/wicked_pdf_helper/assets.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