Class: Reek::Smells::UtilityFunction

Inherits:
SmellDetector show all
Defined in:
lib/reek/smells/utility_function.rb

Overview

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

Currently UtilityFunction will warn about any method that:

  • is non-empty

  • does not override an inherited method

  • calls at least one method on another object

  • doesn’t use any of self’s instance variables

  • doesn’t use any of self’s methods

Constant Summary

Constants inherited from SmellDetector

SmellDetector::ENABLED_KEY, SmellDetector::EXCLUDE_KEY

Instance Method Summary collapse

Methods inherited from SmellDetector

class_name, contexts, default_config, #examine, #exception?, #initialize, listen, #smell_name

Constructor Details

This class inherits a constructor from Reek::Smells::SmellDetector

Instance Method Details

#examine_context(method, report) ⇒ Object

Checks whether the given method is a utility function. Any smells found are added to the report.



25
26
27
28
29
30
31
# File 'lib/reek/smells/utility_function.rb', line 25

def examine_context(method, report)
  return false if method.calls.keys.length == 0 or
    method.num_statements == 0 or
    method.depends_on_instance?
  report << SmellWarning.new(self, method,
                "doesn't depend on instance state")
end