flant/superhosting

View on GitHub
lib/superhosting/controller/container/states.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method install_users has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

      def install_users(name:)
        if (resp = existing_validation(name: name)).net_status_ok?
          mapper = index[name].inheritance_mapper

          # user / group
Severity: Minor
Found in lib/superhosting/controller/container/states.rb - About 3 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

Method has too many lines. [40/38]
Open

      def install_users(name:)
        if (resp = existing_validation(name: name)).net_status_ok?
          mapper = index[name].inheritance_mapper

          # user / group

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method install_users has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def install_users(name:)
        if (resp = existing_validation(name: name)).net_status_ok?
          mapper = index[name].inheritance_mapper

          # user / group
Severity: Minor
Found in lib/superhosting/controller/container/states.rb - About 1 hr to fix

    Method install_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def install_data(name:, model: nil)
            etc_mapper = @config.containers.f(name)
            if (model_ = model || etc_mapper.f('model', default: @config.default_model)).nil?
              { error: :input_error, code: :no_model_given }
            else
    Severity: Minor
    Found in lib/superhosting/controller/container/states.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

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

          def stop_mux(name:)
            if (resp = existing_validation(name: name)).net_status_ok?
              mapper = index[name].inheritance_mapper
    
              if (mux_mapper = mapper.mux).file?
    Severity: Minor
    Found in lib/superhosting/controller/container/states.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

    Rename has_sites? to sites?.
    Open

          def has_sites?(name:)

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

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

            if has_sites?(name: name)

    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

    Don't use parentheses around a method call.
    Open

            if (existing_validation(name: name)).net_status_ok? && model && index[name].model_name != model

    This cop checks for redundant parentheses.

    Example:

    # bad
    (x) if ((y.z).nil?)
    
    # good
    x if y.z.nil?

    There are no issues that match your filters.

    Category
    Status