AlbertGazizov/attr_validator

View on GitHub

Showing 15 of 21 total issues

Method class_attribute has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  def class_attribute(*attrs)
    options = attrs.last.is_a?(Hash) ? attrs.pop : {}
    instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
    instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
    instance_predicate = options.fetch(:instance_predicate, true)
Severity: Minor
Found in lib/attr_validator/core_extensions/class_attribute.rb - About 3 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 skip_validation? has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def skip_validation?(options)
    if options[:if]
      if options[:if].is_a?(Symbol)
        true unless self.send(options[:if])
      elsif options[:if].is_a?(Proc)
Severity: Minor
Found in lib/attr_validator/validator.rb - About 3 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 validate has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def self.validate(number, options)
    return [] if number.nil?

    errors = []
    if options[:greater_than]
Severity: Minor
Found in lib/attr_validator/validators/numericality_validator.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

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

  def validate(entity)
    errors = AttrValidator::ValidationErrors.new
    self.validations ||= {}
    self.custom_validations ||= []
    self.associated_validations ||= {}
Severity: Minor
Found in lib/attr_validator/validator.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 ValidationErrors has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class AttrValidator::ValidationErrors
  attr_reader :messages

   def initialize
      @messages = {}
Severity: Minor
Found in lib/attr_validator/validation_errors.rb - About 2 hrs to fix

    Method class_attribute has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def class_attribute(*attrs)
        options = attrs.last.is_a?(Hash) ? attrs.pop : {}
        instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
        instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
        instance_predicate = options.fetch(:instance_predicate, true)
    Severity: Minor
    Found in lib/attr_validator/core_extensions/class_attribute.rb - About 1 hr to fix

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

        def self.validate(object, options)
          return [] if object.nil?
      
          errors = []
          if options[:min]
      Severity: Minor
      Found in lib/attr_validator/validators/length_validator.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 validate has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def validate(entity)
          errors = AttrValidator::ValidationErrors.new
          self.validations ||= {}
          self.custom_validations ||= []
          self.associated_validations ||= {}
      Severity: Minor
      Found in lib/attr_validator/validator.rb - About 1 hr to fix

        Method append_features has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def append_features(base)
              if base.instance_variable_defined?(:@_dependencies)
                base.instance_variable_get(:@_dependencies) << self
                return false
              else
        Severity: Minor
        Found in lib/attr_validator/concern.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

        Avoid deeply nested control flow statements.
        Open

                true if self.instance_exec(&options[:unless])
        Severity: Major
        Found in lib/attr_validator/validator.rb - About 45 mins to fix

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

            def self.validate(value, email_flag)
              return [] if value.nil?
          
              errors = []
              if email_flag
          Severity: Minor
          Found in lib/attr_validator/validators/email_validator.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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.validate(value, presence)
              errors = []
              if presence
                if value.nil? || (value.is_a?(String) && value.strip.length == 0)
                  errors << AttrValidator::I18n.t('errors.can_not_be_blank')
          Severity: Minor
          Found in lib/attr_validator/validators/presence_validator.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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.validate(value, url_flag)
              return [] if value.nil?
          
              errors = []
              if url_flag
          Severity: Minor
          Found in lib/attr_validator/validators/url_validator.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 validate_children has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def validate_children(association_name, validator, children, errors)
              if validator.respond_to?(:validate_all)
                children_errors = validator.validate_all(children)
              elsif validator.respond_to?(:validate)
                children_errors = children.inject([]) do |errors, child|
          Severity: Minor
          Found in lib/attr_validator/validator.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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.validate(value, options)
              return [] if value.nil?
          
              errors = []
              if options[:in]
          Severity: Minor
          Found in lib/attr_validator/validators/inclusion_validator.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

          Severity
          Category
          Status
          Source
          Language