rapid7/nexpose-client

View on GitHub
lib/nexpose/alert.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.create(hash)
      alert_type = hash[:alert_type]
      raise 'An alert must have an alert type' if alert_type.nil?
      raise 'Alert name cannot be empty.' if !hash.key?(:name) || hash[:name].to_s == ''
      raise 'SNMP and Syslog alerts must have a server defined' if ['SNMP', 'Syslog'].include?(alert_type) && hash[:server].to_s == ''
Severity: Minor
Found in lib/nexpose/alert.rb - About 1 hr to fix

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

        def self.json_initializer(filter)
          new(filter[:start] ? 1 : 0,
              filter[:stop] ? 1 : 0,
              filter[:failed] ? 1 : 0,
              filter[:resume] ? 1 : 0,
    Severity: Minor
    Found in lib/nexpose/alert.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 initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1, verbose = 0)
    Severity: Major
    Found in lib/nexpose/alert.rb - About 50 mins to fix

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

          def self.json_initializer(filter)
            new(filter[:severity] ? 1 : 0,
                filter[:unconfirmed] ? 1 : 0,
                filter[:confirmed] ? 1 : 0,
                filter[:potential] ? 1 : 0)
      Severity: Minor
      Found in lib/nexpose/alert.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1, verbose = 0)
            unless recipients.is_a?(Array) && !recipients.empty?
              raise 'An SMTP alert must contain an array of recipient emails with at least 1 recipient'
            end
      
      
      Severity: Minor
      Found in lib/nexpose/alert.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def initialize(name, community, server, enabled = 1, max_alerts = -1)
      Severity: Minor
      Found in lib/nexpose/alert.rb - About 35 mins to fix

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def initialize(start = 0, stop = 0, fail = 0, resume = 0, pause = 0)
        Severity: Minor
        Found in lib/nexpose/alert.rb - About 35 mins to fix

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

              def validate
                raise ArgumentError.new('Name is a required attribute.') unless @name
                raise ArgumentError.new('Scan filter is a required attribute.') unless @scan_filter
                raise ArgumentError.new('Vuln filter is a required attribute.') unless @vuln_filter
              end
          Severity: Minor
          Found in lib/nexpose/alert.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.create(hash)
                alert_type = hash[:alert_type]
                raise 'An alert must have an alert type' if alert_type.nil?
                raise 'Alert name cannot be empty.' if !hash.key?(:name) || hash[:name].to_s == ''
                raise 'SNMP and Syslog alerts must have a server defined' if ['SNMP', 'Syslog'].include?(alert_type) && hash[:server].to_s == ''
          Severity: Minor
          Found in lib/nexpose/alert.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

          There are no issues that match your filters.

          Category
          Status