postmodern/command_mapper.rb

View on GitHub

Showing 26 of 30 total issues

Method sudo_command has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    def sudo_command(askpass: nil,
                     background: nil,
                     bell: nil,
                     close_from: nil,
                     chdir: nil,
Severity: Minor
Found in lib/command_mapper/command.rb - About 7 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

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

  class Command

    include Types

    # The command name.
Severity: Minor
Found in lib/command_mapper/command.rb - About 3 hrs to fix

    File command.rb has 281 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative 'types'
    require_relative 'argument'
    require_relative 'option'
    
    require 'shellwords'
    Severity: Minor
    Found in lib/command_mapper/command.rb - About 2 hrs to fix

      Method validate has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate(value)
              case value
              when nil
                unless allow_empty?
                  return [false, "cannot be nil"]
      Severity: Minor
      Found in lib/command_mapper/types/str.rb - About 2 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_argv has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def command_argv
            argv = [@command_path || @command_name]
      
            self.class.options.each do |name,option|
              unless (value = self[name]).nil?
      Severity: Minor
      Found in lib/command_mapper/command.rb - About 2 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 validate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate(value)
            if repeats?
              values = case value
                       when Array then value
                       else            [value]
      Severity: Minor
      Found in lib/command_mapper/argument.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 validate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate(value)
              case value
              when Hash
                if value.length < 1
                  return [false, "cannot be empty"]
      Severity: Minor
      Found in lib/command_mapper/types/key_value.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 validate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate(value)
              case value
              when Integer
                # no-op
              when String
      Severity: Minor
      Found in lib/command_mapper/types/num.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 validate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate(value)
              case value
              when Float
                # no-op
              when String
      Severity: Minor
      Found in lib/command_mapper/types/dec.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 validate has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def validate(value)
              case value
              when Hash
                if value.length < 1
                  return [false, "cannot be empty"]
      Severity: Minor
      Found in lib/command_mapper/types/key_value.rb - About 1 hr to fix

        Method validate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def validate(value)
                case value
                when String
                  unless value =~ /\A(?:0x)?[A-Fa-f0-9]+\z/
                    return [false, "not in hex format (#{value.inspect})"]
        Severity: Minor
        Found in lib/command_mapper/types/hex.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 emit_option_flag_and_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def emit_option_flag_and_value(argv,value)
              if !@value.required? && value == true
                argv << @flag
              else
                string = @value.format(value)
        Severity: Minor
        Found in lib/command_mapper/option.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_argv has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def command_argv
              argv = [@command_path || @command_name]
        
              self.class.options.each do |name,option|
                unless (value = self[name]).nil?
        Severity: Minor
        Found in lib/command_mapper/command.rb - About 1 hr to fix

          Method subcommand has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.subcommand(name,&block)
                name            = name.to_s
                method_name     = name.tr('-','_')
                class_name      = name.split(/[_-]+/).map(&:capitalize).join
                subcommand_name = method_name.to_sym
          Severity: Minor
          Found in lib/command_mapper/command.rb - About 1 hr to fix

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

                  def format(value)
                    case value
                    when String
                      if leading_zero? && !value.start_with?('0x')
                        value = "0x#{value}"
            Severity: Minor
            Found in lib/command_mapper/types/hex.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 subcommand has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.subcommand(name,&block)
                  name            = name.to_s
                  method_name     = name.tr('-','_')
                  class_name      = name.split(/[_-]+/).map(&:capitalize).join
                  subcommand_name = method_name.to_sym
            Severity: Minor
            Found in lib/command_mapper/command.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 validate_repeating has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate_repeating(value)
                  values = case value
                           when Array then value
                           else            [value]
                           end
            Severity: Minor
            Found in lib/command_mapper/option.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 argv has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def argv(argv=[],value)
                  valid, message = validate(value)
            
                  unless valid
                    raise(ValidationError,"option #{@name} was given an invalid value (#{value.inspect}): #{message}")
            Severity: Minor
            Found in lib/command_mapper/option.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 validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def validate(value)
                    values = Array(value)
            
                    if values.empty?
                      unless allow_empty?
            Severity: Minor
            Found in lib/command_mapper/types/list.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

            Avoid too many return statements within this method.
            Open

                      return [false, "must be a Hash or an Array (#{value.inspect})"]
            Severity: Major
            Found in lib/command_mapper/types/key_value.rb - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language