bio-miga/miga

View on GitHub
lib/miga/cli/action/add.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Class has too many lines. [154/100]
Open

class MiGA::Cli::Action::Add < MiGA::Cli::Action
  def parse_cli
    cli.expect_files = true
    cli.defaults = { ref: true, ignore_dups: false }
    cli.parse do |opt|
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [48/10]
Open

  def parse_cli
    cli.expect_files = true
    cli.defaults = { ref: true, ignore_dups: false }
    cli.parse do |opt|
      opt.separator 'You can create multiple datasets with a single command; ' \
Severity: Minor
Found in lib/miga/cli/action/add.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 get_files_and_type is too high. [41.05/15]
Open

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.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 parse_cli is too high. [35.44/15]
Open

  def parse_cli
    cli.expect_files = true
    cli.defaults = { ref: true, ignore_dups: false }
    cli.parse do |opt|
      opt.separator 'You can create multiple datasets with a single command; ' \
Severity: Minor
Found in lib/miga/cli/action/add.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. [26/10]
Open

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.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_dataset is too high. [31.38/15]
Open

  def create_dataset(file, p)
    name = cli[:dataset]
    if name.nil?
      ref_file = file.is_a?(Array) ? file.first : file
      m = cli[:regexp].match(ref_file)
Severity: Minor
Found in lib/miga/cli/action/add.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 perform is too high. [26.27/15]
Open

  def perform
    p = cli.load_project
    cli.ensure_par(type: '-t')
    files, file_type = get_files_and_type

Severity: Minor
Found in lib/miga/cli/action/add.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. [20/10]
Open

  def create_dataset(file, p)
    name = cli[:dataset]
    if name.nil?
      ref_file = file.is_a?(Array) ? file.first : file
      m = cli[:regexp].match(ref_file)
Severity: Minor
Found in lib/miga/cli/action/add.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 copy_file_to_project is too high. [21.31/15]
Open

  def copy_file_to_project(file, file_type, d, p)
    return if file.nil?

    r_dir = Dataset.RESULT_DIRS[file_type[1]]
    r_path = File.expand_path("data/#{r_dir}/#{d.name}", p.path)
Severity: Minor
Found in lib/miga/cli/action/add.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. [15/10]
Open

  def perform
    p = cli.load_project
    cli.ensure_par(type: '-t')
    files, file_type = get_files_and_type

Severity: Minor
Found in lib/miga/cli/action/add.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 get_files_and_type is too high. [10/7]
Open

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.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

Method parse_cli has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def parse_cli
    cli.expect_files = true
    cli.defaults = { ref: true, ignore_dups: false }
    cli.parse do |opt|
      opt.separator 'You can create multiple datasets with a single command; ' \
Severity: Minor
Found in lib/miga/cli/action/add.rb - About 1 hr to fix

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

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.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

Block has too many lines. [44/25]
Open

    cli.parse do |opt|
      opt.separator 'You can create multiple datasets with a single command; ' \
        'simply pass all the files at the end: {FILES...}'
      opt.separator 'If -D is passed, only one dataset will be added. ' \
        'Otherwise, dataset names will be determined by the file paths (see -R)'
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Cyclomatic complexity for get_files_and_type is too high. [8/6]
Open

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.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.

Cyclomatic complexity for create_dataset is too high. [8/6]
Open

  def create_dataset(file, p)
    name = cli[:dataset]
    if name.nil?
      ref_file = file.is_a?(Array) ? file.first : file
      m = cli[:regexp].match(ref_file)
Severity: Minor
Found in lib/miga/cli/action/add.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.

Perceived complexity for create_dataset is too high. [9/7]
Open

  def create_dataset(file, p)
    name = cli[:dataset]
    if name.nil?
      ref_file = file.is_a?(Array) ? file.first : file
      m = cli[:regexp].match(ref_file)
Severity: Minor
Found in lib/miga/cli/action/add.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

Method create_dataset has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def create_dataset(file, p)
    name = cli[:dataset]
    if name.nil?
      ref_file = file.is_a?(Array) ? file.first : file
      m = cli[:regexp].match(ref_file)
Severity: Minor
Found in lib/miga/cli/action/add.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 get_files_and_type has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_files_and_type
    files = cli.files
    file_type = nil
    if files.empty?
      cli.ensure_par({ dataset: '-D' },
Severity: Minor
Found in lib/miga/cli/action/add.rb - About 1 hr to fix

Use || instead of or.
Open

      raise "Cannot extract name from file: #{ref_file}" if m.nil? or m[1].nil?
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

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

      if cli[:ignore_dups]
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

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

Use snake_case for variable names.
Open

  @@INPUT_TYPES = {
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
fooBar = 1

# good
foo_bar = 1

Example: EnforcedStyle: camelCase

# bad
foo_bar = 1

# good
fooBar = 1

Replace class var @@INPUT_TYPES with a class instance var.
Open

  @@INPUT_TYPES = {
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Missing top-level class documentation comment.
Open

class MiGA::Cli::Action::Add < MiGA::Cli::Action
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Do not prefix reader method names with get_.
Open

  def get_files_and_type
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop makes sure that accessor methods are named properly.

Example:

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

Use %i or %I for an array of symbols.
Open

      cli.opt_object(opt, [:project, :dataset_opt, :dataset_type_req])
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Use snake_case for method names.
Open

    def INPUT_TYPES
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop makes sure that all methods use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
def fooBar; end

# good
def foo_bar; end

Example: EnforcedStyle: camelCase

# bad
def foo_bar; end

# good
def fooBar; end

Missing magic comment # frozen_string_literal: true.
Open

# @package MiGA
Severity: Minor
Found in lib/miga/cli/action/add.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

There are no issues that match your filters.

Category
Status