decko-commons/decko

View on GitHub
cardname/lib/cardname/manipulate.rb

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

Assignment Branch Condition size for swap_all_subsequences is too high. [25.4/15]
Open

    def swap_all_subsequences oldseq, newseq
      res = []
      i = 0
      while i <= num_parts - oldseq.num_parts
        # for performance reasons: check first character first then the rest
Severity: Minor
Found in cardname/lib/cardname/manipulate.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 swap_all_subsequences has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def swap_all_subsequences oldseq, newseq
      res = []
      i = 0
      while i <= num_parts - oldseq.num_parts
        # for performance reasons: check first character first then the rest
Severity: Minor
Found in cardname/lib/cardname/manipulate.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 match? instead of =~ when MatchData is not used.
Open

      self =~ /^#{Regexp.escape joint}/ ? self : (joint + self)
Severity: Minor
Found in cardname/lib/cardname/manipulate.rb by rubocop

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

There are no issues that match your filters.

Category
Status