theforeman/smart-proxy

View on GitHub
lib/proxy/dhcp/subnet.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Subnet has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Subnet
    attr_reader :network, :netmask, :server, :timestamp
    attr_accessor :options

    include Proxy::DHCP
Severity: Minor
Found in lib/proxy/dhcp/subnet.rb - About 3 hrs to fix

    Method tcp_pingable? has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def tcp_pingable? ip
          # This code is from net-ping, and stripped down for use here
          # We don't need all the ldap dependencies net-ping brings in
    
          @service_check = true
    Severity: Minor
    Found in lib/proxy/dhcp/subnet.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 unused_ip has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def unused_ip args = {}
          # first check if we already have a record for this host
          # if we do, we can simply reuse the same ip address.
          if args[:mac] and r=has_mac?(args[:mac])
            logger.debug "Found an existing dhcp record #{r}, reusing..."
    Severity: Minor
    Found in lib/proxy/dhcp/subnet.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 unused_ip has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def unused_ip args = {}
          # first check if we already have a record for this host
          # if we do, we can simply reuse the same ip address.
          if args[:mac] and r=has_mac?(args[:mac])
            logger.debug "Found an existing dhcp record #{r}, reusing..."
    Severity: Minor
    Found in lib/proxy/dhcp/subnet.rb - About 1 hr to fix

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

          def tcp_pingable? ip
            # This code is from net-ping, and stripped down for use here
            # We don't need all the ldap dependencies net-ping brings in
      
            @service_check = true
      Severity: Minor
      Found in lib/proxy/dhcp/subnet.rb - About 1 hr to fix

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

            def valid_range args = {}
              logger.debug "trying to find an ip address, we got #{args.inspect}"
              if args[:from] and (from=validate_ip(args[:from])) and args[:to] and (to=validate_ip(args[:to]))
                raise Proxy::DHCP::Error, "Range does not belong to provided subnet" unless self.include?(from) and self.include?(to)
                from = IPAddr.new(from)
        Severity: Minor
        Found in lib/proxy/dhcp/subnet.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

        There are no issues that match your filters.

        Category
        Status