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-*).
Class NetworkInterfacesClass
has 58 methods (exceeds 20 allowed). Consider refactoring. Open
class NetworkInterfacesClass < Module
attr_reader :Devices
include Logger
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}")
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}")
- Read upRead up
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
Method main
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
def main
textdomain "base"
Yast.import "Arch"
Yast.import "Map"
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"
- Read upRead up
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}")
- Read upRead up
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(
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)
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)
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")
- Read upRead up
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
- Read upRead up
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(
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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("/")
- Read upRead up
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)
- Read upRead up
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(
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76