keymetrics/pm2-io-apm

View on GitHub
src/census/plugins/http.ts

Summary

Maintainability
D
2 days
Test Coverage

File http.ts has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Copyright 2018, OpenCensus Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
Severity: Minor
Found in src/census/plugins/http.ts - About 4 hrs to fix

    Function getPatchIncomingRequestFunction has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      protected getPatchIncomingRequestFunction () {
        return (original: (event: string) => boolean) => {
          const plugin = this
          // This function's signature is that of an event listener, which can have
          // any number of variable-type arguments.
    Severity: Major
    Found in src/census/plugins/http.ts - About 2 hrs to fix

      Function getMakeRequestTraceFunction has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private getMakeRequestTraceFunction (
            request: httpModule.ClientRequest, options: httpModule.RequestOptions,
            plugin: HttpPlugin): Func<httpModule.ClientRequest> {
          return (span: Span): httpModule.ClientRequest => {
            plugin.logger.debug('makeRequestTrace')
      Severity: Major
      Found in src/census/plugins/http.ts - About 2 hrs to fix

        Function incomingRequest has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              return function incomingRequest (event: string, ...args: any[]): boolean {
                // Only traces request events
                if (event !== 'request') {
                  return original.apply(this, arguments)
                }
        Severity: Major
        Found in src/census/plugins/http.ts - About 2 hrs to fix

          Function getPatchOutgoingRequestFunction has 61 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            protected getPatchOutgoingRequestFunction () {
              return (original: Func<httpModule.ClientRequest>): Func<
                         httpModule.ClientRequest> => {
                const plugin = this
                const kind = plugin.moduleName === 'https' ? 'HTTPS' : 'HTTP'
          Severity: Major
          Found in src/census/plugins/http.ts - About 2 hrs to fix

            Function outgoingRequest has 52 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  return function outgoingRequest (
                             options: httpModule.RequestOptions | string,
                             callback): httpModule.ClientRequest {
                    if (!options) {
                      return original.apply(this, arguments)
            Severity: Major
            Found in src/census/plugins/http.ts - About 2 hrs to fix

              Function end has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Wontfix

                        response.end = function (this: httpModule.ServerResponse) {
                          response.end = originalEnd
                          const returned = response.end.apply(this, arguments)
              
                          const requestUrl = url.parse(request.url || 'localhost')
              Severity: Minor
              Found in src/census/plugins/http.ts - About 1 hr to fix

                Function convertTraceStatus has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  static convertTraceStatus (statusCode: number): number {
                    if (statusCode < 200 || statusCode > 504) {
                      return TraceStatusCodes.UNKNOWN
                    } else if (statusCode >= 200 && statusCode < 400) {
                      return TraceStatusCodes.OK
                Severity: Minor
                Found in src/census/plugins/http.ts - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if (typeof (options) === 'string') {
                            const parsedUrl = url.parse(options)
                            options = parsedUrl
                            pathname = parsedUrl.pathname || '/'
                            origin = `${parsedUrl.protocol || 'http:'}//${parsedUrl.host}`
                  Severity: Major
                  Found in src/census/plugins/http.ts - About 40 mins to fix

                    Avoid too many return statements within this function.
                    Open

                              return plugin.tracer.startRootSpan(
                                  traceOptions,
                                  plugin.getMakeRequestTraceFunction(request, options, plugin))
                    Severity: Major
                    Found in src/census/plugins/http.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
                                    span)
                      Severity: Major
                      Found in src/census/plugins/http.ts - About 30 mins to fix

                        Function convertTraceStatus has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          static convertTraceStatus (statusCode: number): number {
                            if (statusCode < 200 || statusCode > 504) {
                              return TraceStatusCodes.UNKNOWN
                            } else if (statusCode >= 200 && statusCode < 400) {
                              return TraceStatusCodes.OK
                        Severity: Minor
                        Found in src/census/plugins/http.ts - About 25 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        There are no issues that match your filters.

                        Category
                        Status