crowbar/crowbar-core

View on GitHub
crowbar_framework/app/controllers/nodes_controller.rb

Summary

Maintainability
F
5 days
Test Coverage

Method bulk has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
Open

  def bulk
    @report = {
      success: [],
      failed: [],
      duplicate_public: false,
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 day 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

File nodes_controller.rb has 545 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class NodesController < ApplicationController
  # allow node polling during the upgrade
  skip_before_filter :upgrade, only: [:index]

  api :GET, "/nodes", "List all nodes and their status"
Severity: Major
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 day to fix

Method get_node_and_network has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def get_node_and_network(node_name)
    network = {}
    @network = []
    @node = Node.find_by_name(node_name) if @node.nil?
    if @node
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 4 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 bulk has 93 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def bulk
    @report = {
      success: [],
      failed: [],
      duplicate_public: false,
Severity: Major
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 3 hrs to fix

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

  def save_node
    if params[:group] and params[:group] != "" and !(params[:group] =~ /^[a-zA-Z][a-zA-Z0-9._:-]+$/)
      flash[:alert] = t("nodes.list.group_error", failed: @node.name)
      return false
    end
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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

Consider simplifying this complex logical expression.
Open

    if (params[:raid_type] == "raid1" && raid_disks_selected < 2) || \
        (params[:raid_type] == "raid0" && raid_disks_selected < 1) || \
        (params[:raid_type] == "raid5" && raid_disks_selected < 3) || \
        (params[:raid_type] == "raid6" && raid_disks_selected < 4) || \
        (params[:raid_type] == "raid10" && raid_disks_selected < 4)
Severity: Critical
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 2 hrs to fix

Method save_node has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def save_node
    if params[:group] and params[:group] != "" and !(params[:group] =~ /^[a-zA-Z][a-zA-Z0-9._:-]+$/)
      flash[:alert] = t("nodes.list.group_error", failed: @node.name)
      return false
    end
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 hr to fix

Method status has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def status
    @result = {
      nodes: {},
      groups: {}
    }.tap do |result|
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 hr to fix

Method get_node_and_network has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_node_and_network(node_name)
    network = {}
    @network = []
    @node = Node.find_by_name(node_name) if @node.nil?
    if @node
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 hr to fix

Method hit has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def hit
    name = params[:name] || params[:id]
    machine = Node.find_by_name(name)

    respond_to do |format|
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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 update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    unless request.post?
      raise ActionController::UnknownHttpMethod.new("POST is required to update proposal #{params[:id]}")
    end

Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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 hit has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def hit
    name = params[:name] || params[:id]
    machine = Node.find_by_name(name)

    respond_to do |format|
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.rb - About 1 hr to fix

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

  def show
    get_node_and_network(params[:id] || params[:name])
    if @node.nil?
      msg = "Node #{params[:id] || params[:name]}: not found"
      if request.format == "html"
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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 index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    @sum = 0
    @groups = {}
    session[:node] = params[:name]
    if params.key?(:role)
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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

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

  def get_nodes_and_groups(node_name, draggable = true)
    @sum = 0
    @groups = {}
    @nodes  = {}
    raw_nodes = Node.all
Severity: Minor
Found in crowbar_framework/app/controllers/nodes_controller.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

There are no issues that match your filters.

Category
Status