zold-io/zold

View on GitHub
lib/zold/copies.rb

Summary

Maintainability
C
1 day
Test Coverage

Method add has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def add(content, host, port, score, time: Time.now, master: false)
      raise "Content can't be empty" if content.empty?
      raise 'TCP port must be of type Integer' unless port.is_a?(Integer)
      raise "TCP port can't be negative: #{port}" if port.negative?
      raise 'Time must be of type Time' unless time.is_a?(Time)
Severity: Minor
Found in lib/zold/copies.rb - About 2 hrs 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 clean has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def clean(max: 24 * 60 * 60)
      Futex.new(file, log: @log).open do
        list = load
        list.reject! do |s|
          if s[:time] >= Time.now - max
Severity: Minor
Found in lib/zold/copies.rb - About 2 hrs 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 add has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def add(content, host, port, score, time: Time.now, master: false)
      raise "Content can't be empty" if content.empty?
      raise 'TCP port must be of type Integer' unless port.is_a?(Integer)
      raise "TCP port can't be negative: #{port}" if port.negative?
      raise 'Time must be of type Time' unless time.is_a?(Time)
Severity: Minor
Found in lib/zold/copies.rb - About 1 hr to fix

    Method clean has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def clean(max: 24 * 60 * 60)
          Futex.new(file, log: @log).open do
            list = load
            list.reject! do |s|
              if s[:time] >= Time.now - max
    Severity: Minor
    Found in lib/zold/copies.rb - About 1 hr to fix

      Method all has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def all(masters_first: true)
            Futex.new(file, log: @log).open(false) do
              list = load.group_by { |s| s[:name] }.map do |name, scores|
                {
                  name: name,
      Severity: Minor
      Found in lib/zold/copies.rb - About 55 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

      There are no issues that match your filters.

      Category
      Status