yast/yast-yast2

View on GitHub
library/network/src/lib/network/susefirewall.rb

Summary

Maintainability
F
5 days
Test Coverage

File susefirewall.rb has 629 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "yast"

module Yast
  # Factory for construction of appropriate firewall object based on
  # desired backend.
Severity: Major
Found in library/network/src/lib/network/susefirewall.rb - About 1 day to fix

    Class SuSEFirewallClass has 36 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class SuSEFirewallClass < Module
        # @return [String] the systemd service name: "firewalld" or "SuSEfirewall2"
        attr_reader :firewall_service
    
        Yast.import "Mode"
    Severity: Minor
    Found in library/network/src/lib/network/susefirewall.rb - About 4 hrs to fix

      Method RemoveAllowedPortsOrServices has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def RemoveAllowedPortsOrServices(remove_ports, protocol, zone, check_for_aliases)
            remove_ports = deep_copy(remove_ports)
            if Ops.less_than(Builtins.size(remove_ports), 1)
              Builtins.y2warning(
                "Undefined list of %1 services/ports for service",
      Severity: Major
      Found in library/network/src/lib/network/susefirewall.rb - About 3 hrs to fix

        Method RemoveAllowedPortsOrServices has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            def RemoveAllowedPortsOrServices(remove_ports, protocol, zone, check_for_aliases)
              remove_ports = deep_copy(remove_ports)
              if Ops.less_than(Builtins.size(remove_ports), 1)
                Builtins.y2warning(
                  "Undefined list of %1 services/ports for service",
        Severity: Minor
        Found in library/network/src/lib/network/susefirewall.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 GetAllKnownInterfaces has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def GetAllKnownInterfaces
              known_interfaces = []
        
              # All dial-up interfaces
              dialup_interfaces = NetworkInterfaces.List("dialup")
        Severity: Major
        Found in library/network/src/lib/network/susefirewall.rb - About 2 hrs to fix

          Method RemoveService has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def RemoveService(service, protocol, interface)
                Builtins.y2milestone(
                  "Removing service %1, protocol %2 from %3",
                  service,
                  protocol,
          Severity: Minor
          Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

            Method AddService has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def AddService(service, protocol, interface)
                  Builtins.y2milestone(
                    "Adding service %1, protocol %2 to %3",
                    service,
                    protocol,
            Severity: Minor
            Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

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

                  def GetAllKnownInterfaces
                    known_interfaces = []
              
                    # All dial-up interfaces
                    dialup_interfaces = NetworkInterfaces.List("dialup")
              Severity: Minor
              Found in library/network/src/lib/network/susefirewall.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 SetAdditionalServices has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def SetAdditionalServices(protocol, zone, new_list_services)
                    new_list_services = deep_copy(new_list_services)
                    old_list_services = Builtins.toset(GetAdditionalServices(protocol, zone))
                    new_list_services = Builtins.toset(new_list_services)
              
              
              Severity: Minor
              Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

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

                    def ArePortsOrServicesAllowed(needed_ports, protocol, zone, check_for_aliases)
                      needed_ports = deep_copy(needed_ports)
                      are_allowed = true
                
                      if Ops.less_than(Builtins.size(needed_ports), 1)
                Severity: Minor
                Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

                  Method IsOtherFirewallRunning has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def IsOtherFirewallRunning
                        any_firewall_running = true
                  
                        # grep must return at least blank lines, else it returns 'exit 1' instead of 'exit 0'
                        command = "LANG=C /usr/sbin/iptables -L -n | /usr/bin/grep -v \"^\\(Chain\\|target\\)\""
                  Severity: Minor
                  Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

                    Method SetAdditionalServices has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def SetAdditionalServices(protocol, zone, new_list_services)
                          new_list_services = deep_copy(new_list_services)
                          old_list_services = Builtins.toset(GetAdditionalServices(protocol, zone))
                          new_list_services = Builtins.toset(new_list_services)
                    
                    
                    Severity: Minor
                    Found in library/network/src/lib/network/susefirewall.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 AddService has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def AddService(service, protocol, interface)
                          Builtins.y2milestone(
                            "Adding service %1, protocol %2 to %3",
                            service,
                            protocol,
                    Severity: Minor
                    Found in library/network/src/lib/network/susefirewall.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 RemoveService has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def RemoveService(service, protocol, interface)
                          Builtins.y2milestone(
                            "Removing service %1, protocol %2 from %3",
                            service,
                            protocol,
                    Severity: Minor
                    Found in library/network/src/lib/network/susefirewall.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 HaveService has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def HaveService(service, protocol, interface)
                          if !IsSupportedProtocol(protocol)
                            Builtins.y2error("Unknown protocol: %1", protocol)
                            return nil
                          end
                    Severity: Minor
                    Found in library/network/src/lib/network/susefirewall.rb - About 1 hr to fix

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

                          def HaveService(service, protocol, interface)
                            if !IsSupportedProtocol(protocol)
                              Builtins.y2error("Unknown protocol: %1", protocol)
                              return nil
                            end
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.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 ArePortsOrServicesAllowed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def ArePortsOrServicesAllowed(needed_ports, protocol, zone, check_for_aliases)
                            needed_ports = deep_copy(needed_ports)
                            are_allowed = true
                      
                            if Ops.less_than(Builtins.size(needed_ports), 1)
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.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

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                            if interface == "all"
                              zones_affected = GetKnownFirewallZones()
                      
                              # zone or interface name
                            else
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 35 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 1013..1039

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 35.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                            if interface == "all"
                              zones_affected = GetKnownFirewallZones()
                      
                              # zone or interface name
                            else
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 35 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 936..963

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 35.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def SetEnableService(enable_service)
                            if !SuSEFirewallIsSelectedOrInstalled()
                              Builtins.y2warning("Cannot set SetEnableService")
                              return nil
                            end
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 25 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 63..83

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 31.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def SetStartService(start_service)
                            if !SuSEFirewallIsSelectedOrInstalled()
                              Builtins.y2warning("Cannot set SetStartService")
                              return nil
                            end
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 25 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 100..120

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 31.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                            Builtins.foreach(needed_ports) do |needed_port|
                              if !Builtins.contains(Ops.get(allowed_ports, "ports", []), needed_port) &&
                                  !PortRanges.PortIsInPortranges(
                                    needed_port,
                                    Ops.get(allowed_ports, "port_ranges", [])
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 25 mins to fix
                      library/network/src/lib/network/susefirewall2.rb on lines 594..606

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 30.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def StopServices
                            return true if Mode.testsuite
                      
                            return false if !SuSEFirewallIsInstalled()
                      
                      
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 20 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 126..136

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 27.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def StartServices
                            return true if Mode.testsuite
                      
                            return false if !SuSEFirewallIsInstalled()
                      
                      
                      Severity: Minor
                      Found in library/network/src/lib/network/susefirewall.rb and 1 other location - About 20 mins to fix
                      library/network/src/lib/network/susefirewall.rb on lines 143..153

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 27.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status