|
Counts the number of parameters of a callable (a method or a constructor).
It is generally considered bad practice to have methods with 8
or more parameters: in those cases, it is often preferable to
encapsulate the tuple of parameters in a new class.
Pre-packaged Query
Query name = "Semmle/Metrics/Methods/Many-parameter methods"
Reports methods that have more than seven parameters,
in the Eclipse problems view.
from MetricCallable c, int n
where c.fromSource()
and
n=c.getNumberOfParameters()
and
n > 7
select c, "too many parameters"
.QL Source of Metric
This metric is defined in the class MetricCallable:
int getNumberOfParameters() {
result = count(int pos | params(_,_,_,pos,this,_) )
}
References
Martin Fowler.
Introduce Parameter Object Refactoring
.
Streek.
Bad Smells in Code: Long Parameter List
,
University of California at Berkeley, 2006.
|