flant/superhosting

View on GitHub
lib/superhosting/controller/user/user.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method _add_custom has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

      def _add_custom(name:, group:, shell: '/usr/sbin/nologin', home_dir: "/web/#{group}", uid: nil)
        debug_operation(desc: { code: :user, data: { name: name } }) do |&blk|
          if _get(name: name)
            blk.call(code: :ok)
            {}
Severity: Minor
Found in lib/superhosting/controller/user/user.rb - About 2 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 _del has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def _del(name:, group:)
        debug_operation(desc: { code: :user, data: { name: name } }) do |&blk|
          with_dry_run do |dry_run|
            resp = {}
            with_adding_group = _group_get_users(name: group).one? ? true : false
Severity: Minor
Found in lib/superhosting/controller/user/user.rb - About 2 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 _create_password has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def _create_password(generate: false)
        if generate
          password = SecureRandom.hex
        else
         loop do
Severity: Minor
Found in lib/superhosting/controller/user/user.rb - About 45 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

%w-literals should be delimited by [ and ].
Open

                user_gid, user_uid = dry_run ? %w(XXXX XXXX) : [user.gid, user.uid]

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Use 2 (not 1) spaces for indentation.
Open

         loop do

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

There are no issues that match your filters.

Category
Status