Standard Analyses

SemmleCode Professional comes with a wide range of pre-packaged analyses, from architectural properties and metrics, to statement-level checks for likely bugs and violations of best practice.


Methods or constructors with too many parameters

This query finds callables (methods or constructors) with more than seven parameters. Library callables and generated callables are not shown.

How to Interpret the Query Results

The query flags any such callable, and also display the list of found occurrences in the result view.

How to Address the Query Results

Methods and constructors with too many parameters are hard to use, and it may not be easy for the programmer to remember the semantics of every individual parameter. It is usually preferable to introduce a new class to bundle up several parameters into a common abstraction, and pass an object of this class instead.

Source Code
import default

from Callable c
where c.fromSource() and 
      not c instanceof GeneratedCallable and
      c.getNumberOfParameters() > 7
select c, "Method or constructor with many parameters (" 
          + c.getNumberOfParameters().toString() + ")"
References