goshippo/shippo-ruby-client

View on GitHub
lib/shippo/api/category/base.rb

Summary

Maintainability
A
1 hr
Test Coverage

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

        def self.inherited(klazz)
          klazz.instance_eval do
            @allowed_values = Set.new
            class << self
              def categories
Severity: Minor
Found in lib/shippo/api/category/base.rb - About 1 hr to fix

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

                  def allowed_values(*values)
                    return @allowed_values if values.nil? || values.empty? || !@allowed_values.empty?
    
                    @allowed_values = self.value_transformer(values)
                    @allowed_values.each do |allowed_value|
    Severity: Minor
    Found in lib/shippo/api/category/base.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

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

              klazz.instance_eval do
                @allowed_values = Set.new
                class << self
                  def categories
                    ::Shippo::API::Category::Base.categories
    Severity: Minor
    Found in lib/shippo/api/category/base.rb by rubocop

    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.

    Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
    Open

                        "Constant #{category_const} is already defined in #{self.name}") if self.const_defined?(category_const)
    Severity: Minor
    Found in lib/shippo/api/category/base.rb by rubocop

    This cop checks that the closing brace in a method call is either on the same line as the last method argument, or a new line.

    When using the symmetrical (default) style:

    If a method call's opening brace is on the same line as the first argument of the call, then the closing brace should be on the same line as the last argument of the call.

    If an method call's opening brace is on the line above the first argument of the call, then the closing brace should be on the line below the last argument of the call.

    When using the new_line style:

    The closing brace of a multi-line method call must be on the line after the last argument of the call.

    When using the same_line style:

    The closing brace of a multi-line method call must be on the same line as the last argument of the call.

    Example:

    # symmetrical: bad
      # new_line: good
      # same_line: bad
      foo(a,
        b
      )
    
      # symmetrical: bad
      # new_line: bad
      # same_line: good
      foo(
        a,
        b)
    
      # symmetrical: good
      # new_line: bad
      # same_line: good
      foo(a,
        b)
    
      # symmetrical: good
      # new_line: good
      # same_line: bad
      foo(
        a,
        b
      )

    Favor a normal if-statement over a modifier clause in a multiline statement.
    Open

                      raise ::Shippo::API::Category::DuplicateValueError.new(
                        "Constant #{category_const} is already defined in #{self.name}") if self.const_defined?(category_const)
    Severity: Minor
    Found in lib/shippo/api/category/base.rb by rubocop

    Checks for uses of if/unless modifiers with multiple-lines bodies.

    Example:

    # bad
    {
      result: 'this should not happen'
    } unless cond
    
    # good
    { result: 'ok' } if cond

    Prefer to_s over string interpolation.
    Open

              "#{self.value.upcase}"
    Severity: Minor
    Found in lib/shippo/api/category/base.rb by rubocop

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
    Open

                  "Value #{value} is not allowed for Category #{self.class.name}, allowed values are: #{self.class.allowed_values})")
    Severity: Minor
    Found in lib/shippo/api/category/base.rb by rubocop

    This cop checks that the closing brace in a method call is either on the same line as the last method argument, or a new line.

    When using the symmetrical (default) style:

    If a method call's opening brace is on the same line as the first argument of the call, then the closing brace should be on the same line as the last argument of the call.

    If an method call's opening brace is on the line above the first argument of the call, then the closing brace should be on the line below the last argument of the call.

    When using the new_line style:

    The closing brace of a multi-line method call must be on the line after the last argument of the call.

    When using the same_line style:

    The closing brace of a multi-line method call must be on the same line as the last argument of the call.

    Example:

    # symmetrical: bad
      # new_line: good
      # same_line: bad
      foo(a,
        b
      )
    
      # symmetrical: bad
      # new_line: bad
      # same_line: good
      foo(
        a,
        b)
    
      # symmetrical: good
      # new_line: bad
      # same_line: good
      foo(a,
        b)
    
      # symmetrical: good
      # new_line: good
      # same_line: bad
      foo(
        a,
        b
      )

    There are no issues that match your filters.

    Category
    Status