airbrake/airbrake-ruby

View on GitHub
lib/airbrake-ruby/tdigest.rb

Summary

Maintainability
D
2 days
Test Coverage

File tdigest.rb has 280 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rbtree'

module Airbrake
  # Ruby implementation of Ted Dunning's t-digest data structure.
  #
Severity: Minor
Found in lib/airbrake-ruby/tdigest.rb - About 2 hrs to fix

    Method percentile has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def percentile(p)
          is_array = p.is_a? Array
          p = [p] unless is_array
          p.map! do |item|
            unless (0..1).cover?(item)
    Severity: Minor
    Found in lib/airbrake-ruby/tdigest.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

    Class TDigest has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class TDigest
        VERBOSE_ENCODING = 1
        SMALL_ENCODING   = 2
    
        # Centroid represents a number of data points.
    Severity: Minor
    Found in lib/airbrake-ruby/tdigest.rb - About 2 hrs to fix

      Method from_bytes has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.from_bytes(bytes)
            format, compression, size = bytes.unpack('NGN')
            tdigest = new(1 / compression)
      
            start_idx = 16 # after header
      Severity: Minor
      Found in lib/airbrake-ruby/tdigest.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 p_rank has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def p_rank(x)
            is_array = x.is_a? Array
            x = [x] unless is_array
      
            min = @centroids.first
      Severity: Minor
      Found in lib/airbrake-ruby/tdigest.rb - About 1 hr 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 from_bytes has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.from_bytes(bytes)
            format, compression, size = bytes.unpack('NGN')
            tdigest = new(1 / compression)
      
            start_idx = 16 # after header
      Severity: Minor
      Found in lib/airbrake-ruby/tdigest.rb - About 1 hr to fix

        Method _digest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def _digest(x, n)
              # Use 'first' and 'last' instead of min/max because of performance reasons
              # This works because RBTree is sorted
              min = min.last if (min = @centroids.first)
              max = max.last if (max = @centroids.last)
        Severity: Minor
        Found in lib/airbrake-ruby/tdigest.rb - About 1 hr 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 _cumulate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _cumulate(exact: false, force: false)
              unless force
                factor = if @last_cumulate == 0
                           Float::INFINITY
                         else
        Severity: Minor
        Found in lib/airbrake-ruby/tdigest.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

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

            def bound_mean_cumn(cumn)
              last_c = nil
              bounds = []
              @centroids.each_value do |v|
                if v.mean_cumn == cumn
        Severity: Minor
        Found in lib/airbrake-ruby/tdigest.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

        Method find_nearest has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def find_nearest(x)
              return if size == 0
        
              upper_key, upper = @centroids.upper_bound(x)
              lower_key, lower = @centroids.lower_bound(x)
        Severity: Minor
        Found in lib/airbrake-ruby/tdigest.rb - About 35 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

        Method as_small_bytes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def as_small_bytes
              size = @centroids.size
              output = [self.class::SMALL_ENCODING, compression, size]
              x = 0
              # delta encoding allows saving 4-bytes floats
        Severity: Minor
        Found in lib/airbrake-ruby/tdigest.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

        There are no issues that match your filters.

        Category
        Status