yast/yast-yast2

View on GitHub
library/commandline/src/modules/CommandLine.rb

Summary

Maintainability
F
2 wks
Test Coverage

File CommandLine.rb has 1148 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "yast"

module Yast
  class CommandLineClass < Module
    include Yast::Logger
Severity: Major
Found in library/commandline/src/modules/CommandLine.rb - About 2 days to fix

    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
    Severity: Minor
    Found in library/commandline/src/modules/CommandLine.rb - About 2 days 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 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
    Severity: Minor
    Found in library/commandline/src/modules/CommandLine.rb - About 6 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 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
    Severity: Major
    Found in library/commandline/src/modules/CommandLine.rb - About 6 hrs to fix

      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
      Severity: Major
      Found in library/commandline/src/modules/CommandLine.rb - About 5 hrs to fix

        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")
        Severity: Minor
        Found in library/commandline/src/modules/CommandLine.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 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"])
        Severity: Major
        Found in library/commandline/src/modules/CommandLine.rb - About 5 hrs to fix

          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")
          Severity: Minor
          Found in library/commandline/src/modules/CommandLine.rb - About 4 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 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
          Severity: Major
          Found in library/commandline/src/modules/CommandLine.rb - About 4 hrs to fix

            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")
            Severity: Major
            Found in library/commandline/src/modules/CommandLine.rb - About 4 hrs to fix

              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"])
              Severity: Minor
              Found in library/commandline/src/modules/CommandLine.rb - About 4 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 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
              Severity: Minor
              Found in library/commandline/src/modules/CommandLine.rb - About 3 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 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")
              Severity: Major
              Found in library/commandline/src/modules/CommandLine.rb - About 3 hrs to fix

                Class CommandLineClass has 29 methods (exceeds 20 allowed). Consider refactoring.
                Open

                  class CommandLineClass < Module
                    include Yast::Logger
                
                    def main
                      Yast.import "Directory"
                Severity: Minor
                Found in library/commandline/src/modules/CommandLine.rb - About 3 hrs to fix

                  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"
                  Severity: Major
                  Found in library/commandline/src/modules/CommandLine.rb - About 3 hrs to fix

                    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 = []
                    Severity: Major
                    Found in library/commandline/src/modules/CommandLine.rb - About 2 hrs to fix

                      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 = []
                      Severity: Minor
                      Found in library/commandline/src/modules/CommandLine.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 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
                      Severity: Minor
                      Found in library/commandline/src/modules/CommandLine.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 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
                      Severity: Minor
                      Found in library/commandline/src/modules/CommandLine.rb - About 1 hr to fix

                        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?
                        Severity: Minor
                        Found in library/commandline/src/modules/CommandLine.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 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?
                        Severity: Minor
                        Found in library/commandline/src/modules/CommandLine.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

                        Avoid deeply nested control flow statements.
                        Open

                                        @aborted = true if !@interactive
                        Severity: Major
                        Found in library/commandline/src/modules/CommandLine.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                          @aborted = true if !@interactive
                          Severity: Major
                          Found in library/commandline/src/modules/CommandLine.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                            @aborted = true if !@interactive
                            Severity: Major
                            Found in library/commandline/src/modules/CommandLine.rb - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                              @aborted = true if !@interactive
                              Severity: Major
                              Found in library/commandline/src/modules/CommandLine.rb - About 45 mins to fix

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

                                          return true
                                  Severity: Major
                                  Found in library/commandline/src/modules/CommandLine.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return {}
                                    Severity: Major
                                    Found in library/commandline/src/modules/CommandLine.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

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

                                        Avoid too many return statements within this method.
                                        Open

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

                                          Avoid too many return statements within this method.
                                          Open

                                                  return true
                                          Severity: Major
                                          Found in library/commandline/src/modules/CommandLine.rb - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

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

                                              Avoid too many return statements within this method.
                                              Open

                                                      return true
                                              Severity: Major
                                              Found in library/commandline/src/modules/CommandLine.rb - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

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

                                                  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, "]")
                                                  Severity: Minor
                                                  Found in library/commandline/src/modules/CommandLine.rb and 1 other location - About 15 mins to fix
                                                  library/commandline/src/modules/CommandLine.rb on lines 642..646

                                                  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

                                                  Further Reading

                                                  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, "]")
                                                  Severity: Minor
                                                  Found in library/commandline/src/modules/CommandLine.rb and 1 other location - About 15 mins to fix
                                                  library/commandline/src/modules/CommandLine.rb on lines 623..627

                                                  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

                                                  Further Reading

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status