ManageIQ/linux_admin

View on GitHub
lib/linux_admin/network_interface/network_interface_rh.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
100%

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

    def save
      old_contents = @interface_file.file? ? File.read(@interface_file) : ""

      stop_success = stop
      # Stop twice because when configure both ipv4 and ipv6 as dhcp, ipv6 dhcp client will
Severity: Minor
Found in lib/linux_admin/network_interface/network_interface_rh.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 apply_static has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def apply_static(ip, mask, gw, dns, search = nil)
Severity: Minor
Found in lib/linux_admin/network_interface/network_interface_rh.rb - About 35 mins to fix

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

        def apply_static6(ip, prefix, gw, dns, search = nil)
    Severity: Minor
    Found in lib/linux_admin/network_interface/network_interface_rh.rb - About 35 mins to fix

      Use match? instead of =~ when MatchData is not used.
      Open

                next if line =~ /^\s*#/

      In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

      Example:

      # bad
      def foo
        if x =~ /re/
          do_something
        end
      end
      
      # bad
      def foo
        if x.match(/re/)
          do_something
        end
      end
      
      # bad
      def foo
        if /re/ === x
          do_something
        end
      end
      
      # good
      def foo
        if x.match?(/re/)
          do_something
        end
      end
      
      # good
      def foo
        if x =~ /re/
          do_something(Regexp.last_match)
        end
      end
      
      # good
      def foo
        if x.match(/re/)
          do_something($~)
        end
      end
      
      # good
      def foo
        if /re/ === x
          do_something($~)
        end
      end

      There are no issues that match your filters.

      Category
      Status