superiorlu/unicorn_metrics

View on GitHub
lib/unicorn_metrics/middleware.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Use each_value instead of each.
Open

      Raindrops::Linux.unix_listener_stats(@unix).each do |_, stats|
Severity: Minor
Found in lib/unicorn_metrics/middleware.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 }

Use each_value instead of each.
Open

      Raindrops::Linux.tcp_listener_stats(@tcp).each do |_, stats|
Severity: Minor
Found in lib/unicorn_metrics/middleware.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 raindrops_unix_listener_stats
      hash = {
        'raindrops.unix.active' => { type: :gauge, value: 0 },
        'raindrops.unix.queued' => { type: :gauge, value: 0 }
      }
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb and 1 other location - About 50 mins to fix
lib/unicorn_metrics/middleware.rb on lines 80..89

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

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 raindrops_tcp_listener_stats
      hash = {
        'raindrops.tcp.active' => { type: :gauge, value: 0 },
        'raindrops.tcp.queued' => { type: :gauge, value: 0 }
      }
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb and 1 other location - About 50 mins to fix
lib/unicorn_metrics/middleware.rb on lines 92..101

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

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

        Raindrops::Linux.tcp_listener_stats(@tcp).each do |addr, stats|
          listeners["raindrops.#{addr}.active"] = stats.active.to_s
          listeners["raindrops.#{addr}.queued"] = stats.queued.to_s
        end if @tcp
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb and 1 other location - About 20 mins to fix
lib/unicorn_metrics/middleware.rb on lines 112..115

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

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

        Raindrops::Linux.unix_listener_stats(@unix).each do |addr, stats|
          listeners["raindrops.#{addr}.active"] = stats.active.to_s
          listeners["raindrops.#{addr}.queued"] = stats.queued.to_s
        end if @unix
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb and 1 other location - About 20 mins to fix
lib/unicorn_metrics/middleware.rb on lines 108..111

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

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 a normal if-statement over a modifier clause in a multiline statement.
Open

        Raindrops::Linux.unix_listener_stats(@unix).each do |addr, stats|
          listeners["raindrops.#{addr}.active"] = stats.active.to_s
          listeners["raindrops.#{addr}.queued"] = stats.queued.to_s
        end if @unix
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb by rubocop

Checks for uses of if/unless modifiers with multiple-lines bodies.

Example:

# bad
{
  result: 'this should not happen'
} unless cond

# good
{ result: 'ok' } if cond

Favor a normal if-statement over a modifier clause in a multiline statement.
Open

        Raindrops::Linux.tcp_listener_stats(@tcp).each do |addr, stats|
          listeners["raindrops.#{addr}.active"] = stats.active.to_s
          listeners["raindrops.#{addr}.queued"] = stats.queued.to_s
        end if @tcp
Severity: Minor
Found in lib/unicorn_metrics/middleware.rb by rubocop

Checks for uses of if/unless modifiers with multiple-lines bodies.

Example:

# bad
{
  result: 'this should not happen'
} unless cond

# good
{ result: 'ok' } if cond

There are no issues that match your filters.

Category
Status