bio-miga/miga

View on GitHub

Showing 838 of 1,651 total issues

Method parse has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def parse(path, opts = {})
      opts = default_opts(opts)

      # Read JSON
      cont = path
Severity: Minor
Found in lib/miga/json.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 check_mts has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def check_mts(cli)
    cli.say 'Looking for unarchived MyTaxa Scan runs'
    cli.load_project.each_dataset do |d|
      res = d.result(:mytaxa_scan)
      next if res.nil?
Severity: Minor
Found in lib/miga/cli/action/doctor/operations.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 perform has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def perform
    unless cli[:value].nil?
      cli.ensure_par(
        { key: '-k' },
        '%<name>s is mandatory when --value is set: provide %<flag>s'
Severity: Minor
Found in lib/miga/cli/action/option.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

Class DaemonTest has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class DaemonTest < Test::Unit::TestCase
  include TestHelper
  include DaemonHelper

  def setup
Severity: Minor
Found in test/daemon_test.rb - About 2 hrs to fix

Assignment Branch Condition size for test_daemmon_status is too high. [22.36/15]
Open

  def test_daemmon_status
    d = TestWithDaemon.new(tmpdir)
    out = capture_stdout { d.status }.string
    assert_match(/Not running/, out)

Severity: Minor
Found in test/with_daemon_test.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 test_ncbi_datasets_download_request is too high. [22.56/15]
Open

  def test_ncbi_datasets_download_request
    # No remote access needed
    rd = MiGA::RemoteDataset.new(
      'GCF_004684205.1', :genome, :ncbi_datasets_download
    )
Severity: Minor
Found in test/remote_dataset_test.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 has too many lines. [17/10]
Open

  def test_status
    d = dataset
    assert_equal(:ignore_empty, d.result_status(:trimmed_reads))
    d.add_result(:trimmed_reads)
    assert_equal(:-, d.result_status(:raw_reads))
Severity: Minor
Found in test/result_test.rb by rubocop

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.

Assignment Branch Condition size for test_advance is too high. [22.8/15]
Open

  def test_advance
    m = MiGA::MiGA.new

    # Check advance when missing total and n
    o = capture_stderr { m.advance('x', 0) }.string
Severity: Minor
Found in test/common_test.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 helper_daemon_launch_job is too high. [22.02/15]
Open

  def helper_daemon_launch_job(project_i = 0)
    declare_forks
    d1 = daemon(project_i)
    helper_datasets_with_results(1, project_i).first.inactivate!
    assert_equal(0, d1.jobs_to_run.size, 'The queue should be empty')
Severity: Minor
Found in test/daemon_helper.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 has too many lines. [17/10]
Open

  def test_flush
    d1 = daemon
    p1 = project
    helper_datasets_with_results
    p1.add_dataset(MiGA::Dataset.new(p1, 'd1').name)
Severity: Minor
Found in test/daemon_test.rb by rubocop

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.

Assignment Branch Condition size for fix_essential_genes_by_domain is too high. [22.72/15]
Open

  def fix_essential_genes_by_domain
    return if file_path(:raw_report)

    tax = source.metadata[:tax]
    return unless tax.nil? || %w[Archaea Bacteria].include?(tax[:d])
Severity: Minor
Found in lib/miga/result/stats.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 has too many lines. [17/10]
Open

  def daemon_loop
    l_say(3, 'Daemon loop start')
    reload_project
    check_datasets or check_project
    if shutdown_when_done? && (jobs_running.size + jobs_to_run.size).zero?
Severity: Minor
Found in lib/miga/daemon.rb by rubocop

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 has too many lines. [17/10]
Open

    def aai_taxtest(aai, test, opts = {})
      meaning = {
        most_likely: [0.00, 0.01],
        probably: [0.01, 0.10],
        possibly_even: [0.10, 0.50]
Severity: Minor
Found in lib/miga/tax_dist.rb by rubocop

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.

Assignment Branch Condition size for create is too high. [22.65/15]
Open

  def create
    unless MiGA::MiGA.initialized?
      warn 'Projects cannot be processed yet, first run: miga init'
    end

Severity: Minor
Found in lib/miga/project.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

Cyclomatic complexity for load_and_filter_datasets is too high. [13/6]
Open

  def load_and_filter_datasets(silent = false)
    return @objects[:filtered_datasets] unless @objects[:filtered_datasets].nil?

    say 'Listing datasets'
    ds =
Severity: Minor
Found in lib/miga/cli/objects_helper.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Assignment Branch Condition size for load_result is too high. [22.72/15]
Open

  def load_result
    return @objects[:result] unless @objects[:result].nil?

    ensure_par(result: '-r')
    obj = load_project_or_dataset
Severity: Minor
Found in lib/miga/cli/objects_helper.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 download_file_ftp is too high. [22.83/15]
Open

  def download_file_ftp(connection, file = nil, target = nil)
    # Open connection unless passed
    close_conn = false
    if connection.is_a?(String) || connection.is_a?(Symbol) ||
          connection.is_a?(URI)
Severity: Minor
Found in lib/miga/common/net.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 option_from_string is too high. [22.38/15]
Open

  def option_from_string(key, value)
    opt = assert_has_option(key)

    if ['', 'nil'].include?(value)
      nil
Severity: Minor
Found in lib/miga/common/with_option.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 has too many lines. [17/10]
Open

  def query_probability_distributions(d, cr)
    cli.say 'Querying probability distributions'
    tax = closest_relative_tax(cr)
    if %w[intax both].include? cli[:test]
      r = test_closest_relative(cr, tax, :intax)
Severity: Minor
Found in lib/miga/cli/action/tax_test.rb by rubocop

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.

Perceived complexity for load_and_filter_datasets is too high. [14/7]
Open

  def load_and_filter_datasets(silent = false)
    return @objects[:filtered_datasets] unless @objects[:filtered_datasets].nil?

    say 'Listing datasets'
    ds =
Severity: Minor
Found in lib/miga/cli/objects_helper.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points
Severity
Category
Status
Source
Language