theforeman/smart-proxy

View on GitHub

Showing 52 of 56 total issues

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

    def log_halt code=nil, exception=nil
      message = exception.is_a?(String) ? exception : exception.to_s
      begin
        if block_given?
          return yield
Severity: Minor
Found in lib/helpers.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 loadSubnetData has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def loadSubnetData subnet
      super
      conf = format((@config+@leases).split("\n"))
      # scan for host statements
      conf.scan(/host\s+(\S+\s*\{[^}]+\})/) do |host|
Severity: Minor
Found in lib/proxy/dhcp/server/isc.rb - About 1 hr to fix

    Method parse_record_options has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def parse_record_options text
          options = {}
          case text
            # standard record values
          when /^hardware\s+ethernet\s+(\S+)/
    Severity: Minor
    Found in lib/proxy/dhcp/server/isc.rb - About 1 hr to fix

      Method run! has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.run!(options={})
            set options
            handler      = detect_rack_handler
            handler_name = handler.name.gsub(/.*::/, '')
      
      
      Severity: Minor
      Found in lib/sinatra-patch.rb - About 1 hr to fix

        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 find_puppetca has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def find_puppetca
              ssl_dir = Pathname.new ssldir
              unless (ssl_dir + "ca").directory?
                logger.warn "PuppetCA: SSL/CA unavailable on this machine: ssldir not found at #{ssl_dir}"
                raise "SSL/CA unavailable on this machine"
        Severity: Minor
        Found in lib/proxy/puppetca.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 addRecord has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def addRecord options={}
              record = super(options)
        
              cmd = "scope #{record.subnet.network} add reservedip #{record.ip} #{record.mac.gsub(/:/,"")} #{record.name}"
              execute(cmd, "Added DHCP reservation for #{record}")
        Severity: Minor
        Found in lib/proxy/dhcp/server/native_ms.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 daemon has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.daemon(nochdir = nil, noclose = nil)
                  exit if fork                     # Parent exits, child continues.
                  Process.setsid                   # Become session leader.
                  exit if fork                     # Zap session leader. See [1].
            
            
            Severity: Minor
            Found in lib/daemon.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 bmc_setup has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def bmc_setup
            
                raise "Smart Proxy is not configured to support BMC control" unless SETTINGS.bmc
            
                # Either use the default provider or allow user to specify provider in request
            Severity: Minor
            Found in lib/bmc_api.rb - About 1 hr to fix

              Method execute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def execute cmd, msg=nil, error_only=false
                    tsecs = 5
                    response = nil
                    interpreter = SETTINGS.x86_64 ? 'c:\windows\sysnative\cmd.exe' : 'c:\windows\system32\cmd.exe'
                    command  = interpreter + ' /c c:\Windows\System32\netsh.exe -c dhcp ' + "server #{name} #{cmd}"
              Severity: Minor
              Found in lib/proxy/dhcp/server/native_ms.rb - About 55 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 read_config has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def read_config file
                    logger.debug "Reading config file #{file}"
                    config = []
                    File.readlines(file).each do |line|
                      if /^include\s+"(.*)"\s*;/ =~ line.strip
              Severity: Minor
              Found in lib/proxy/dhcp/server/isc.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 nsupdate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def nsupdate cmd
                    status = nil
                    if cmd == "connect"
                      find_nsupdate if @nsupdate.nil?
                      nsupdate_cmd = "#{@nsupdate} #{nsupdate_args}"
              Severity: Minor
              Found in lib/proxy/dns/nsupdate.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 find_subnet has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def find_subnet value
                    subnets.each do |s|
                      return s if value.is_a?(String) and s.network == value
                      return s if value.is_a?(Proxy::DHCP::Record) and s.include?(value.ip)
                      return s if value.is_a?(IPAddr) and s.include?(value)
              Severity: Minor
              Found in lib/proxy/dhcp/server.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 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

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

                    def load
                      Puppet.clear
                      if Puppet::PUPPETVERSION.to_i >= 3
                        # Used on Puppet 3.0, private method that clears the "initialized or
                        # not" state too, so a full config reload takes place and we pick up
              Severity: Minor
              Found in lib/proxy/puppet/initializer.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 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def initialize(cmd)
                    # clean finished tasks from the array
                    @@tasks = @@tasks.collect { |t| nil unless t.is_a? String }.compact
              
                    # run the task in its own thread
              Severity: Minor
              Found in lib/proxy/util.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 loadSubnets has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def loadSubnets
                    super
                    cmd = "show scope"
                    msg = "Enumerated the scopes on #{@name}"
              
              
              Severity: Minor
              Found in lib/proxy/dhcp/server/native_ms.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 addRecord has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def addRecord options = {}
                    ip = validate_ip options[:ip]
                    mac = validate_mac options[:mac]
                    name = options[:hostname] || raise(Proxy::DHCP::Error, "Must provide hostname")
                    net = options.delete("network")
              Severity: Minor
              Found in lib/proxy/dhcp/server.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

              Severity
              Category
              Status
              Source
              Language