rapid7/metasploit-model

View on GitHub

Showing 12 of 12 total issues

Method validate_each has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    if value.is_a? Array
      value.each_with_index do |element, index|
        if element.is_a? Array
          if element.length != 2
Severity: Minor
Found in app/validators/parameters_validator.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 validate_each has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    if value.is_a? Array
      value.each_with_index do |element, index|
        if element.is_a? Array
          if element.length != 2
Severity: Major
Found in app/validators/parameters_validator.rb - About 2 hrs to fix

    Method visitor has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def visitor(klass)
          visitor = visitor_by_module[klass]
    
          unless visitor
            klass.ancestors.each do |mod|
    Severity: Minor
    Found in lib/metasploit/model/visitation/visit.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 children has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def children(formatted_value)
        if formatted_value.include? '-'
          head, tail = formatted_value.split('-', 2)
    
          if head.casecmp('URL') == 0
    Severity: Minor
    Found in app/models/metasploit/model/search/operator/deprecated/ref.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_each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_each(object, attribute, value)
        error_message_block = lambda{ object.errors.add attribute, "must be a valid (IP or hostname) address" }
        begin
          # Checks for valid IP addresses
          if value.is_a? IPAddr
    Severity: Minor
    Found in app/validators/address_format_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 children has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def children(formatted_value)
        if formatted_value.include? '-'
          head, tail = formatted_value.split('-', 2)
    
          if head.casecmp('URL') == 0
    Severity: Minor
    Found in app/models/metasploit/model/search/operator/deprecated/ref.rb - About 1 hr to fix

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

        def mutate_pass(password)
          mutations = {
              'a' => '@',
              'o' => '0',
              'e' => '3',
      Severity: Minor
      Found in app/validators/password_is_strong_validator.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

                    unless parameter_name.present?
                      error = error_at(
                          :element => element,
                          :index => index,
                          :prefix => "has blank parameter name"
      Severity: Major
      Found in app/validators/parameters_validator.rb - About 45 mins to fix

        Method merge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.merge(first_expanded, second_expanded)
            if first_expanded.nil? && second_expanded.nil?
              nil
            elsif !first_expanded.nil? && second_expanded.nil?
              first_expanded
        Severity: Minor
        Found in lib/metasploit/model/association/tree.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

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

          def validate_each(object, attribute, value)
            error_message_block = lambda{ object.errors.add attribute, "must be a valid IPv4 or IPv6 address" }
            begin
              if value.is_a? IPAddr
                potential_ip = value.dup
        Severity: Minor
        Found in app/validators/ip_format_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 constant_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.constant_name(type)
            case type
              when Hash
                if type.length < 1
                  raise ArgumentError, "Cannot destructure a Hash without entries"
        Severity: Minor
        Found in app/models/metasploit/model/search/operator/single.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_each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def validate_each(record, attribute, value)
            return if value.blank?
        
            if is_simple?(value)
              record.errors.add attribute, 'must contain letters, numbers, and at least one special character'
        Severity: Minor
        Found in app/validators/password_is_strong_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