getsentry/raven-ruby

Very high overall complexity: 446

# frozen_string_literal: true
require 'rubygems'
require 'socket'
require 'securerandom'
require 'digest/md5'
Found in Raven::Event - About 3 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

High overall complexity: 240

require 'uri'

module Raven
  class Configuration
    # Directories to be recognized as part of your app. e.g. if you
Found in Raven::Configuration - About 1 day 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 complex method in #add_exception_interface

      def add_exception_interface(evt, exc)
        evt.interface(:exception) do |exc_int|
          exceptions = [exc]
          context = Set.new [exc.object_id]
          backtraces = Set.new
Found in Raven::Event - About 1 day 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

Very complex method in #initialize

    def initialize(init = {})
      @configuration = init[:configuration] || Raven.configuration
      @interfaces    = {}
      @breadcrumbs   = init[:breadcrumbs] || Raven.breadcrumbs
      @context       = init[:context] || Raven.context
Found in Raven::Event - About 1 day 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

Very complex method in .test

    def self.test(dsn = nil, silent = false) # rubocop:disable all
      if silent
        Raven.configuration.logger = ::Logger.new(nil)
      else
        logger = ::Logger.new(STDOUT)
Found in Raven::CLI - About 1 day 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 'uri'

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

    Complex method in #stacktrace_interface_from

          def stacktrace_interface_from(int, evt, backtrace)
            backtrace = Backtrace.parse(backtrace)
    
            int.frames = []
            backtrace.lines.reverse_each do |line|
    Found in Raven::Event - About 6 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 5 hrs to fix

      Complex method in #from_exception

            def from_exception(exc, options = {}, &block)
              exception_context = get_exception_context(exc) || {}
              options = Raven::Utils::DeepMergeHash.deep_merge(exception_context, options)
      
              configuration = options[:configuration] || Raven.configuration
      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 #set_conn

            def set_conn
              configuration.logger.debug "Raven HTTP Transport connecting to #{configuration.server}"
      
              ssl_configuration = configuration.ssl || {}
              ssl_configuration[:verify] = configuration.ssl_verification
      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 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 #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 #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 #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::HTTPHeaders < Processor
            DEFAULT_FIELDS = ["Authorization"].freeze
        
            attr_accessor :sanitize_http_headers
        Found in Raven::Processor::HTTPHeaders and 1 other location - About 3 hrs to fix
        lib/raven/processor/sanitizedata.rb on lines 58..61

        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/http_headers.rb on lines 28..31

        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

        Complex method in #sanitize

            def sanitize(k, v)
              if v.is_a?(Hash)
                process(v)
              elsif v.is_a?(Array)
                v.map { |a| sanitize(k, a) }
        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 class definition

        # frozen_string_literal: true
        require 'rubygems'
        require 'socket'
        require 'securerandom'
        require 'digest/md5'
        Found in Raven::Event - About 3 hrs to fix

          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 #format_headers_for_sentry

              def format_headers_for_sentry(env_hash)
                env_hash.each_with_object({}) do |(key, value), memo|
                  key = key.to_s # rack env can contain symbols
                  value = value.to_s
                  next unless key.upcase == key # Non-upper case stuff isn't either
          Found in Raven::RackInterface - 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 #initialize

              def initialize
                self.async = false
                self.context_lines = 3
                self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
                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 #qualified_const_get

                def qualified_const_get(x)
                  x = x.to_s
                  parts = x.split("::")
                  parts.reject!(&:empty?)
          
          
          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 #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 #server=

              def server=(value)
                uri = URI.parse(value)
                uri_path = uri.path.split('/')
          
                if uri.user
          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 #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 .included

                def self.included(base)
                  base.class_eval do
                    rescue_from(Exception) do |exception|
                      # Do not capture exceptions when using Sidekiq so we don't capture
                      # The same exception twice.
          Found in Raven::Rails::ActiveJob - 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