uptech/togls

View on GitHub
lib/togls/rule_repository_drivers/in_memory_driver.rb

Summary

Maintainability
A
35 mins
Test Coverage

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

module Togls
  module RuleRepositoryDrivers
    # Rule Repository In-Memory Driver
    #
    # The Rule Repository In-Memory Driver provides the interface to store and
Severity: Minor
Found in lib/togls/rule_repository_drivers/in_memory_driver.rb and 2 other locations - About 35 mins to fix
lib/togls/feature_repository_drivers/in_memory_driver.rb on lines 3..26
lib/togls/toggle_repository_drivers/in_memory_driver.rb on lines 3..26

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

Remove unnecessary require statement.
Open

require 'thread'

Checks for unnecessary require statement.

The following features are unnecessary require statement because they are already loaded.

ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }' ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13] ["enumerator.so", "rational.so", "complex.so", "thread.rb"]

This cop targets Ruby 2.2 or higher containing these 4 features.

Example:

# bad
require 'unloaded_feature'
require 'thread'

# good
require 'unloaded_feature'

Avoid using Marshal.load.
Open

            Marshal.load(@rules[rule_id])

This cop checks for the use of Marshal class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

Example:

# bad
Marshal.load("{}")
Marshal.restore("{}")

# good
Marshal.dump("{}")

# okish - deep copy hack
Marshal.load(Marshal.dump({}))

Use Hash#key? instead of Hash#has_key?.
Open

          if @rules.has_key?(rule_id)

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Missing magic comment # frozen_string_literal: true.
Open

require 'thread'

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Redundant else-clause.
Open

          else

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

There are no issues that match your filters.

Category
Status