unixmonkey/wicked_pdf

View on GitHub

Showing 15 of 15 total issues

File wicked_pdf.rb has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'logger'
require 'digest/md5'
require 'rbconfig'

if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9')
Severity: Minor
Found in lib/wicked_pdf.rb - About 3 hrs to fix

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

      def parse_header_footer(options)
        r = []
        [:header, :footer].collect do |hf|
          next if options[hf].blank?
          opt_hf = options[hf]
    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

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

    class WickedPdf
      DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
      BINARY_VERSION_WITHOUT_DASHES = Gem::Version.new('0.12.0')
      EXE_NAME = 'wkhtmltopdf'.freeze
      @@config = {}
    Severity: Minor
    Found in lib/wicked_pdf.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 make_and_send_pdf has a Cognitive Complexity of 15 (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 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)
            [:header, :footer].each do |hf|
              next unless options[hf] && options[hf][:html] && options[hf][:html][:template]
              @hf_tempfiles = [] unless defined?(@hf_tempfiles)
              @hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html"))
      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 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 pdf_from_url has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def pdf_from_url(url, options = {})
          # merge in global config options
          options.merge!(WickedPdf.config) { |_key, option, _config| option }
          generated_pdf_file = WickedPdfTempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
          command = [@exe_path]
      Severity: Minor
      Found in lib/wicked_pdf.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_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?
            r += make_options(options, [:font_name, :header_text], 'toc')
      Severity: Minor
      Found in lib/wicked_pdf.rb - About 1 hr to fix

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

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

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

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

            def initialize(wkhtmltopdf_binary_path = nil)
              @exe_path = wkhtmltopdf_binary_path || find_wkhtmltopdf_binary_path
              raise "Location of #{EXE_NAME} unknown" if @exe_path.empty?
              raise "Bad #{EXE_NAME}'s path: #{@exe_path}" unless File.exist?(@exe_path)
              raise "#{EXE_NAME} is not executable" unless File.executable?(@exe_path)
          Severity: Minor
          Found in lib/wicked_pdf.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

          Method find_wkhtmltopdf_binary_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def find_wkhtmltopdf_binary_path
              possible_locations = (ENV['PATH'].split(':') + %w(/usr/bin /usr/local/bin ~/bin)).uniq
              exe_path ||= WickedPdf.config[:exe_path] unless WickedPdf.config.empty?
              exe_path ||= begin
                detected_path = (defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
          Severity: Minor
          Found in lib/wicked_pdf.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