ClusterLabs/hawk

View on GitHub
hawk/app/lib/hb_report.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Assignment Branch Condition size for initialize is too high. [30.72/15]
Open

  def initialize(name = nil)
    tmpbase = Rails.root.join('tmp', 'pids')
    reports = Rails.root.join('tmp', 'reports')
    tmpbase.mkpath unless tmpbase.directory?
    reports.mkpath unless reports.directory?
Severity: Minor
Found in hawk/app/lib/hb_report.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for generate is too high. [30.61/15]
Open

  def generate(from_time, to_time, all_nodes = true)
    [@outfile, @errfile, @exitfile, @timefile].each do |fn|
      File.unlink(fn) if File.exist?(fn)
    end
    @lastexit = nil
Severity: Minor
Found in hawk/app/lib/hb_report.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method generate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def generate(from_time, to_time, all_nodes = true)
    [@outfile, @errfile, @exitfile, @timefile].each do |fn|
      File.unlink(fn) if File.exist?(fn)
    end
    @lastexit = nil
Severity: Minor
Found in hawk/app/lib/hb_report.rb - About 1 hr to fix

    Method initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def initialize(name = nil)
        tmpbase = Rails.root.join('tmp', 'pids')
        reports = Rails.root.join('tmp', 'reports')
        tmpbase.mkpath unless tmpbase.directory?
        reports.mkpath unless reports.directory?
    Severity: Minor
    Found in hawk/app/lib/hb_report.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

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

      def generate(from_time, to_time, all_nodes = true)
        [@outfile, @errfile, @exitfile, @timefile].each do |fn|
          File.unlink(fn) if File.exist?(fn)
        end
        @lastexit = nil
    Severity: Minor
    Found in hawk/app/lib/hb_report.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

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

      def err_lines
        err = []
        begin
          File.new(@errfile).read.split(/\n/).each do |e|
            next if e.empty?
    Severity: Minor
    Found in hawk/app/lib/hb_report.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

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

          File.new(@errfile).read.split(/\n/).each do |e|
            next if e.empty?
            err << e
          end if File.exist?(@errfile)
    Severity: Minor
    Found in hawk/app/lib/hb_report.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

    There are no issues that match your filters.

    Category
    Status