attr-encrypted/attr_encrypted

View on GitHub

Showing 11 of 13 total issues

Method attr_encrypted has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

  def attr_encrypted(*attributes)
    options = attributes.last.is_a?(Hash) ? attributes.pop : {}
    options = attr_encrypted_default_options.dup.merge!(attr_encrypted_options).merge!(options)

    options[:encode] = options[:default_encoding] if options[:encode] == true
Severity: Minor
Found in lib/attr_encrypted.rb - About 5 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 evaluated_attr_encrypted_options_for has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def evaluated_attr_encrypted_options_for(attribute)
        evaluated_options = Hash.new
        attributes = encrypted_attributes[attribute.to_sym]
        attribute_option_value = attributes[:attribute]

Severity: Minor
Found in lib/attr_encrypted.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 extended has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def self.extended(base) # :nodoc:
          base.class_eval do

            # https://github.com/attr-encrypted/attr_encrypted/issues/68
            alias_method :reload_without_attr_encrypted, :reload
Severity: Minor
Found in lib/attr_encrypted/adapters/active_record.rb - About 1 hr to fix

    Method attr_encrypted has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def attr_encrypted(*attributes)
        options = attributes.last.is_a?(Hash) ? attributes.pop : {}
        options = attr_encrypted_default_options.dup.merge!(attr_encrypted_options).merge!(options)
    
        options[:encode] = options[:default_encoding] if options[:encode] == true
    Severity: Minor
    Found in lib/attr_encrypted.rb - About 1 hr to fix

      Method load_iv_for_attribute has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def load_iv_for_attribute(attribute, options)
              encrypted_attribute_name = options[:attribute]
              encode_iv = options[:encode_iv]
              iv = options[:iv] || send("#{encrypted_attribute_name}_iv")
              if options[:operation] == :encrypting
      Severity: Minor
      Found in lib/attr_encrypted.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 attr_encrypted has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                def attr_encrypted(*attrs)
                  super
                  options = attrs.extract_options!
                  attr = attrs.pop
                  attribute attr if ::ActiveRecord::VERSION::STRING >= "5.1.0"
      Severity: Minor
      Found in lib/attr_encrypted/adapters/active_record.rb - About 1 hr to fix

        Method encrypt has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def encrypt(attribute, value, options = {})
            options = encrypted_attributes[attribute.to_sym].merge(options)
            if options[:if] && !options[:unless] && (options[:allow_empty_value] || not_empty?(value))
              value = options[:marshal] ? options[:marshaler].send(options[:dump_method], value) : value.to_s
              encrypted_value = options[:encryptor].send(options[:encrypt_method], options.merge!(value: value))
        Severity: Minor
        Found in lib/attr_encrypted.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 decrypt has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def decrypt(attribute, encrypted_value, options = {})
            options = encrypted_attributes[attribute.to_sym].merge(options)
            if options[:if] && !options[:unless] && not_empty?(encrypted_value)
              encrypted_value = encrypted_value.unpack(options[:encode]).first if options[:encode]
              value = options[:encryptor].send(options[:decrypt_method], options.merge!(value: encrypted_value))
        Severity: Minor
        Found in lib/attr_encrypted.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 load_salt_for_attribute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def load_salt_for_attribute(attribute, options)
                encrypted_attribute_name = options[:attribute]
                encode_salt = options[:encode_salt]
                salt = options[:salt] || send("#{encrypted_attribute_name}_salt")
                if options[:operation] == :encrypting
        Severity: Minor
        Found in lib/attr_encrypted.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 attr_encrypted has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

                  def attr_encrypted(*attrs)
                    super
                    options = attrs.extract_options!
                    attr = attrs.pop
                    attribute attr if ::ActiveRecord::VERSION::STRING >= "5.1.0"
        Severity: Minor
        Found in lib/attr_encrypted/adapters/active_record.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 method_missing_with_attr_encrypted has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                  def method_missing_with_attr_encrypted(method, *args, &block)
                    if match = /^(find|scoped)_(all_by|by)_([_a-zA-Z]\w*)$/.match(method.to_s)
                      attribute_names = match.captures.last.split('_and_')
                      attribute_names.each_with_index do |attribute, index|
                        if attr_encrypted?(attribute) && encrypted_attributes[attribute.to_sym][:mode] == :single_iv_and_salt
        Severity: Minor
        Found in lib/attr_encrypted/adapters/active_record.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

        Severity
        Category
        Status
        Source
        Language