flant/superhosting

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

Summary

Maintainability
A
2 hrs
Test Coverage

Method _safe_run_docker has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def _safe_run_docker(*docker_options, name:, restart: false)
        if restart
          _recreate_docker(*docker_options, name: name)
        elsif @docker_api.container_running?(name)
        elsif @docker_api.container_exists?(name)
Severity: Minor
Found in lib/superhosting/controller/container/docker.rb - About 1 hr 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 _collect_docker_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def _collect_docker_options(mapper:, model_or_mux: nil)
        model_or_mux ||= mapper.f('model', default: @config.default_model)
        return { error: :input_error, code: :no_docker_image_specified_in_model_or_mux, data: { name: model_or_mux } } if (image = mapper.docker.image).nil?

        all_options = mapper.docker.grep_files.map { |n| [n.name[/(.*(?=\.erb))|(.*)/].to_sym, n.value] }.to_h
Severity: Minor
Found in lib/superhosting/controller/container/docker.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

Line is too long. [168/150]
Open

        { error: :logical_error, code: :no_docker_options_specified_in_container_or_mux, data: { name: mapper_name(lib_mapper) } }.net_status_ok! if docker_options.nil?

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

        if @docker_api.container_exists?(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

Avoid using Marshal.load.
Open

        Marshal.load(docker_options)

This cop checks for the use of Marshal class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

Example:

# bad
Marshal.load("{}")
Marshal.restore("{}")

# good
Marshal.dump("{}")

# okish - deep copy hack
Marshal.load(Marshal.dump({}))

Line is too long. [156/150]
Open

        return { error: :input_error, code: :no_docker_image_specified_in_model_or_mux, data: { name: model_or_mux } } if (image = mapper.docker.image).nil?

There are no issues that match your filters.

Category
Status