keymetrics/pm2-io-apm

View on GitHub
src/utils/transactionAggregator.ts

Summary

Maintainability
D
2 days
Test Coverage

File transactionAggregator.ts has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'

import * as Debug from 'debug'
import { EventEmitter2 } from 'eventemitter2'
import EWMA from './EWMA'
Severity: Minor
Found in src/utils/transactionAggregator.ts - About 4 hrs to fix

    Function matchPath has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

      matchPath (path, routes) {
        // empty route is / without the fist slash
        if (!path || !routes) return false
        if (path === '/') return routes[path] ? path : null
    
    
    Severity: Minor
    Found in src/utils/transactionAggregator.ts - About 3 hrs 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

    Function prepareAggregationforShipping has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      prepareAggregationforShipping () {
        let routes = this.cache.routes
    
        const normalized: Trace = {
          routes: [],
    Severity: Major
    Found in src/utils/transactionAggregator.ts - About 2 hrs to fix

      Function aggregate has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        aggregate (packet) {
          if (this.validateData(packet) === false) return false
      
          // Get http path of current span
          let path = packet.spans[0].labels['http/path']
      Severity: Minor
      Found in src/utils/transactionAggregator.ts - About 1 hr to fix

        Function compareList has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          compareList (one: any[], two: any[]) {
            if (one.length !== two.length) return false
        
            for (let i = 0; i < one.length; i++) {
              if (one[i].name !== two[i].name) return false
        Severity: Minor
        Found in src/utils/transactionAggregator.ts - About 1 hr 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

        Function mergeTrace has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          mergeTrace (aggregated, trace) {
            if (!aggregated || !trace) return
        
            // if the trace doesn't any spans stop aggregation here
            if (trace.spans.length === 0) return
        Severity: Minor
        Found in src/utils/transactionAggregator.ts - About 1 hr to fix

          Function mergeTrace has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            mergeTrace (aggregated, trace) {
              if (!aggregated || !trace) return
          
              // if the trace doesn't any spans stop aggregation here
              if (trace.spans.length === 0) return
          Severity: Minor
          Found in src/utils/transactionAggregator.ts - About 1 hr 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

          Function matchPath has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            matchPath (path, routes) {
              // empty route is / without the fist slash
              if (!path || !routes) return false
              if (path === '/') return routes[path] ? path : null
          
          
          Severity: Minor
          Found in src/utils/transactionAggregator.ts - About 1 hr to fix

            Avoid too many return statements within this function.
            Open

                  if (one[i].labels.length !== two[i].labels.length) return false
            Severity: Major
            Found in src/utils/transactionAggregator.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return false
              Severity: Major
              Found in src/utils/transactionAggregator.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return segments.join('/')
                Severity: Major
                Found in src/utils/transactionAggregator.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return true
                  Severity: Major
                  Found in src/utils/transactionAggregator.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          if (one[i].labels && !two[i].labels) return false
                    Severity: Major
                    Found in src/utils/transactionAggregator.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              if (j === 0) return segments.join('/')
                      Severity: Major
                      Found in src/utils/transactionAggregator.ts - About 30 mins to fix

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

                          aggregate (packet) {
                            if (this.validateData(packet) === false) return false
                        
                            // Get http path of current span
                            let path = packet.spans[0].labels['http/path']
                        Severity: Minor
                        Found in src/utils/transactionAggregator.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