zold-io/zold

View on GitHub
lib/zold/age.rb

Summary

Maintainability
A
2 hrs
Test Coverage

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

    def text(sec)
      return "#{(sec * 1_000_000).round}μs" if sec < 0.001
      return "#{(sec * 1000).round}ms" if sec < 1
      return "#{sec.round(2)}s" if sec < 60
      return "#{(sec / 60).round}m" if sec < 60 * 60
Severity: Minor
Found in lib/zold/age.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

Avoid too many return statements within this method.
Open

      return "#{hours}h" if hours < 24
Severity: Major
Found in lib/zold/age.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return "#{(days / 30).round}mo" if days < 365
    Severity: Major
    Found in lib/zold/age.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

            return "#{days}d" if days < 14
      Severity: Major
      Found in lib/zold/age.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return "#{(days / 7).round}w" if days < 40
        Severity: Major
        Found in lib/zold/age.rb - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status