ClusterLabs/hawk

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

Summary

Maintainability
B
5 hrs
Test Coverage

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

    def mapping
      # TODO(must): Are other meta attributes for clone valid?
      @mapping ||= begin
        {
          "is-managed" => {
Severity: Minor
Found in hawk/app/models/master.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 mapping has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def mapping
      # TODO(must): Are other meta attributes for clone valid?
      @mapping ||= begin
        {
          "is-managed" => {
Severity: Major
Found in hawk/app/models/master.rb - About 2 hrs to fix

    Assignment Branch Condition size for update is too high. [19.13/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/master.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 instantiate is too high. [18.55/15]
    Open

        def instantiate(xml)
          record = allocate
    
          record.child = if xml.elements["primitive|group"]
            xml.elements["primitive|group"].attributes["id"]
    Severity: Minor
    Found in hawk/app/models/master.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 mapping is too high. [16.12/15]
    Open

        def mapping
          # TODO(must): Are other meta attributes for clone valid?
          @mapping ||= begin
            {
              "is-managed" => {
    Severity: Minor
    Found in hawk/app/models/master.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

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

        def instantiate(xml)
          record = allocate
    
          record.child = if xml.elements["primitive|group"]
            xml.elements["primitive|group"].attributes["id"]
    Severity: Major
    Found in hawk/app/models/master.rb and 1 other location - About 1 hr to fix
    hawk/app/models/clone.rb on lines 31..53

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

    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/master.rb and 1 other location - About 1 hr to fix
    hawk/app/models/clone.rb on lines 133..146

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

    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 shell_syntax
        [].tap do |cmd|
          cmd.push "ms #{id} #{child}"
    
          unless meta.empty?
    Severity: Minor
    Found in hawk/app/models/master.rb and 1 other location - About 35 mins to fix
    hawk/app/models/clone.rb on lines 149..163

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

    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

    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/master.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>

    Redundant self detected.
    Open

        unless self.class.exists?(self.id, self.class.cib_type_write)
    Severity: Minor
    Found in hawk/app/models/master.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 else-clause.
    Open

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

    Checks for empty else-clauses, possibly including comments and/or an explicit nil depending on the EnforcedStyle.

    Example: EnforcedStyle: empty

    # warn only on empty else
    
    # bad
    if condition
      statement
    else
    end
    
    # good
    if condition
      statement
    else
      nil
    end
    
    # good
    if condition
      statement
    else
      statement
    end
    
    # good
    if condition
      statement
    end

    Example: EnforcedStyle: nil

    # warn on else with nil in it
    
    # bad
    if condition
      statement
    else
      nil
    end
    
    # good
    if condition
      statement
    else
    end
    
    # good
    if condition
      statement
    else
      statement
    end
    
    # good
    if condition
      statement
    end

    Example: EnforcedStyle: both (default)

    # warn on empty else and else with nil in it
    
    # bad
    if condition
      statement
    else
      nil
    end
    
    # bad
    if condition
      statement
    else
    end
    
    # good
    if condition
      statement
    else
      statement
    end
    
    # good
    if condition
      statement
    end

    Favor format over String#%.
    Open

          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
    Severity: Minor
    Found in hawk/app/models/master.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'

    Redundant self detected.
    Open

          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
    Severity: Minor
    Found in hawk/app/models/master.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

    Empty line detected around arguments.
    Open

    
            Hash[vals]
    Severity: Minor
    Found in hawk/app/models/master.rb by rubocop

    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
    )

    There are no issues that match your filters.

    Category
    Status