3

I have a microservice using Spring Webflux that makes some requests to another services. The code looks like this:

public class ExampleService {
    
    @Autowired
    private WebClient webClient;
    
    @Value("${microservices.address-data.baseUrl}")
    private String exampleBaseUrl;
    
    @Value("${microservices.address-data.endpoints.get}")
    private String exampleGetEndpoint;
    
    @Value("${microservices.address-data.endpoints.post}")
    private String examplePostEndpoint;
    
    @Value("${microservices.address-data.endpoints.patch}")
    private String examplePatchEndpoint;
    
    public Flux<exampleBO> getexample(String customerId) {
        return webClient.mutate().baseUrl(exampleBaseUrl).build().get()
                .uri(uriBuilder -> uriBuilder.path(exampleGetEndpoint).build(customerId))
                .retrieve().bodyToFlux(exampleBO.class);
        
    }
    public Mono<Long> saveexample(String customerId, Mono<exampleBO> personalData) {
        return webClient.mutate().baseUrl(exampleBaseUrl).build().post()
                .uri(uriBuilder -> uriBuilder.path(examplePostEndpoint).build(customerId))
                .body(personalData, exampleBO.class).retrieve().bodyToMono(Long.class);
    }
    public Mono<Long> updateexample(String leadId, String addressId, Mono<exampleBO> example) {
        return webClient.mutate().baseUrl(exampleBaseUrl).build().patch()
                .uri(uriBuilder -> uriBuilder.path(examplePatchEndpoint).build(leadId, addressId))
                .body(example, exampleBO.class).retrieve().bodyToMono(Long.class);
    }
}

When Sonar analyzes this code, the measure of Cyclomatic Complexity has a value of 6 I don't know how to reduce this values, because I haven't any block with conditionals (if/else/switch). If in this service I have many classes like this, the final complexity will be high and I can pass the Sonar analysis.

radrow
  • 6,419
  • 4
  • 26
  • 53

0 Answers0