Priyanka
Priyanka

Reputation: 11

Cyclomatic Complexity OF Model Class

Can anybody help me to understand why my model class has cyclomatic complexity of 89. When I run PMD it gives me 'The class 'GetResponse' has a total cyclomatic complexity of 89 (highest 1)'.

Please find code snippet as:

public class GetResponse  {
private String ewbNo;
private String ewayBillDate;
private String genMode;
private String userGstin;
private String supplyType;
private String subSupplyType;
private String docType;
private String docNo;
private String docDate;
private String fromGstin;
private String fromTrdName;
private String fromAddr1;
private String fromAddr2;
private String fromPlace;
private String fromPincode;
private String fromStateCode;
private String toGstin;
private String toTrdName;
private String toAddr1;
private String toAddr2;
private String toPlace;
private String toPincode;
private String toStateCode;
private Float totalValue;
private Float totInvValue;
private Float cgstValue;
private Float sgstValue;
private Float igstValue;
private Float cessValue;
private String transporterId;
private String transporterName;
private String transDocNo;
private String transMode;
private String transDocDate;
private String status;
private Integer actualDist;
private Integer noValidDays;
private String validUpto;
private Integer extendedTimes;
private String rejectStatus;
private String vehicleType;
private String actFromStateCode;
private String actToStateCode;
private Object itemList;
private Object VehiclListDetails;

//getters and setters
}

Upvotes: 1

Views: 660

Answers (1)

Stephen C
Stephen C

Reputation: 719436

According the Wikipedia page:

The [cyclomatic] complexity M is [] defined as

M = E − N + 2P,

where

E = the number of edges of the graph.
N = the number of nodes of the graph.
P = the number of connected components.

By my count, your class has 44 fields plus (I assume) getters and setters for each field.

A typical getter looks like this:

  public T getX() { return x; }

and this has cyclomatic complexity 1.

A typical setter looks like this:

  public void setX(T x) { this.x = x; }

and this also has cyclomatic complexity 1.

Finally, if we consider the field declarations as a sequence of statements, that is a graph with 44 nodes and 43 edges (and no connected components), giving a complexity of 1.

Thus, the aggregated cyclomatic complexity of the entire class is 44 x 1 + 44 x 1 + 1 == 89.

Upvotes: 2

Related Questions