thoughtbot/paperclip

View on GitHub
lib/paperclip/thumbnail.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Assignment Branch Condition size for initialize is too high. [30.43/15]
Open

    def initialize(file, options = {}, attachment = nil)
      super

      geometry             = options[:geometry].to_s
      @crop                = geometry[-1,1] == '#'
Severity: Minor
Found in lib/paperclip/thumbnail.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for make is too high. [28.74/15]
Open

    def make
      src = @file
      filename = [@basename, @format ? ".#{@format}" : ""].join
      dst = TempfileFactory.new.generate(filename)

Severity: Minor
Found in lib/paperclip/thumbnail.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for transformation_command is too high. [16.64/15]
Open

    def transformation_command
      scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
      trans = []
      trans << "-coalesce" if animated?
      trans << "-auto-orient" if auto_orient
Severity: Minor
Found in lib/paperclip/thumbnail.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

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

    def make
      src = @file
      filename = [@basename, @format ? ".#{@format}" : ""].join
      dst = TempfileFactory.new.generate(filename)

Severity: Minor
Found in lib/paperclip/thumbnail.rb - About 1 hr to fix

    Method transformation_command has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def transformation_command
          scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
          trans = []
          trans << "-coalesce" if animated?
          trans << "-auto-orient" if auto_orient
    Severity: Minor
    Found in lib/paperclip/thumbnail.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 make has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def make
          src = @file
          filename = [@basename, @format ? ".#{@format}" : ""].join
          dst = TempfileFactory.new.generate(filename)
    
    
    Severity: Minor
    Found in lib/paperclip/thumbnail.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(file, options = {}, attachment = nil)
          super
    
          geometry             = options[:geometry].to_s
          @crop                = geometry[-1,1] == '#'
    Severity: Minor
    Found in lib/paperclip/thumbnail.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

    Space missing after comma.
    Open

          @crop                = geometry[-1,1] == '#'
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Checks for comma (,) not followed by some kind of space.

    Example:

    # bad
    [1,2]
    { foo:bar,}
    
    # good
    [1, 2]
    { foo:bar, }

    Extra empty line detected at class body beginning.
    Open

    
        attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options,
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cops checks if empty lines around the bodies of classes match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    class Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    class Foo
      class Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    class Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    class Foo
      def bar
        # ...
      end
    end

    Useless assignment to variable - e.
    Open

        rescue Terrapin::CommandNotFoundError => e
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Operator && should be surrounded by a single space.
    Open

          @animated && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)  && identified_as_animated?
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Useless assignment to variable - e.
    Open

          rescue Terrapin::CommandNotFoundError => e
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Useless assignment to variable - e.
    Open

        rescue Terrapin::ExitStatusError => e
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Unnecessary spacing detected.
    Open

          @animated && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)  && identified_as_animated?
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks for extra/unnecessary whitespace.

    Example:

    # good if AllowForAlignment is true
    name      = "RuboCop"
    # Some comment and an empty line
    
    website  += "/bbatsov/rubocop" unless cond
    puts        "rubocop"          if     debug
    
    # bad for any configuration
    set_app("RuboCop")
    website  = "https://github.com/bbatsov/rubocop"

    Line is too long. [83/80]
    Open

        # Returns true if the image is meant to make use of additional convert options.
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
    Open

          @crop                = geometry[-1,1] == '#'
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Line is too long. [83/80]
    Open

        #   +animated+ - whether to merge all the layers in the image. Defaults to true
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [184/80]
    Open

        #   +file_geometry_parser+ - an object with a method named +from_file+ that takes an image file and produces its geometry and a +transformation_to+. Defaults to Paperclip::Geometry
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [83/80]
    Open

        #   +whiny+ - whether to raise an error when processing fails. Defaults to true
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [102/80]
    Open

          @convert_options     = @convert_options.split(/\s+/)     if @convert_options.respond_to?(:split)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [93/80]
    Open

          @target_geometry     = options.fetch(:string_geometry_parser, Geometry).parse(geometry)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Avoid comma after the last parameter of a method call.
    Open

              dest: File.expand_path(dst.path),
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks for trailing comma in argument lists.

    Example: EnforcedStyleForMultiline: consistent_comma

    # bad
    method(1, 2,)
    
    # good
    method(
      1, 2,
      3,
    )
    
    # good
    method(
      1,
      2,
    )

    Example: EnforcedStyleForMultiline: comma

    # bad
    method(1, 2,)
    
    # good
    method(
      1,
      2,
    )

    Example: EnforcedStyleForMultiline: no_comma (default)

    # bad
    method(1, 2,)
    
    # good
    method(
      1,
      2
    )

    Line is too long. [107/80]
    Open

        #   +convert_options+ - flags passed to the +convert+ command that influence how the image is processed
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [193/80]
    Open

        #   +string_geometry_parser+ - an object with a method named +parse+ that takes a string and produces an object with +width+, +height+, and +to_s+ accessors. Defaults to Paperclip::Geometry
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [85/80]
    Open

        #   +frame_index+ - the frame index of the source file to render as the thumbnail
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Use the new Ruby 1.9 hash syntax.
    Open

            @identified_as_animated = ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks hash literal syntax.

    It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

    A separate offense is registered for each problematic pair.

    The supported styles are:

    • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
    • hash_rockets - forces use of hash rockets for all hashes
    • nomixedkeys - simply checks for hashes with mixed syntaxes
    • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

    Example: EnforcedStyle: ruby19 (default)

    # bad
    {:a => 2}
    {b: 1, :c => 2}
    
    # good
    {a: 2, b: 1}
    {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
    {d: 1, 'e' => 2} # technically not forbidden

    Example: EnforcedStyle: hash_rockets

    # bad
    {a: 1, b: 2}
    {c: 1, 'd' => 5}
    
    # good
    {:a => 1, :b => 2}

    Example: EnforcedStyle: nomixedkeys

    # bad
    {:a => 1, b: 2}
    {c: 1, 'd' => 2}
    
    # good
    {:a => 1, :b => 2}
    {c: 1, d: 2}

    Example: EnforcedStyle: ruby19nomixed_keys

    # bad
    {:a => 1, :b => 2}
    {c: 2, 'd' => 3} # should just use hash rockets
    
    # good
    {a: 1, b: 2}
    {:c => 3, 'd' => 4}

    Line is too long. [84/80]
    Open

        # set, the options will be appended to the convert command upon image conversion
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [89/80]
    Open

        attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options,
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [85/80]
    Open

          @frame_index         = multi_frame_format? ? options.fetch(:frame_index, 0) : 0
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [92/80]
    Open

          @current_geometry    = options.fetch(:file_geometry_parser, Geometry).from_file(@file)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [125/80]
    Open

            raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [106/80]
    Open

          @animated && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)  && identified_as_animated?
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [96/80]
    Open

          raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [106/80]
    Open

          @source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [137/80]
    Open

            @identified_as_animated = ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Freeze mutable objects assigned to constants.
    Open

        MULTI_FRAME_FORMATS = %w(.mkv .avi .mp4 .mov .mpg .mpeg .gif)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    Line is too long. [112/80]
    Open

        #   +source_file_options+ - flags passed to the +convert+ command that influence how the source file is read
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [97/80]
    Open

              message = "There was an error processing the thumbnail for #{@basename}:\n" + e.message
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [124/80]
    Open

          raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Line is too long. [82/80]
    Open

        # Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    Freeze mutable objects assigned to constants.
    Open

        ANIMATED_FORMATS = %w(gif)
    Severity: Minor
    Found in lib/paperclip/thumbnail.rb by rubocop

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    There are no issues that match your filters.

    Category
    Status