AlbertGazizov/attr_validator

View on GitHub

Showing 21 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

          Similar blocks of code found in 2 locations. 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 and 1 other location - About 40 mins to fix
          lib/attr_validator/validators/email_validator.rb on lines 32..41

          Duplicated Code

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

          Tuning

          This issue has a mass of 37.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. 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 and 1 other location - About 40 mins to fix
          lib/attr_validator/validators/url_validator.rb on lines 8..18

          Duplicated Code

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

          Tuning

          This issue has a mass of 37.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. 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 and 1 other location - About 35 mins to fix
          lib/attr_validator/validators/exclusion_validator.rb on lines 6..15

          Duplicated Code

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

          Tuning

          This issue has a mass of 36.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            def self.validate(value, options)
              return [] if value.nil?
          
              errors = []
              if options[:in]
          Severity: Minor
          Found in lib/attr_validator/validators/exclusion_validator.rb and 1 other location - About 35 mins to fix
          lib/attr_validator/validators/inclusion_validator.rb on lines 9..18

          Duplicated Code

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

          Tuning

          This issue has a mass of 36.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                if options[:if].is_a?(Symbol)
                  true unless self.send(options[:if])
                elsif options[:if].is_a?(Proc)
                  true unless self.instance_exec(&options[:if])
                else
          Severity: Minor
          Found in lib/attr_validator/validator.rb and 1 other location - About 20 mins to fix
          lib/attr_validator/validator.rb on lines 115..121

          Duplicated Code

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

          Tuning

          This issue has a mass of 28.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language