cyberark/conjur-api-ruby

View on GitHub
lib/conjur/escape.rb

Summary

Maintainability
A
0 mins
Test Coverage
B
86%

Conjur::Escape::ClassMethods#path_or_query_escape refers to 'str' more than self (maybe move it to another class?)
Open

        str = str.id if str.respond_to?(:id)
        # Leave colons and forward slashes alone
        require 'addressable/uri'
        Addressable::URI.encode(str.to_s)
Severity: Minor
Found in lib/conjur/escape.rb by reek

Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

Example

Running Reek on:

class Warehouse
  def sale_price(item)
    (item.price - item.rebate) * @vat
  end
end

would report:

Warehouse#total_price refers to item more than self (FeatureEnvy)

since this:

(item.price - item.rebate)

belongs to the Item class, not the Warehouse.

Conjur::Escape::ClassMethods#path_or_query_escape manually dispatches method call
Open

        str = str.id if str.respond_to?(:id)
Severity: Minor
Found in lib/conjur/escape.rb by reek

Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

Example

class MyManualDispatcher
  attr_reader :foo

  def initialize(foo)
    @foo = foo
  end

  def call
    foo.bar if foo.respond_to?(:bar)
  end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

Conjur::Escape::ClassMethods has no descriptive comment
Open

    module ClassMethods
Severity: Minor
Found in lib/conjur/escape.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

Conjur::Escape::ClassMethods#fully_escape doesn't depend on instance state (maybe move it to another class?)
Open

      def fully_escape(str)
Severity: Minor
Found in lib/conjur/escape.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Add empty line after guard clause.
Open

        return "false" unless str
Severity: Minor
Found in lib/conjur/escape.rb by rubocop

This cop enforces empty line after guard clause

Example:

# bad
def foo
  return if need_return?
  bar
end

# good
def foo
  return if need_return?

  bar
end

# good
def foo
  return if something?
  return if something_different?

  bar
end

# also good
def foo
  if something?
    do_something
    return if need_return?
  end
end

There are no issues that match your filters.

Category
Status