yast/yast-yast2

View on GitHub
library/gpg/src/modules/GPG.rb

Summary

Maintainability
C
1 day
Test Coverage

File GPG.rb has 259 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "yast"
require "shellwords"

module Yast
  class GPGClass < Module
Severity: Minor
Found in library/gpg/src/modules/GPG.rb - About 2 hrs to fix

    Method SignFile has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def SignFile(keyid, file, passphrase, ascii_signature)
          if passphrase.nil? || keyid.nil? || keyid == "" || file.nil? ||
              file == ""
            Builtins.y2error(
              "Invalid parameters: keyid: %1, file: %2, passphrase: %3",
    Severity: Minor
    Found in library/gpg/src/modules/GPG.rb - About 1 hr to fix

      Method CreateKey has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def CreateKey
            command = Ops.add("GPG_AGENT_INFO='' ", buildGPGcommand("--gen-key"))
            text_mode = Ops.get_boolean(UI.GetDisplayInfo, "TextMode", false)
      
            Builtins.y2debug("text_mode: %1", text_mode)
      Severity: Minor
      Found in library/gpg/src/modules/GPG.rb - About 1 hr to fix

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

            def parse_key(lines)
              lines = deep_copy(lines)
              ret = {}
        
              Builtins.foreach(lines) do |line|
        Severity: Minor
        Found in library/gpg/src/modules/GPG.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 CreateKey has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def CreateKey
              command = Ops.add("GPG_AGENT_INFO='' ", buildGPGcommand("--gen-key"))
              text_mode = Ops.get_boolean(UI.GetDisplayInfo, "TextMode", false)
        
              Builtins.y2debug("text_mode: %1", text_mode)
        Severity: Minor
        Found in library/gpg/src/modules/GPG.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 SignFile has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def SignFile(keyid, file, passphrase, ascii_signature)
              if passphrase.nil? || keyid.nil? || keyid == "" || file.nil? ||
                  file == ""
                Builtins.y2error(
                  "Invalid parameters: keyid: %1, file: %2, passphrase: %3",
        Severity: Minor
        Found in library/gpg/src/modules/GPG.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 parseKeys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def parseKeys(input)
              # NOTE: see /usr/share/doc/packages/gpg/DETAILS for another way
        
              ret = []
              lines = Builtins.splitstring(input, "\n")
        Severity: Minor
        Found in library/gpg/src/modules/GPG.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

            def PublicKeys
              # return the cached values if available
              return deep_copy(@public_keys) if !@public_keys.nil?
        
              out = callGPG("--list-keys --fingerprint")
        Severity: Minor
        Found in library/gpg/src/modules/GPG.rb and 1 other location - About 25 mins to fix
        library/gpg/src/modules/GPG.rb on lines 200..208

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

        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 PrivateKeys
              # return the cached values if available
              return deep_copy(@private_keys) if !@private_keys.nil?
        
              out = callGPG("--list-secret-keys --fingerprint")
        Severity: Minor
        Found in library/gpg/src/modules/GPG.rb and 1 other location - About 25 mins to fix
        library/gpg/src/modules/GPG.rb on lines 187..195

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

        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