thoughtbot/paperclip

View on GitHub
lib/paperclip/geometry.rb

Summary

Maintainability
A
55 mins
Test Coverage

Assignment Branch Condition size for resize_to is too high. [18.41/15]
Open

    def resize_to(geometry)
      new_geometry = Paperclip::Geometry.parse geometry
      case new_geometry.modifier
      when '!', '#'
        new_geometry
Severity: Minor
Found in lib/paperclip/geometry.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 scale_to is too high. [18.03/15]
Open

    def scale_to(new_geometry)
      scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
      Paperclip::Geometry.new((self.width * scale).round, (self.height * scale).round)
    end
Severity: Minor
Found in lib/paperclip/geometry.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 cropping is too high. [18.11/15]
Open

    def cropping dst, ratio, scale
      if ratio.horizontal? || ratio.square?
        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
      else
        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
Severity: Minor
Found in lib/paperclip/geometry.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 resize_to has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def resize_to(geometry)
      new_geometry = Paperclip::Geometry.parse geometry
      case new_geometry.modifier
      when '!', '#'
        new_geometry
Severity: Minor
Found in lib/paperclip/geometry.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

Redundant self detected.
Open

      scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Line is too long. [86/80]
Open

    # Returns the scaling and cropping geometries (in string-based ImageMagick format)
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        if new_geometry.width <= self.width || new_geometry.height <= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

        [ "x%d" % dst.height, ratio.height ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

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

      when '>'
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

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

      when '!', '#'
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [85/80]
Open

    # neccessary to transform this Geometry into the Geometry given. If crop is true,
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [90/80]
Open

    # overhanging image would be cropped. Useful for square thumbnail images. The cropping
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [92/80]
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [107/80]
Open

      scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        if new_geometry.width >= self.width && new_geometry.height >= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [81/80]
Open

    # In this case, the source Geometry is scaled so that an image containing the
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [90/80]
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def scaling dst, ratio
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def cropping dst, ratio, scale
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space inside square brackets detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

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

      when '<'
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [85/80]
Open

    # then it is assumed the destination Geometry will be the exact final resolution.
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [81/80]
Open

        if new_geometry.width <= self.width || new_geometry.height <= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def transformation_to dst, crop = false
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space found before comma.
Open

      scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space inside square brackets detected.
Open

        [ "%dx" % dst.width, ratio.width ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [82/80]
Open

    # destination Geometry would be completely filled by the source image, and any
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

      Paperclip::Geometry.new((self.width * scale).round, (self.height * scale).round)
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

      [ scale_geometry, crop_geometry ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space inside square brackets detected.
Open

        [ "x%d" % dst.height, ratio.height ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        if new_geometry.width >= self.width && new_geometry.height >= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

      [ scale_geometry, crop_geometry ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [86/80]
Open

    # Returns the width and height in a format suitable to be passed to Geometry.parse
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Line is too long. [86/80]
Open

      Paperclip::Geometry.new((self.width * scale).round, (self.height * scale).round)
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Extra empty line detected at module body beginning.
Open


  # Defines the geometry of an image.
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

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

Example:

EnforcedStyle: empty_lines

# good

module Foo

  def bar
    ...
  end

end

EnforcedStyle: no_empty_lines

# good

module Foo
  def bar
    ...
  end
end

Freeze mutable objects assigned to constants.
Open

    EXIF_ROTATED_ORIENTATION_VALUES = [5, 6, 7, 8]
Severity: Minor
Found in lib/paperclip/geometry.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

Redundant self detected.
Open

        ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space inside parentheses detected.
Open

        ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

      scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Line is too long. [81/80]
Open

        if new_geometry.width >= self.width && new_geometry.height >= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Redundant self detected.
Open

      Paperclip::Geometry.new((self.width * scale).round, (self.height * scale).round)
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Space inside square brackets detected.
Open

        [ "%dx" % dst.width, ratio.width ]
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Space inside parentheses detected.
Open

        ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

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

      when '!', '#'
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

Redundant self detected.
Open

        if new_geometry.width <= self.width || new_geometry.height <= self.height
Severity: Minor
Found in lib/paperclip/geometry.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

There are no issues that match your filters.

Category
Status