railsdog/spree_shipping_labels

View on GitHub
app/models/spree/shipment_decorator.rb

Summary

Maintainability
A
25 mins
Test Coverage

Block has too many lines. [41/25]
Open

Spree::Shipment.class_eval do
  include Spree::PackageTypePicking

  belongs_to :package_type
  has_one :label, dependent: :destroy

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

  def generate_label!
    raise Spree::ShippingLabels::Error, 'Cannot generate a label without a package type' unless package_type
    raise Spree::ShippingLabels::Error, 'Cannot generate a label without a label-able selected shipping method' unless calculator
    # Restrict to just 5 seconds to get response to avoid appearing slow
    timeout 10 do
Severity: Minor
Found in app/models/spree/shipment_decorator.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

Avoid the use of the case equality operator ===.
Open

    calc if Spree::Calculator::Shipping::QuotedForLabel === calc

This cop checks for uses of the case equality operator(===).

Example:

# bad
Array === something
(1..100) === 7
/something/ === some_string

# good
something.is_a?(Array)
(1..100).include?(7)
some_string =~ /something/

Line is too long. [105/80]
Open

      preferred = preferred_package_type calculator.preferred_provider, calculator.preferred_service_type

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if calculator

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Line is too long. [108/80]
Open

    raise Spree::ShippingLabels::Error, 'Cannot generate a label without a package type' unless package_type

Line is too long. [102/80]
Open

    possible_package_types_for calculator.preferred_provider, calculator.preferred_service_type, false

Avoid rescuing without specifying an error class.
Open

      rescue

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Extra empty line detected at block body end.
Open


end

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

Example: EnforcedStyle: empty_lines

# good

foo do |bar|

  # ...

end

Example: EnforcedStyle: noemptylines (default)

# good

foo do |bar|
  # ...
end

Line is too long. [97/80]
Open

      package_type.provider.generate_label! calculator.preferred_service_type, package_type, self

Line is too long. [97/80]
Open

  alias_method_chain :finalize!, :label unless instance_methods.include? :finalize_without_label!

Line is too long. [129/80]
Open

    raise Spree::ShippingLabels::Error, 'Cannot generate a label without a label-able selected shipping method' unless calculator

There are no issues that match your filters.

Category
Status