ClusterLabs/hawk

View on GitHub
hawk/app/models/primitive.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Assignment Branch Condition size for shell_syntax is too high. [32.25/15]
Open

  def shell_syntax
    [].tap do |cmd|
      # TODO(must): Ensure clazz, provider and type are sanitized
      cmd.push "primitive #{id}"

Severity: Minor
Found in hawk/app/models/primitive.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for update is too high. [25.1/15]
Open

  def update
    unless self.class.exists?(self.id, self.class.cib_type_write)
      errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
      return false
    end
Severity: Minor
Found in hawk/app/models/primitive.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [33/30]
Open

  def shell_syntax
    [].tap do |cmd|
      # TODO(must): Ensure clazz, provider and type are sanitized
      cmd.push "primitive #{id}"

Severity: Minor
Found in hawk/app/models/primitive.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method shell_syntax has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def shell_syntax
    [].tap do |cmd|
      # TODO(must): Ensure clazz, provider and type are sanitized
      cmd.push "primitive #{id}"

Severity: Minor
Found in hawk/app/models/primitive.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

Assignment Branch Condition size for validate_params is too high. [17.97/15]
Open

  def validate_params
    required_params = []
    res = Util.get_metadata_hash(agent_name)
    param_res = res["resource_agent"]["parameters"]["parameter"]
    if param_res
Severity: Minor
Found in hawk/app/models/primitive.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method shell_syntax has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def shell_syntax
    [].tap do |cmd|
      # TODO(must): Ensure clazz, provider and type are sanitized
      cmd.push "primitive #{id}"

Severity: Minor
Found in hawk/app/models/primitive.rb - About 1 hr to fix

    Method validate_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_params
        required_params = []
        res = Util.get_metadata_hash(agent_name)
        param_res = res["resource_agent"]["parameters"]["parameter"]
        if param_res
    Severity: Minor
    Found in hawk/app/models/primitive.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

    Use each_value instead of each.
    Open

            ops.each do |_id, op|
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      def shell_syntax
        [].tap do |cmd|
          # TODO(must): Ensure clazz, provider and type are sanitized
          cmd.push "primitive #{id}"
    
    
    Severity: Major
    Found in hawk/app/models/primitive.rb and 1 other location - About 2 hrs to fix
    hawk/app/models/template.rb on lines 304..344

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

    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

      def update
        unless self.class.exists?(self.id, self.class.cib_type_write)
          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
          return false
        end
    Severity: Major
    Found in hawk/app/models/primitive.rb and 1 other location - About 1 hr to fix
    hawk/app/models/template.rb on lines 283..301

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

    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

    Favor format over String#%.
    Open

          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of a single string formatting utility. Valid options include Kernel#format, Kernel#sprintf and String#%.

    The detection of String#% cannot be implemented in a reliable manner for all cases, so only two scenarios are considered - if the first argument is a string literal and if the second argument is an array literal.

    Example: EnforcedStyle: format(default)

    # bad
    puts sprintf('%10s', 'hoge')
    puts '%10s' % 'hoge'
    
    # good
    puts format('%10s', 'hoge')

    Example: EnforcedStyle: sprintf

    # bad
    puts format('%10s', 'hoge')
    puts '%10s' % 'hoge'
    
    # good
    puts sprintf('%10s', 'hoge')

    Example: EnforcedStyle: percent

    # bad
    puts format('%10s', 'hoge')
    puts sprintf('%10s', 'hoge')
    
    # good
    puts '%10s' % 'hoge'

    Use alias instead of alias_method in a class body.
    Open

      alias_method :clazz, :clazz_with_template
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Use alias instead of alias_method in a class body.
    Open

      alias_method :type_without_template, :type
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Use alias instead of alias_method in a class body.
    Open

      alias_method :provider_without_template, :provider
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Use alias instead of alias_method in a class body.
    Open

      alias_method :clazz_without_template, :clazz
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Use alias instead of alias_method in a class body.
    Open

      alias_method :type, :type_with_template
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Extra blank line detected.
    Open

    
      protected
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cops checks for two or more consecutive blank lines.

    Example:

    # bad - It has two empty lines.
    some_method
    # one empty line
    # two empty lines
    some_method
    
    # good
    some_method
    # one empty line
    some_method

    Use alias instead of alias_method in a class body.
    Open

      alias_method :provider, :provider_with_template
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if items.key?("required") && items["required"] == "1"
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Prefer annotated tokens (like %<foo>s</foo>) over template tokens (like %{foo}).
    Open

          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

          if value.blank? && required_params.include?(param)
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Redundant self detected.
    Open

            record.class.to_s == self.to_s
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    Redundant self detected.
    Open

          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    Redundant self detected.
    Open

        unless self.class.exists?(self.id, self.class.cib_type_write)
    Severity: Minor
    Found in hawk/app/models/primitive.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    There are no issues that match your filters.

    Category
    Status