unixmonkey/wicked_pdf

View on GitHub
lib/wicked_pdf.rb

Summary

Maintainability
D
1 day
Test Coverage

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

          There are no issues that match your filters.

          Category
          Status