yast/yast-yast2

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

Summary

Maintainability
F
1 wk
Test Coverage

File NetworkInterfaces.rb has 996 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "yast"
require "shellwords"

module Yast
  # Reads and writes the ifcfg files (/etc/sysconfig/network/ifcfg-*).
Severity: Major
Found in library/network/src/modules/NetworkInterfaces.rb - About 2 days to fix

    Class NetworkInterfacesClass has 58 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class NetworkInterfacesClass < Module
        attr_reader :Devices
    
        include Logger
    
    
    Severity: Major
    Found in library/network/src/modules/NetworkInterfaces.rb - About 1 day to fix

      Method Write has 145 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def Write(devregex)
            log.info("Writing configuration")
            log.debug("Devices=#{@Devices}")
            log.debug("Deleted=#{@Deleted}")
      
      
      Severity: Major
      Found in library/network/src/modules/NetworkInterfaces.rb - About 5 hrs to fix

        Method Write has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
        Open

            def Write(devregex)
              log.info("Writing configuration")
              log.debug("Devices=#{@Devices}")
              log.debug("Deleted=#{@Deleted}")
        
        
        Severity: Minor
        Found in library/network/src/modules/NetworkInterfaces.rb - About 5 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 GetDevTypeDescription has 88 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def GetDevTypeDescription(type, longdescr)
              if Builtins.issubstring(type, "#")
                # Device type label
                # This is what used to be Virtual Interface (eth0:1).
                # In our data model, additional addresses for an interface
        Severity: Major
        Found in library/network/src/modules/NetworkInterfaces.rb - About 3 hrs to fix

          Method main has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def main
                textdomain "base"
          
                Yast.import "Arch"
                Yast.import "Map"
          Severity: Major
          Found in library/network/src/modules/NetworkInterfaces.rb - About 3 hrs to fix

            Method adapt_old_config! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def adapt_old_config!
                  @Devices.each do |devtype, devices|
                    devices.each do |device, config|
                      bootproto = config["BOOTPROTO"] || "static"
                      next unless bootproto == "static" && config["IPADDR"] == "0.0.0.0"
            Severity: Minor
            Found in library/network/src/modules/NetworkInterfaces.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 generate_config has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def generate_config(pth, values)
                  config = {}
                  values.each do |val|
                    item = SCR.Read(path("#{pth}.#{val}"))
                    log.debug("item=#{item}")
            Severity: Minor
            Found in library/network/src/modules/NetworkInterfaces.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 List has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def List(devregex)
                  ret = []
                  if devregex == "" || devregex.nil?
                    Builtins.maplist(@Devices) do |_t, d|
                      Builtins.maplist(
            Severity: Minor
            Found in library/network/src/modules/NetworkInterfaces.rb - About 1 hr to fix

              Method Import has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def Import(devregex, devices)
                    devices = deep_copy(devices)
                    devs = FilterNOT(@Devices, devregex)
                    Builtins.y2debug("Devs=%1", devs)
              
              
              Severity: Minor
              Found in library/network/src/modules/NetworkInterfaces.rb - About 1 hr to fix

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

                    def GetTypeFromSysfs(dev)
                      sys_dir_path = Builtins.sformat("/sys/class/net/%1", dev)
                      sys_type_path = Builtins.sformat("%1/type", sys_dir_path)
                
                      return nil if IsEmpty(dev) || !FileUtils.Exists(sys_type_path)
                Severity: Minor
                Found in library/network/src/modules/NetworkInterfaces.rb - About 1 hr to fix

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

                      def GetEthTypeFromSysfs(dev)
                        sys_dir_path = "/sys/class/net/#{dev}"
                  
                        if FileUtils.Exists("#{sys_dir_path}/wireless") ||
                            FileUtils.Exists("#{sys_dir_path}/phy80211")
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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 GetDevTypeDescription has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def GetDevTypeDescription(type, longdescr)
                        if Builtins.issubstring(type, "#")
                          # Device type label
                          # This is what used to be Virtual Interface (eth0:1).
                          # In our data model, additional addresses for an interface
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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 List has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def List(devregex)
                        ret = []
                        if devregex == "" || devregex.nil?
                          Builtins.maplist(@Devices) do |_t, d|
                            Builtins.maplist(
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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 GetTypeFromIfcfg has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def GetTypeFromIfcfg(ifcfg)
                        ifcfg = deep_copy(ifcfg)
                        type = nil
                  
                        return nil if IsEmpty(ifcfg)
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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 Change2 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def Change2(name, newdev, check)
                        newdev = deep_copy(newdev)
                        Builtins.y2debug("Change(%1,%2,%3)", name, newdev, check)
                        Builtins.y2debug("Devices=%1", @Devices)
                        if Check(name) && check
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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 CanonicalizeIP has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def CanonicalizeIP(ifcfg)
                        ifcfg = deep_copy(ifcfg)
                        return nil if ifcfg.nil?
                  
                        ipaddr, prefixlen = ifcfg["IPADDR"].to_s.split("/")
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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

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

                      def GetTypeFromSysfs(dev)
                        sys_dir_path = Builtins.sformat("/sys/class/net/%1", dev)
                        sys_type_path = Builtins.sformat("%1/type", sys_dir_path)
                  
                        return nil if IsEmpty(dev) || !FileUtils.Exists(sys_type_path)
                  Severity: Minor
                  Found in library/network/src/modules/NetworkInterfaces.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

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

                              if Ops.greater_than(
                                Builtins.size(Ops.get_string(devmap, "IPADDR", "")),
                                0
                              ) &&
                                  Ops.greater_than(
                  Severity: Major
                  Found in library/network/src/modules/NetworkInterfaces.rb and 1 other location - About 2 hrs to fix
                  library/network/src/modules/NetworkInterfaces.rb on lines 884..919

                  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 92.

                  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

                                  if Ops.greater_than(Builtins.size(Ops.get(amap, "IPADDR", "")), 0) &&
                                      Ops.greater_than(
                                        Builtins.size(Ops.get(amap, "NETMASK", "")),
                                        0
                                      )
                  Severity: Major
                  Found in library/network/src/modules/NetworkInterfaces.rb and 1 other location - About 2 hrs to fix
                  library/network/src/modules/NetworkInterfaces.rb on lines 828..866

                  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 92.

                  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