Class: Reek::SmellDetectors::TooManyMethods
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::TooManyMethods
- Defined in:
- lib/reek/smell_detectors/too_many_methods.rb
Overview
A Large Class is a class or module that has a large number of instance variables, methods or lines of code.
TooManyMethods
reports classes having more than a configurable number of methods. The method count includes public, protected and private methods, and excludes methods inherited from superclasses or included modules.
See Too-Many-Methods for details.
Constant Summary collapse
- MAX_ALLOWED_METHODS_KEY =
The name of the config field that sets the maximum number of methods permitted in a class.
'max_methods'
- DEFAULT_MAX_METHODS =
15
Constants inherited from BaseDetector
BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Class Method Summary collapse
Instance Method Summary collapse
- #max_allowed_methods ⇒ Object private
-
#sniff ⇒ Array<SmellWarning>
Checks context for too many methods.
Methods inherited from BaseDetector
#config_for, configuration_keys, descendants, #enabled?, #exception?, #expression, inherited, #initialize, #run, smell_type, #smell_type, #smell_warning, #source_line, to_detector, todo_configuration_for, #value
Constructor Details
This class inherits a constructor from Reek::SmellDetectors::BaseDetector
Class Method Details
.contexts ⇒ Object
23 24 25 |
# File 'lib/reek/smell_detectors/too_many_methods.rb', line 23 def self.contexts [:class] end |
.default_config ⇒ Object
27 28 29 30 31 |
# File 'lib/reek/smell_detectors/too_many_methods.rb', line 27 def self.default_config super.merge( MAX_ALLOWED_METHODS_KEY => DEFAULT_MAX_METHODS, EXCLUDE_KEY => []) end |
Instance Method Details
#max_allowed_methods ⇒ Object (private)
51 52 53 |
# File 'lib/reek/smell_detectors/too_many_methods.rb', line 51 def max_allowed_methods value(MAX_ALLOWED_METHODS_KEY, context) end |
#sniff ⇒ Array<SmellWarning>
Checks context for too many methods
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/reek/smell_detectors/too_many_methods.rb', line 38 def sniff # TODO: Only checks instance methods! actual = context.node_instance_methods.length return [] if actual <= max_allowed_methods [smell_warning( lines: [source_line], message: "has at least #{actual} methods", parameters: { count: actual })] end |