I tried the plug in CodeMetrics for Visual Studio Code along with some of my current Angular projects, and I was a little suprised about the outcome.

I have a Service in Angular that fetches search results from an API. This method is pretty much boilerplate Angular code. It looks like this:

getSearchResult(searchValue: string): Subscription {
  const path = '/api/getSearchResult';

  const params = new URLSearchParams();
  params.set('searchValue', searchValue);

  return this.http.get<SearchResult>(
    this.apiService.getUrl() + path + '?' + params.toString()
    map((response: any) => response.result),
    catchError(error => {
      return of(SearchResultFactory.createEmptyResult());
  ).subscribe(result => this.searchResult$.next(result));

I don't find this method particular hard to read or to understand. And yes, you need to be used to "The Angular Way" and rxjs or course.

But CodeMetrics says:

Complexity is 7 It's time to do something …

Is the metric right? Could this be simplyfied? I mean this looks almost like a text book example. I could think of is to construct the URL parameters in a separate function, but is it worth it?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.