How can I reduce the cyclomatic complexity of the following code
public class AnswerTypeEnumConverter implements CustomConverter {
public Object convert(Object destination, Object source, Class destinationClass, Class sourceClass)
...
the method convert()
is from the interface CustomConverter
which is a predefined interface in my project and is provided as a jar, so I can't change the signature of the convert()
method, which is
Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass);
I am using SONAR 3.6 and it is showing error as:
The Cyclomatic Complexity of this method is 15 which is greater than 10 authorized.
Here is the code for the convert
method
public Object convert(Object destination, Object source, Class<?> destinationClass, Class<?> sourceClass) {
Object destinationValue = destination;
if (source == null) {
LOGGER.info("APPLICATION OBJECT IS NULL CONVERSION STOPPED AND RETURNING NULL");
return null;
}
if (destinationValue == null) {
destinationValue = new KYExchangeTransfer();
}
destinationValue = setRequest(((Application) source), ((KYExchangeTransfer) destinationValue));
return destinationValue;
}
How can i reduce the complexity?