bio-miga/miga

View on GitHub
lib/miga/taxonomy/base.rb

Summary

Maintainability
A
1 hr
Test Coverage
A
95%

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

    def normalize_rank(rank)
      return unless rank
      return rank.to_sym if @@_KNOWN_RANKS_H[rank.to_sym]

      rank = rank.to_s.downcase
Severity: Minor
Found in lib/miga/taxonomy/base.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  @@LONG_RANKS = {
    root: 'root', ns: 'namespace', d: 'domain', k: 'kingdom',
    p: 'phylum', c: 'class', o: 'order', f: 'family', g: 'genus', s: 'species',
    ssp: 'subspecies', str: 'strain', ds: 'dataset'
  }
Severity: Minor
Found in lib/miga/taxonomy/base.rb and 1 other location - About 20 mins to fix
lib/miga/dataset/base.rb on lines 66..84

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 28.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Use snake_case for variable names.
Open

  @@_KNOWN_RANKS_H = Hash[@@KNOWN_RANKS.map { |i| [i, true] }]
Severity: Minor
Found in lib/miga/taxonomy/base.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

Missing magic comment # frozen_string_literal: true.
Open

# @package MiGA
Severity: Minor
Found in lib/miga/taxonomy/base.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

Missing top-level module documentation comment.
Open

module MiGA::Taxonomy::Base
Severity: Minor
Found in lib/miga/taxonomy/base.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

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

  @@LONG_RANKS = {
Severity: Minor
Found in lib/miga/taxonomy/base.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.

Pass &:to_sym as an argument to map instead of a block.
Open

  @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map { |r| r.to_sym }
Severity: Minor
Found in lib/miga/taxonomy/base.rb by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Omit the parentheses in defs when the method doesn't accept any arguments.
Open

    def LONG_RANKS()
Severity: Minor
Found in lib/miga/taxonomy/base.rb by rubocop

This cop checks for parentheses in the definition of a method, that does not take any arguments. Both instance and class/singleton methods are checked.

Example:

# bad
def foo()
  # does a thing
end

# good
def foo
  # does a thing
end

# also good
def foo() does_a_thing end

Example:

# bad
def Baz.foo()
  # does a thing
end

# good
def Baz.foo
  # does a thing
end

Use snake_case for method names.
Open

    def KNOWN_RANKS()
Severity: Minor
Found in lib/miga/taxonomy/base.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

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

  @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map { |r| r.to_sym }
Severity: Minor
Found in lib/miga/taxonomy/base.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.

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

  @@RANK_SYNONYMS = {
Severity: Minor
Found in lib/miga/taxonomy/base.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.

%w-literals should be delimited by [ and ].
Open

  @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map { |r| r.to_sym }
Severity: Minor
Found in lib/miga/taxonomy/base.rb by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Use snake_case for method names.
Open

    def LONG_RANKS()
Severity: Minor
Found in lib/miga/taxonomy/base.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

Use snake_case for variable names.
Open

  @@RANK_SYNONYMS = {
Severity: Minor
Found in lib/miga/taxonomy/base.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

Use snake_case for variable names.
Open

  @@KNOWN_RANKS = %w{ns d k p c o f g s ssp str ds}.map { |r| r.to_sym }
Severity: Minor
Found in lib/miga/taxonomy/base.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

Missing top-level class documentation comment.
Open

class MiGA::Taxonomy < MiGA::MiGA
Severity: Minor
Found in lib/miga/taxonomy/base.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

Use snake_case for variable names.
Open

  @@LONG_RANKS = {
Severity: Minor
Found in lib/miga/taxonomy/base.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 @@_KNOWN_RANKS_H with a class instance var.
Open

  @@_KNOWN_RANKS_H = Hash[@@KNOWN_RANKS.map { |i| [i, true] }]
Severity: Minor
Found in lib/miga/taxonomy/base.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.

Omit the parentheses in defs when the method doesn't accept any arguments.
Open

    def KNOWN_RANKS()
Severity: Minor
Found in lib/miga/taxonomy/base.rb by rubocop

This cop checks for parentheses in the definition of a method, that does not take any arguments. Both instance and class/singleton methods are checked.

Example:

# bad
def foo()
  # does a thing
end

# good
def foo
  # does a thing
end

# also good
def foo() does_a_thing end

Example:

# bad
def Baz.foo()
  # does a thing
end

# good
def Baz.foo
  # does a thing
end

There are no issues that match your filters.

Category
Status