cyberark/conjur-api-ruby

View on GitHub
lib/conjur/has_attributes.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
90%

Conjur::HasAttributes#annotation_value is controlled by argument 'name'
Open

        (annotations.find{|a| a['name'] == name} || {})['value']
Severity: Minor
Found in lib/conjur/has_attributes.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Conjur::HasAttributes#annotations refers to 'e' more than self (maybe move it to another class?)
Open

      Hash[(attributes['annotations']||{}).collect {|e| [e['name'],e['value']]}]
Severity: Minor
Found in lib/conjur/has_attributes.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::HasAttributes#fetch_attributes calls 'url_for(:resources_resource, credentials, id)' 2 times
Open

      cache_key = Conjur.cache_key username, url_for(:resources_resource, credentials, id).url
      Conjur.cache.fetch_attributes cache_key do
        JSON.parse(url_for(:resources_resource, credentials, id).get.body)
Severity: Minor
Found in lib/conjur/has_attributes.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

Conjur::HasAttributes#annotations has the variable name 'e'
Open

      Hash[(attributes['annotations']||{}).collect {|e| [e['name'],e['value']]}]
Severity: Minor
Found in lib/conjur/has_attributes.rb by reek

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

Conjur::HasAttributes#annotation_value has the variable name 'a'
Open

        (annotations.find{|a| a['name'] == name} || {})['value']
Severity: Minor
Found in lib/conjur/has_attributes.rb by reek

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

Add empty line after guard clause.
Open

      return @attributes if @attributes
Severity: Minor
Found in lib/conjur/has_attributes.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