Methods per class
Methods per class is the number of methods a class declares. It is the one metric of a class, and it is reported only: no rule limits it.
A class here is a declaration that has members of its own: a class, a mixin, an extension, an enum or an extension type.
How it is counted
Section titled “How it is counted”The methods and operators a class, mixin, extension, enum or extension type declares, instance and static, with a body or abstract. Constructors, getters, setters and fields do not count.
Example
Section titled “Example”class Cart { Cart(this.items); Cart.empty() : items = [];
final List<Item> items;
int get count => items.length;
int total() => items.fold(0, (sum, item) => sum + item.price); void add(Item item) => items.add(item); static Cart merge(Cart first, Cart second) => Cart([...first.items, ...second.items]); Cart operator +(Cart other) => merge(this, other);}Its value is 4:
| Member | Counts |
|---|---|
total and add, instance methods |
2 |
merge, a static method |
1 |
operator + |
1 |
the two constructors, the field items and the getter count |
0 |
None. No rule limits methods per class, so the report shows its limit as none and marks no value as over it.
In the report
Section titled “In the report”assay metrics gives the metric a row in the box Metrics, with the limit none, and a box of its own with the highest values first. assay metrics shows the report.
- JSON: the key
methodsPerClassof each class, with itsvalueand thelimitnull. A class is listed with its name, its kind and its place. - HTML: the table of classes: the class, its kind, methods per class, file and line.