savonarola/pulse_meter_core

View on GitHub

Showing 12 of 12 total issues

Class Timeline has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Timeline < Base
      include PulseMeter::Mixins::Utils
      include PulseMeter::Sensor::TimelineReduce

      MAX_TIMESPAN_POINTS = 1000
Severity: Minor
Found in lib/pulse_meter/sensor/timeline.rb - About 2 hrs to fix

    Method dump! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

            def dump!(safe = true)
              ensure_storability!
              serialized_obj = to_yaml
              if safe
                unless redis.hsetnx(DUMP_REDIS_KEY, name, serialized_obj)
    Severity: Minor
    Found in lib/pulse_meter/mixins/dumper.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 start has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def start(max_packets = nil)
          while true do
            if max_packets
              break if max_packets <= 0
              max_packets -= 1
    Severity: Minor
    Found in lib/pulse_meter/udp_server.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 assert_ranged_float! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def assert_ranged_float!(options, key, from, to)
            f = options[key]
            raise ArgumentError, "#{key} should be defined" unless f
            raise ArgumentError, "#{key} should be float" unless f.respond_to?(:to_f)
            f = f.to_f
    Severity: Minor
    Found in lib/pulse_meter/mixins/utils.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 assert_positive_integer! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def assert_positive_integer!(options, key, default = nil)
            value = options[key] || default
            raise ArgumentError, "#{key} should be defined" unless value
            raise ArgumentError, "#{key} should be integer" unless value.respond_to?(:to_i)
            raise ArgumentError, "#{key} should be positive" unless value.to_i > 0
    Severity: Minor
    Found in lib/pulse_meter/mixins/utils.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 collect_ids_to_reduce has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def collect_ids_to_reduce(time, time_from, time_to)
            ids = []
            while (time > time_from) # go backwards
              time -= interval
              interval_id = get_interval_id(time)
    Severity: Minor
    Found in lib/pulse_meter/sensor/timeline_reduce.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 create_sensor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def create_sensor(name, opts)
            sensor_type = opts.respond_to?(:sensor_type) ? opts.sensor_type : opts[:sensor_type]
            klass_s = sensor_class(sensor_type)
            klass = constantize(klass_s)
            raise ArgumentError, "#{klass_s} is not a valid class for a sensor" unless klass
    Severity: Minor
    Found in lib/pulse_meter/sensor/configuration.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 drop_within has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def drop_within(from, till)
            raise ArgumentError unless from.kind_of?(Time) && till.kind_of?(Time)
            start_time, end_time = time_to_redis(from.to_i), time_to_redis(till.to_i)
            current_interval_id = get_interval_id(start_time) + interval
            keys = []
    Severity: Minor
    Found in lib/pulse_meter/sensor/timeline.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

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

          def method_missing(name, *args)
            with_resque do
              name = name.to_s
              if sensors.has_key?(name)
                sensors[name].event(*args)
    Severity: Minor
    Found in lib/pulse_meter/sensor/configuration.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

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

          def define_without_observer(method_owner, method, without_observer)
            if has_method?(method_owner, method)
              #for redefined methods
              unless has_method?(method_owner, without_observer)
                method_owner.send(:alias_method, without_observer, method)
    Severity: Minor
    Found in lib/pulse_meter/observer.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      module Sensor
        module Timelined
          # Calculates max value in interval
          class Max < ZSetBased
    
    
    Severity: Minor
    Found in lib/pulse_meter/sensor/timelined/max.rb and 1 other location - About 15 mins to fix
    lib/pulse_meter/sensor/timelined/min.rb on lines 2..13

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 25.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      module Sensor
        module Timelined
          # Calculates min value in interval
          class Min < ZSetBased
    
    
    Severity: Minor
    Found in lib/pulse_meter/sensor/timelined/min.rb and 1 other location - About 15 mins to fix
    lib/pulse_meter/sensor/timelined/max.rb on lines 2..13

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 25.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Severity
    Category
    Status
    Source
    Language