FreedomBen/dory

View on GitHub
lib/dory/dnsmasq.rb

Summary

Maintainability
C
7 hrs
Test Coverage

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

  class Dnsmasq
    extend Dory::DockerService

    #
    # I really hate these globals.  It would be great to refactor these out
Severity: Minor
Found in lib/dory/dnsmasq.rb - About 3 hrs to fix

    Cyclomatic complexity for run_preconditions is too high. [7/6]
    Open

        def self.run_preconditions
          puts "[DEBUG] dnsmasq service running preconditions" if Dory::Config.debug?
    
          # we don't want to hassle the user with checking the port unless necessary
          if first_attempt_failed?
    Severity: Minor
    Found in lib/dory/dnsmasq.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

        def self.run_preconditions
          puts "[DEBUG] dnsmasq service running preconditions" if Dory::Config.debug?
    
          # we don't want to hassle the user with checking the port unless necessary
          if first_attempt_failed?
    Severity: Minor
    Found in lib/dory/dnsmasq.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 down_systemd_services has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.down_systemd_services
          puts "[DEBUG] Putting systemd services down" if Dory::Config.debug?
    
          conf = if ask_about_killing?
                   puts "You have some systemd services running that will race against us \n" \
    Severity: Minor
    Found in lib/dory/dnsmasq.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 handle_error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.handle_error(_command_output)
          puts "[DEBUG] handling dnsmasq start error" if Dory::Config.debug?
          # If we've already tried to handle failure, prevent infinite recursion
          if first_attempt_failed?
            puts "[DEBUG] Attempt to kill conflicting service failed" if Dory::Config.debug?
    Severity: Minor
    Found in lib/dory/dnsmasq.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 up_systemd_services has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.up_systemd_services
          if self.systemd_services?
            puts "[DEBUG] Putting systemd services back up: #{self.systemd_services.join(', ')}" if Dory::Config.debug?
            if self.systemd_services.reverse.all? { |service|
              Dory::Systemd.set_systemd_service(service: service, up: true)
    Severity: Minor
    Found in lib/dory/dnsmasq.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 offer_to_kill has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.offer_to_kill(listener_list, answer: nil)
          listener_list.each do |process|
            puts "Process '#{process.command}' with PID '#{process.pid}' is listening on #{process.node} port #{self.port}.".yellow
          end
          pids = listener_list.uniq(&:pid).map(&:pid)
    Severity: Minor
    Found in lib/dory/dnsmasq.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