bio-miga/miga

View on GitHub
lib/miga/metadata.rb

Summary

Maintainability
A
25 mins
Test Coverage
A
95%

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

class MiGA::Metadata < MiGA::MiGA
  # Class-level

  ##
  # Does the metadata described in +path+ already exist?
Severity: Minor
Found in lib/miga/metadata.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.

Assignment Branch Condition size for save is too high. [30.68/15]
Open

  def save
    return if self[:never_save]
    return if !saved_hash.nil? && saved_hash == data.hash

    MiGA::MiGA.DEBUG "Metadata.save #{path}"
Severity: Minor
Found in lib/miga/metadata.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 save
    return if self[:never_save]
    return if !saved_hash.nil? && saved_hash == data.hash

    MiGA::MiGA.DEBUG "Metadata.save #{path}"
Severity: Minor
Found in lib/miga/metadata.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 save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def save
    return if self[:never_save]
    return if !saved_hash.nil? && saved_hash == data.hash

    MiGA::MiGA.DEBUG "Metadata.save #{path}"
Severity: Minor
Found in lib/miga/metadata.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

Use yield instead of blk.call.
Open

    data.each { |k, v| blk.call(k, v) }
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop identifies the use of a &block parameter and block.call where yield would do just as well.

Example:

# bad
def method(&block)
  block.call
end
def another(&func)
  func.call 1, 2, 3
end

# good
def method
  yield
end
def another
  yield 1, 2, 3
end

Do not return a value in []=.
Open

    return @data.delete(k) if v.nil?
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop checks for the use of a return with a value in a context where the value will be ignored. (initialize and setter methods)

Example:

# bad
def initialize
  foo
  return :qux if bar?
  baz
end

def foo=(bar)
  return 42
end

Example:

# good
def initialize
  foo
  return if bar?
  baz
end

def foo=(bar)
  return
end

Redundant self detected.
Open

    self.load if @data.nil?
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Avoid single-line method definitions.
Open

  def self.exist?(path) File.exist? path end
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.

Example:

# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end

# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end

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

    unless File.exist? path
Severity: Minor
Found in lib/miga/metadata.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

Avoid the use of Perl-style backrefs.
Open

      data[$1.to_sym]&.fetch($2)
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.

Example:

# bad
puts $1

# good
puts Regexp.last_match(1)

Avoid the use of Perl-style backrefs.
Open

      data[$1.to_sym]&.fetch($2)
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.

Example:

# bad
puts $1

# good
puts Regexp.last_match(1)

Missing magic comment # frozen_string_literal: true.
Open

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

Redundant self detected.
Open

    self.load if @data.nil?
Severity: Minor
Found in lib/miga/metadata.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

There are no issues that match your filters.

Category
Status