File CommandLine.rb
has 1148 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "yast"
module Yast
class CommandLineClass < Module
include Yast::Logger
Method Parse
has a Cognitive Complexity of 101 (exceeds 5 allowed). Consider refactoring. Open
def Parse(arguments)
args = deep_copy(arguments)
return {} if Ops.less_than(Builtins.size(args), 1)
# Parse command
- 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 Init
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
def Init(cmdlineinfo, args)
cmdlineinfo = deep_copy(cmdlineinfo)
args = deep_copy(args)
# remember the command line specification
# required later by xmlhelp command
- 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 Parse
has 166 lines of code (exceeds 25 allowed). Consider refactoring. Open
def Parse(arguments)
args = deep_copy(arguments)
return {} if Ops.less_than(Builtins.size(args), 1)
# Parse command
Method Init
has 146 lines of code (exceeds 25 allowed). Consider refactoring. Open
def Init(cmdlineinfo, args)
cmdlineinfo = deep_copy(cmdlineinfo)
args = deep_copy(args)
# remember the command line specification
# required later by xmlhelp command
Method Run
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def Run(commandline)
commandline = deep_copy(commandline)
# The main ()
Builtins.y2milestone("----------------------------------------")
Builtins.y2milestone("Command line interface started")
- 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 ProcessSystemCommands
has 131 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ProcessSystemCommands(command)
command = deep_copy(command)
# handle help for specific command
# this needs to be before general help, so "help help" works
if Ops.get(command, ["options", "help"])
Method PrintActionHelp
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def PrintActionHelp(action)
# lookup action in actions
command = Ops.get_map(@allcommands, ["actions", action], {})
# translators: the command does not provide any help
commandhelp = Ops.get(command, "help")
- 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 PrintGeneralHelp
has 118 lines of code (exceeds 25 allowed). Consider refactoring. Open
def PrintGeneralHelp
# display custom defined help instead of generic one
if Builtins.haskey(@modulecommands, "customhelp")
Print(Ops.get_string(@modulecommands, "customhelp", ""))
return
Method PrintActionHelp
has 116 lines of code (exceeds 25 allowed). Consider refactoring. Open
def PrintActionHelp(action)
# lookup action in actions
command = Ops.get_map(@allcommands, ["actions", action], {})
# translators: the command does not provide any help
commandhelp = Ops.get(command, "help")
Method ProcessSystemCommands
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def ProcessSystemCommands(command)
command = deep_copy(command)
# handle help for specific command
# this needs to be before general help, so "help help" works
if Ops.get(command, ["options", "help"])
- 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 Command
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def Command
# if we are done already, return the result
return { "command" => @aborted ? "abort" : "exit" } if @done
# there is a command in the cache
- 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 Run
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
def Run(commandline)
commandline = deep_copy(commandline)
# The main ()
Builtins.y2milestone("----------------------------------------")
Builtins.y2milestone("Command line interface started")
Class CommandLineClass
has 29 methods (exceeds 20 allowed). Consider refactoring. Open
class CommandLineClass < Module
include Yast::Logger
def main
Yast.import "Directory"
Method main
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
def main
Yast.import "Directory"
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Report"
Method PrintTable
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
def PrintTable(header, content)
header = deep_copy(header)
content = deep_copy(content)
aligns = []
widths = []
Method PrintTable
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def PrintTable(header, content)
header = deep_copy(header)
content = deep_copy(content)
aligns = []
widths = []
- 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 PrintGeneralHelp
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def PrintGeneralHelp
# display custom defined help instead of generic one
if Builtins.haskey(@modulecommands, "customhelp")
Print(Ops.get_string(@modulecommands, "customhelp", ""))
return
- 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 Command
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def Command
# if we are done already, return the result
return { "command" => @aborted ? "abort" : "exit" } if @done
# there is a command in the cache
Method UniqueOption
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def UniqueOption(options, unique_options)
return nil if options.nil? || unique_options.nil?
# sanity check
if unique_options.empty?
- 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
Avoid deeply nested control flow statements. Open
@aborted = true if !@interactive
Method PrintInternal
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def PrintInternal(string, newline)
return if !Mode.commandline
# avoid using of uninitialized value in .dev.tty perl agent
if string.nil?
- 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
Avoid deeply nested control flow statements. Open
@aborted = true if !@interactive
Avoid deeply nested control flow statements. Open
@aborted = true if !@interactive
Avoid deeply nested control flow statements. Open
@aborted = true if !@interactive
Avoid too many return
statements within this method. Open
return true
Avoid too many return
statements within this method. Open
return true
Avoid too many return
statements within this method. Open
return true
Avoid too many return
statements within this method. Open
return false
Avoid too many return
statements within this method. Open
return false
Avoid too many return
statements within this method. Open
return {}
Avoid too many return
statements within this method. Open
return false
Avoid too many return
statements within this method. Open
return false
Avoid too many return
statements within this method. Open
return false
Identical blocks of code found in 2 locations. Consider refactoring. Open
t = "[ "
Builtins.foreach(Ops.get_list(op, "typespec", [])) do |s|
t = Ops.add(Ops.add(t, s), " ")
end
t = Ops.add(t, "]")
- 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 25.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
t = "[ "
Builtins.foreach(Ops.get_list(op, "typespec", [])) do |s|
t = Ops.add(Ops.add(t, s), " ")
end
t = Ops.add(t, "]")
- 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 25.
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