getsentry/raven-ruby

View on GitHub

Very high overall complexity: 319

# frozen_string_literal: true
require 'socket'
require 'securerandom'

module Raven
Found in Raven::Event - About 2 days to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Very high overall complexity: 312

require 'uri'

module Raven
  class Configuration
    # Directories to be recognized as part of your app. e.g. if you
Found in Raven::Configuration - About 2 days to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Complex class definition

require 'uri'

module Raven
  class Configuration
    # Directories to be recognized as part of your app. e.g. if you
Found in Raven::Configuration - About 7 hrs to fix

    Complex method in .test

        def self.test(dsn = nil, silent = false, config = nil) # rubocop:disable all
          config ||= Raven.configuration
    
          config.logger = if silent
                            ::Logger.new(nil)
    Found in Raven::CLI - About 7 hrs to fix

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Complex class definition

    require 'rails'
    
    module Raven
      class Rails < ::Rails::Railtie
        require 'raven/integrations/rails/overrides/streaming_reporter'
    Found in Raven::Rails - About 7 hrs to fix

      Complex method in #add_exception_interface

          def add_exception_interface(exc)
            interface(:exception) do |exc_int|
              exceptions = exception_chain_to_array(exc)
              backtraces = Set.new
              exc_int.values = exceptions.map do |e|
      Found in Raven::Event - About 5 hrs to fix

      Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

      Refactorings

      Read More

      Complex class definition

      require 'delayed_job'
      
      module Delayed
        module Plugins
          class Raven < ::Delayed::Plugin
      Found in Delayed::Plugins::Raven - About 4 hrs to fix

        Complex method in #process

            def process(value)
              case value
              when Hash
                !value.frozen? ? value.merge!(value) { |_, v| process v } : value.merge(value) { |_, v| process v }
              when Array
        Found in Raven::Processor::UTF8Conversion - About 4 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #send_event

              def send_event(auth_header, data, options = {})
                unless configuration.sending_allowed?
                  logger.debug("Event not sent: #{configuration.error_messages}")
                end
        
        
        Found in Raven::Transports::HTTP - About 4 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #capture_type

            def capture_type(obj, options = {})
              unless configuration.capture_allowed?(obj)
                logger.debug("#{obj} excluded from capture: #{configuration.error_messages}")
                return false
              end
        Found in Raven::Instance - About 4 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #stacktrace_interface_from

            def stacktrace_interface_from(backtrace)
              Backtrace.parse(backtrace).lines.reverse.each_with_object([]) do |line, memo|
                frame = StacktraceInterface::Frame.new
                frame.abs_path = line.file if line.file
                frame.function = line.method if line.method
        Found in Raven::Event - About 4 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #format_headers_for_sentry

            def format_headers_for_sentry(env_hash)
              env_hash.each_with_object({}) do |(key, value), memo|
                begin
                  key = key.to_s # rack env can contain symbols
                  value = value.to_s
        Found in Raven::RackInterface - About 3 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #process

            def process(value, key = nil)
              case value
              when Hash
                !value.frozen? ? value.merge!(value) { |k, v| process v, k } : value.merge(value) { |k, v| process v, k }
              when Array
        Found in Raven::Processor::SanitizeData - About 3 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #safely_prepend

            def safely_prepend(module_name, opts = {})
              return if opts[:to].nil? || opts[:from].nil?
              if opts[:to].respond_to?(:prepend, true)
                opts[:to].send(:prepend, opts[:from].const_get(module_name))
              else
        Found in Raven - About 3 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Similar code found in 1 other location

        module Raven
          class Processor::RemoveCircularReferences < Processor
            def process(value, visited = [])
              return "(...)" if visited.include?(value.__id__)
              visited << value.__id__ if value.is_a?(Array) || value.is_a?(Hash)
        lib/raven/processor/sanitizedata.rb on lines 22..24

        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).

        Refactorings

        Further Reading

        Similar code found in 1 other location

        # frozen_string_literal: true
        require 'json'
        
        module Raven
          class Processor::SanitizeData < Processor
        Found in Raven::Processor::SanitizeData and 1 other location - About 3 hrs to fix
        lib/raven/processor/removecircularreferences.rb on lines 8..10

        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).

        Refactorings

        Further Reading

        Complex method in #add_breadcrumb

            def add_breadcrumb(severity, message = nil, progname = nil)
              message = progname if message.nil? # see Ruby's Logger docs for why
              return if ignored_logger?(progname)
              return if message.nil? || message == ""
        
        
        Found in Raven::BreadcrumbLogger - About 3 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Similar code found in 1 other location

        module Raven
          class Processor::RemoveCircularReferences < Processor
            def process(value, visited = [])
              return "(...)" if visited.include?(value.__id__)
              visited << value.__id__ if value.is_a?(Array) || value.is_a?(Hash)
        lib/raven/processor/sanitizedata.rb on lines 24..26

        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).

        Refactorings

        Further Reading

        Similar code found in 1 other location

        # frozen_string_literal: true
        require 'json'
        
        module Raven
          class Processor::SanitizeData < Processor
        Found in Raven::Processor::SanitizeData and 1 other location - About 3 hrs to fix
        lib/raven/processor/removecircularreferences.rb on lines 10..12

        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).

        Refactorings

        Further Reading

        Complex method in #initialize

            def initialize
              self.async = false
              self.context_lines = 3
              self.current_environment = current_environment_from_env
              self.encoding = 'gzip'
        Found in Raven::Configuration - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #inject_only

            def inject_only(*only_integrations)
              only_integrations = only_integrations.map(&:to_s)
              integrations_to_load = Raven::AVAILABLE_INTEGRATIONS & only_integrations
              not_found_integrations = only_integrations - integrations_to_load
              if not_found_integrations.any?
        Found in Raven - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #set_core_attributes_from_context

            def set_core_attributes_from_context
              self.transaction ||= context.transaction.last
        
              # If this is a Rack event, merge Rack context
              add_rack_context if !self[:http] && context.rack_env
        Found in Raven::Event - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #server=

            def server=(value)
              return if value.nil?
              uri = URI.parse(value)
              uri_path = uri.path.split('/')
        
        
        Found in Raven::Configuration - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #set_conn

              def set_conn
                configuration.logger.debug "Raven HTTP Transport connecting to #{configuration.server}"
        
                Faraday.new(configuration.server, :ssl => ssl_configuration) do |builder|
                  configuration.faraday_builder.call(builder) if configuration.faraday_builder
        Found in Raven::Transports::HTTP - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #failed_send

            def failed_send(e, event)
              @state.failure
              if e # exception was raised
                configuration.logger.error "Unable to record event with remote Sentry server (#{e.class} - #{e.message}):\n#{e.backtrace[0..10].join("\n")}"
              else
        Found in Raven::Client - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #to_hash

              def to_hash(*args)
                data = super(*args)
                data[:filename] = filename
                data.delete(:vars) unless vars && !vars.empty?
                data.delete(:pre_context) unless pre_context && !pre_context.empty?
        Found in Raven::StacktraceInterface::Frame - About 2 hrs to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex method in #process

            def process(value, visited = [])
              return "(...)" if visited.include?(value.__id__)
              visited << value.__id__ if value.is_a?(Array) || value.is_a?(Hash)
        
              case value
        Found in Raven::Processor::RemoveCircularReferences - About 1 hr to fix

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex class definition

        # frozen_string_literal: true
        require 'socket'
        require 'securerandom'
        
        module Raven
        Found in Raven::Event - About 1 hr to fix