reevoo/sapience-rb

View on GitHub

Showing 33 of 1,401 total issues

Method measure_internal has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

    def measure_internal(level, index, message, params)
      params.dup
      start     = Time.now
      exception = nil
      begin
Severity: Minor
Found in lib/sapience/base.rb - About 4 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 log_internal has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def log_internal(level, index, message = nil, payload = nil, exception = nil)
      # Exception being logged?
      if exception.nil? && payload.nil? && message.respond_to?(:backtrace) && message.respond_to?(:message)
        exception = message
        message   = nil
Severity: Minor
Found in lib/sapience/base.rb - About 4 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 to_h has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    def to_h(host = Sapience.config.host, app_name = Sapience.app_name, environment = Sapience.environment) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity, LineLength
      # Header
      h = {
        name:        name,
        pid:         $PROCESS_ID,
Severity: Minor
Found in lib/sapience/log.rb - About 4 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 measure_internal has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def measure_internal(level, index, message, params)
      params.dup
      start     = Time.now
      exception = nil
      begin
Severity: Major
Found in lib/sapience/base.rb - About 2 hrs to fix

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

        def duration_human # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
          return nil unless duration
          days, ms    = duration.divmod(MILLISECONDS_IN_DAY)
          hours, ms   = ms.divmod(MILLISECONDS_IN_HOUR)
          minutes, ms = ms.divmod(MILLISECONDS_IN_MINUTE)
    Severity: Minor
    Found in lib/sapience/log.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 Base has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Base
        # Class name to be logged
        attr_accessor :name, :filter, :log_hooks
        include Sapience::LogMethods
    
    
    Severity: Minor
    Found in lib/sapience/base.rb - About 2 hrs to fix

      Method call has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def call(log, _logger) # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity
              colors      = Sapience::AnsiColors
              level_color = colors::LEVEL_MAP[log.level]
      
      
      
      Severity: Minor
      Found in lib/sapience/formatters/color.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 to_h has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def to_h(host = Sapience.config.host, app_name = Sapience.app_name, environment = Sapience.environment) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity, LineLength
            # Header
            h = {
              name:        name,
              pid:         $PROCESS_ID,
      Severity: Minor
      Found in lib/sapience/log.rb - About 1 hr to fix

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

              def capture_type(data, payload)
                return false unless valid?
                configure_sentry
        
                options = if payload.present?
        Severity: Minor
        Found in lib/sapience/error_handler/sentry.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 log has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def log(log, message = nil, progname = nil, &block)
              # Compatibility with ::Logger
              return add(log, message, progname, &block) unless log.is_a?(Sapience::Log)
              if @@appender_thread
                @@appender_thread << lambda do
        Severity: Minor
        Found in lib/sapience/logger.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 log_internal has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def log_internal(level, index, message = nil, payload = nil, exception = nil)
              # Exception being logged?
              if exception.nil? && payload.nil? && message.respond_to?(:backtrace) && message.respond_to?(:message)
                exception = message
                message   = nil
        Severity: Minor
        Found in lib/sapience/base.rb - About 1 hr to fix

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

              def initialize(klass, level = nil, filter = nil, log_hooks = [])
                # Support filtering all messages to this logger using a Regular Expression
                # or Proc
                fail ArgumentError, ":filter must be a Regexp or Proc" unless filter.nil? || filter.is_a?(Regexp) || filter.is_a?(Proc)
          
          
          Severity: Minor
          Found in lib/sapience/base.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 payload has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def payload # rubocop:disable AbcSize
                return self[:payload] unless self[:payload].is_a?(Hash) && self[:payload][:params].is_a?(Hash)
                @payload ||= nil
                return @payload unless @payload.nil?
          
          
          Severity: Minor
          Found in lib/sapience/log.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 parse_options has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def parse_options(options)
                  @time_format     = options.key?(:time_format) ? options.delete(:time_format) : default_time_format
                  @log_host        = options.key?(:log_host) ? options.delete(:log_host) : true
                  @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
                  @exclude_fields  = options.key?(:exclude_fields) ? options.delete(:exclude_fields).map(&:to_sym) : {}
          Severity: Minor
          Found in lib/sapience/formatters/base.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 flush has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.flush # rubocop:disable AbcSize
                return unless appender_thread
                appender_thread << lambda do
                  Sapience.appenders.each do |appender|
                    next unless appender.valid?
          Severity: Minor
          Found in lib/sapience/logger.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 close has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.close
                return unless appender_thread
                appender_thread << lambda do
                  Sapience.appenders.each do |appender|
                    next unless appender.valid?
          Severity: Minor
          Found in lib/sapience/logger.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 file_name_and_line has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def file_name_and_line(short_name = false) # rubocop:disable CyclomaticComplexity
                return unless backtrace || (exception && exception.backtrace) # rubocop: disable Style/SafeNavigation
                stack = backtrace || exception.backtrace
                extract_file_and_line(stack, short_name) if stack && !stack.empty?
              end
          Severity: Minor
          Found in lib/sapience/log.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 record has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                  def record(event) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
                    return unless record?
          
                    payload = event.payload
                    name    = payload[:name]
          Severity: Minor
          Found in lib/sapience/extensions/active_record/notifications.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 each_exception has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def each_exception # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity
                # With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81
                depth      = 0
                exceptions = []
                ex         = exception
          Severity: Minor
          Found in lib/sapience/log.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 timing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def timing(metric, duration = 0, options = {})
                  if block_given?
                    start = Time.now
                    yield
                    return false unless valid?
          Severity: Minor
          Found in lib/sapience/metrics/datadog.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

          Severity
          Category
          Status
          Source
          Language