yast/yast-yast2

View on GitHub
library/network/src/modules/PortRanges.rb

Summary

Maintainability
F
4 days
Test Coverage

Method FlattenServices has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

    def FlattenServices(old_list, protocol)
      old_list = deep_copy(old_list)
      if !Builtins.contains(["TCP", "UDP"], protocol)
        message = Builtins.sformat(
          "Protocol %1 doesn't support port ranges, skipping...",
Severity: Minor
Found in library/network/src/modules/PortRanges.rb - About 1 day 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 FlattenServices has 191 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def FlattenServices(old_list, protocol)
      old_list = deep_copy(old_list)
      if !Builtins.contains(["TCP", "UDP"], protocol)
        message = Builtins.sformat(
          "Protocol %1 doesn't support port ranges, skipping...",
Severity: Major
Found in library/network/src/modules/PortRanges.rb - About 7 hrs to fix

    File PortRanges.rb has 392 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "yast"
    
    module Yast
      # Tools for ranges of network ports, as used by iptables for firewalling.
      #
    Severity: Minor
    Found in library/network/src/modules/PortRanges.rb - About 5 hrs to fix

      Method IsValidPortRange has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def IsValidPortRange(port_range)
            # not a port range
            if !IsPortRange(port_range)
              warning = Builtins.sformat("Not a port-range %1", port_range)
              Builtins.y2milestone(warning) if ReportOnlyOnce(warning)
      Severity: Minor
      Found in library/network/src/modules/PortRanges.rb - About 2 hrs 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 RemovePortFromPortRanges has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def RemovePortFromPortRanges(port_number, port_ranges)
            port_ranges = deep_copy(port_ranges)
            # Checking necessarity of filtering and params
            return deep_copy(port_ranges) if port_ranges.nil? || port_ranges == []
            return deep_copy(port_ranges) if port_number.nil? || port_number == 0
      Severity: Minor
      Found in library/network/src/modules/PortRanges.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 RemovePortFromPortRanges has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def RemovePortFromPortRanges(port_number, port_ranges)
            port_ranges = deep_copy(port_ranges)
            # Checking necessarity of filtering and params
            return deep_copy(port_ranges) if port_ranges.nil? || port_ranges == []
            return deep_copy(port_ranges) if port_number.nil? || port_number == 0
      Severity: Minor
      Found in library/network/src/modules/PortRanges.rb - About 1 hr to fix

        Method IsValidPortRange has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def IsValidPortRange(port_range)
              # not a port range
              if !IsPortRange(port_range)
                warning = Builtins.sformat("Not a port-range %1", port_range)
                Builtins.y2milestone(warning) if ReportOnlyOnce(warning)
        Severity: Minor
        Found in library/network/src/modules/PortRanges.rb - About 1 hr to fix

          Method CreateNewPortRange has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def CreateNewPortRange(min_pr, max_pr)
                if min_pr.nil? || min_pr == 0
                  Builtins.y2error(
                    "Wrong definition of the starting port '%1', it must be between 1 and 65535",
                    min_pr
          Severity: Minor
          Found in library/network/src/modules/PortRanges.rb - About 1 hr to fix

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

                def PortIsInPortranges(port, port_ranges)
                  port_ranges = deep_copy(port_ranges)
                  return false if Builtins.size(port_ranges) == 0
            
                  ret = false
            Severity: Minor
            Found in library/network/src/modules/PortRanges.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 DividePortsAndPortRanges has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def DividePortsAndPortRanges(unsorted_ports, with_aliases)
                  unsorted_ports = deep_copy(unsorted_ports)
                  ret = {}
            
                  Builtins.foreach(unsorted_ports) do |port|
            Severity: Minor
            Found in library/network/src/modules/PortRanges.rb - About 1 hr to fix

              Avoid too many return statements within this method.
              Open

                      return false
              Severity: Major
              Found in library/network/src/modules/PortRanges.rb - About 30 mins to fix

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

                    def CreateNewPortRange(min_pr, max_pr)
                      if min_pr.nil? || min_pr == 0
                        Builtins.y2error(
                          "Wrong definition of the starting port '%1', it must be between 1 and 65535",
                          min_pr
                Severity: Minor
                Found in library/network/src/modules/PortRanges.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