ptomulik/puppet-portsng

View on GitHub
lib/puppet/provider/package/portsng.rb

Summary

Maintainability
C
1 day
Test Coverage

File portsng.rb has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

%w(vash portsutil backports).each do |p|
  dir = File.join(File.dirname(__FILE__), "../../../../../#{p}/lib")
  dir = File.expand_path(dir)
  $LOAD_PATH.unshift(dir) if !$LOAD_PATH.include?(dir) && File.directory?(dir)
end
Severity: Minor
Found in lib/puppet/provider/package/portsng.rb - About 4 hrs to fix

    Method prepare_options has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def prepare_options(options, defaults, extra = [], deny = [])
        return defaults.dup unless options
    
        # handle {option => value} hashes and flatten nested arrays
        options = options.collect do |x|
    Severity: Minor
    Found in lib/puppet/provider/package/portsng.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 latest has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def latest
        # If there's no "latest" version, we just return a placeholder
        result = :latest
        oldversion = properties[:ensure]
        case portstatus
    Severity: Minor
    Found in lib/puppet/provider/package/portsng.rb - About 1 hr to fix

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

        def self.instances_from_package_records(records, options)
          packages = []
          with_unique('installed ports', records) do |pkgname, rec|
            unless rec[:portorigin] && ['<', '=', '>'].include?(rec[:portstatus])
              rec.delete(:portorigin) if rec[:portorigin]
      Severity: Minor
      Found in lib/puppet/provider/package/portsng.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 package_settings_validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def package_settings_validate(opts)
          return true unless opts # options not defined
          options_class = Puppet::Util::PTomulik::Package::Ports::Options
          unless opts.is_a?(Hash) || opts.is_a?(options_class)
            raise ArgumentError, "#{opts.inspect} of type #{opts.class} is not an " \
      Severity: Minor
      Found in lib/puppet/provider/package/portsng.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 latest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def latest
          # If there's no "latest" version, we just return a placeholder
          result = :latest
          oldversion = properties[:ensure]
          case portstatus
      Severity: Minor
      Found in lib/puppet/provider/package/portsng.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

      Method validate_package_setting has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_package_setting(key, value)
          options_class = Puppet::Util::PTomulik::Package::Ports::Options
          unless options_class.option_name?(key)
            raise ArgumentError, "#{key.inspect} is not a valid option name (for" \
                                 ' $package_settings)'
      Severity: Minor
      Found in lib/puppet/provider/package/portsng.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

      Empty line detected around arguments.
      Open

      
        `install_options` are passed to `portupgrade` command when installing,

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_INSTALL_OPTIONS, %w(-N), %w(-R -f))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      Empty line detected around arguments.
      Open

      
      
      

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      Avoid rescuing without specifying an error class.
      Open

          rescue

      This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

      Example: EnforcedStyle: implicit

      # `implicit` will enforce using `rescue` instead of
      # `rescue StandardError`.
      
      # bad
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Example: EnforcedStyle: explicit (default)

      # `explicit` will enforce using `rescue StandardError`
      # instead of `rescue`.
      
      # bad
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      %w-literals should be delimited by [ and ].
      Open

        %w(INTERACTIVE UNAME).each do |var|

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_UPGRADE_OPTIONS, %w(), %w(-f -N))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_REINSTALL_OPTIONS, %w(-f), %w(-N))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_REINSTALL_OPTIONS, %w(-f), %w(-N))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      Use %i or %I for an array of symbols.
      Open

        self::PORT_ATTRIBUTES = [
          :pkgname,
          :portorigin,
          :portname,
          :portstatus,

      This cop can check for array literals made up of symbols that are not using the %i() syntax.

      Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

      Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

      Example: EnforcedStyle: percent (default)

      # good
      %i[foo bar baz]
      
      # bad
      [:foo, :bar, :baz]

      Example: EnforcedStyle: brackets

      # good
      [:foo, :bar, :baz]
      
      # bad
      %i[foo bar baz]

      Empty line detected around arguments.
      Open

      
        `package_settings` shall be a hash with port's option names as keys (all

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      %w-literals should be delimited by [ and ].
      Open

          self::DEFAULT_UNINSTALL_OPTIONS = %w().freeze

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      Empty line detected around arguments.
      Open

      
            package { 'www/apache22':

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_INSTALL_OPTIONS, %w(-N), %w(-R -f))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

          self::DEFAULT_UNINSTALL_OPTIONS = %w(delete -y).freeze

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

            prepare_options(ops, self.class::DEFAULT_UNINSTALL_OPTIONS, %w(delete))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      Empty line detected around arguments.
      Open

      
        The options are written to `/var/db/ports/*/options.local` files (one file

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      %w-literals should be delimited by [ and ].
      Open

        self::DEFAULT_INSTALL_OPTIONS = %w(-N -M BATCH=yes).freeze

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

        self::DEFAULT_UPGRADE_OPTIONS = %w(-R -M BATCH=yes).freeze

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      Empty line detected around arguments.
      Open

      
        `uninstall_options` are passed to uninstall command. When the target system

      This cops checks if empty lines exist around the arguments of a method invocation.

      Example:

      # bad
      do_something(
        foo
      
      )
      
      process(bar,
      
              baz: qux,
              thud: fred)
      
      some_method(
      
        [1,2,3],
        x: y
      )
      
      # good
      do_something(
        foo
      )
      
      process(bar,
              baz: qux,
              thud: fred)
      
      some_method(
        [1,2,3],
        x: y
      )

      %w-literals should be delimited by [ and ].
      Open

          prepare_options(ops, self.class::DEFAULT_UPGRADE_OPTIONS, %w(), %w(-f -N))

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

      %w(vash portsutil backports).each do |p|

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      %w-literals should be delimited by [ and ].
      Open

        self::DEFAULT_REINSTALL_OPTIONS = %w(-r -f -M BATCH=yes).freeze

      This cop enforces the consistent usage of %-literal delimiters.

      Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

      Example:

      # Style/PercentLiteralDelimiters:
      #   PreferredDelimiters:
      #     default: '[]'
      #     '%i':    '()'
      
      # good
      %w[alpha beta] + %i(gamma delta)
      
      # bad
      %W(alpha #{beta})
      
      # bad
      %I(alpha beta)

      There are no issues that match your filters.

      Category
      Status