src/core/io/socket.ts

Summary

Maintainability
D
1 day
Test Coverage

File socket.ts has 299 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import net from "net";
import { TextEncoder } from "util";

import {
  IBApiCreationOptions,
Severity: Minor
Found in src/core/io/socket.ts - About 3 hrs to fix

    Socket has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Socket {
      /**
       * Create a new [[Socket]] object.
       *
       * @param controller The parent [[Controller]] object.
    Severity: Minor
    Found in src/core/io/socket.ts - About 2 hrs to fix

      Function onData has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        private onData(data: Buffer): void {
          if (this.useV100Plus) {
            let dataToParse = data;
            if (this._v100MessageBuffer.length > 0) {
              dataToParse = Buffer.concat([this._v100MessageBuffer, data]);
      Severity: Minor
      Found in src/core/io/socket.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 onData has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private onData(data: Buffer): void {
          if (this.useV100Plus) {
            let dataToParse = data;
            if (this._v100MessageBuffer.length > 0) {
              dataToParse = Buffer.concat([this._v100MessageBuffer, data]);
      Severity: Minor
      Found in src/core/io/socket.ts - About 1 hr to fix

        Function onServerVersion has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private onServerVersion(tokens: string[]): void {
            this._status = ConnectionStatus.Connected;
        
            this._serverVersion = parseInt(tokens[0], 10);
            this._serverConnectionTime = tokens[1];
        Severity: Minor
        Found in src/core/io/socket.ts - About 1 hr to fix

          Function send has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            send(tokens: unknown[]): void {
              // flatten arrays and convert boolean types to 0/1
          
              tokens = this.flattenDeep(tokens);
              tokens.forEach((value, i) => {
          Severity: Minor
          Found in src/core/io/socket.ts - About 1 hr to fix

            Function onMessage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              private onMessage(data: string): void {
                // tokenize
            
                const dataWithFragment = this.dataFragment + data;
            
            
            Severity: Minor
            Found in src/core/io/socket.ts - About 45 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

            Function startAPI has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              private startAPI(): void {
                // start API
            
                const VERSION = 2;
                if (this.serverVersion >= 3) {
            Severity: Minor
            Found in src/core/io/socket.ts - About 45 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

            Function send has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              send(tokens: unknown[]): void {
                // flatten arrays and convert boolean types to 0/1
            
                tokens = this.flattenDeep(tokens);
                tokens.forEach((value, i) => {
            Severity: Minor
            Found in src/core/io/socket.ts - About 35 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