fh1ch/node-bacstack

View on GitHub
lib/client.js

Summary

Maintainability
F
1 wk
Test Coverage

File client.js has 798 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

// Util Modules
const EventEmitter = require('events').EventEmitter;
const debug = require('debug')('bacstack');
Severity: Major
Found in lib/client.js - About 1 day to fix

    Function _processConfirmedServiceRequest has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
    Open

      _processConfirmedServiceRequest(address, type, service, maxSegments, maxApdu, invokeId, buffer, offset, length) {
        let result;
        debug('Handle this._processConfirmedServiceRequest');
        if (service === baEnum.ConfirmedServiceChoice.READ_PROPERTY) {
          result = baServices.readProperty.decode(buffer, offset, length);
    Severity: Minor
    Found in lib/client.js - About 1 day 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

    Client has 49 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Client extends EventEmitter {
      constructor(options) {
        super();
    
        options = options || {};
    Severity: Minor
    Found in lib/client.js - About 6 hrs to fix

      Function _processUnconfirmedServiceRequest has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

        _processUnconfirmedServiceRequest(address, type, service, buffer, offset, length) {
          let result;
          debug('Handle this._processUnconfirmedServiceRequest');
          if (service === baEnum.UnconfirmedServiceChoice.I_AM) {
            result = baServices.iAmBroadcast.decode(buffer, offset);
      Severity: Minor
      Found in lib/client.js - About 4 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 _processConfirmedServiceRequest has 95 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _processConfirmedServiceRequest(address, type, service, maxSegments, maxApdu, invokeId, buffer, offset, length) {
          let result;
          debug('Handle this._processConfirmedServiceRequest');
          if (service === baEnum.ConfirmedServiceChoice.READ_PROPERTY) {
            result = baServices.readProperty.decode(buffer, offset, length);
      Severity: Major
      Found in lib/client.js - About 3 hrs to fix

        Function _handlePdu has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _handlePdu(address, type, buffer, offset, length) {
            let result;
            // Handle different PDU types
            switch (type & baEnum.PDU_TYPE_MASK) {
              case baEnum.PduTypes.UNCONFIRMED_REQUEST:
        Severity: Minor
        Found in lib/client.js - About 1 hr to fix

          Function _processUnconfirmedServiceRequest has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _processUnconfirmedServiceRequest(address, type, service, buffer, offset, length) {
              let result;
              debug('Handle this._processUnconfirmedServiceRequest');
              if (service === baEnum.UnconfirmedServiceChoice.I_AM) {
                result = baServices.iAmBroadcast.decode(buffer, offset);
          Severity: Minor
          Found in lib/client.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                  if (!result) return debug('Received invalid writePropertyMultiple message');
            Severity: Major
            Found in lib/client.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                  } else if (service === baEnum.ConfirmedServiceChoice.CONFIRMED_COV_NOTIFICATION) {
                    result = baServices.covNotify.decode(buffer, offset, length);
                    if (!result) return debug('Received invalid covNotify message');
                    this.emit('covNotify', {address: address, invokeId: invokeId, request: result});
                  } else if (service === baEnum.ConfirmedServiceChoice.ATOMIC_WRITE_FILE) {
              Severity: Major
              Found in lib/client.js - About 45 mins to fix

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

                  _performDefaultSegmentHandling(sender, adr, type, service, invokeId, maxSegments, maxApdu, sequencenumber, first, moreFollows, buffer, offset, length) {
                    if (first) {
                      this._segmentStore = [];
                      type &= ~baEnum.PduConReqBits.SEGMENTED_MESSAGE;
                      let apduHeaderLen = 3;
                Severity: Minor
                Found in lib/client.js - 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

                Avoid deeply nested control flow statements.
                Open

                    } else if (service === baEnum.UnconfirmedServiceChoice.TIME_SYNCHRONIZATION) {
                      result = baServices.timeSync.decode(buffer, offset, length);
                      if (!result) return debug('Received invalid TimeSync message');
                
                      /**
                Severity: Major
                Found in lib/client.js - About 45 mins to fix

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

                    _processSegment(receiver, type, service, invokeId, maxSegments, maxApdu, server, sequencenumber, proposedWindowNumber, buffer, offset, length) {
                      let first = false;
                      if (sequencenumber === 0 && this._lastSequenceNumber === 0) {
                        first = true;
                      } else {
                  Severity: Minor
                  Found in lib/client.js - 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

                  Avoid deeply nested control flow statements.
                  Open

                        if (!result) return debug('Received invalid covNotifyUnconfirmed message');
                  Severity: Major
                  Found in lib/client.js - About 45 mins to fix

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

                      _handlePdu(address, type, buffer, offset, length) {
                        let result;
                        // Handle different PDU types
                        switch (type & baEnum.PDU_TYPE_MASK) {
                          case baEnum.PduTypes.UNCONFIRMED_REQUEST:
                    Severity: Minor
                    Found in lib/client.js - 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

                    Avoid too many return statements within this function.
                    Open

                          if (!result) return debug('Received invalid subscribeProperty message');
                    Severity: Major
                    Found in lib/client.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            if (!result) return debug('Received invalid eventNotifyData message');
                      Severity: Major
                      Found in lib/client.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              if (!result) return debug('Received invalid removeListElement message');
                        Severity: Major
                        Found in lib/client.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                if (!result) return debug('Received invalid TimeSync message');
                          Severity: Major
                          Found in lib/client.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  if (!result) return debug('Received invalid ihaveBroadcast message');
                            Severity: Major
                            Found in lib/client.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    if (!result) return debug('Received invalid deleteObject message');
                              Severity: Major
                              Found in lib/client.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      if (!result) return debug('Received invalid covNotify message');
                                Severity: Major
                                Found in lib/client.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        if (!result) return debug('Received invalid createObject message');
                                  Severity: Major
                                  Found in lib/client.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          if (!result) return debug('Received invalid alarmAcknowledge message');
                                    Severity: Major
                                    Found in lib/client.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            if (!result) return debug('Received invalid TimeSyncUTC message');
                                      Severity: Major
                                      Found in lib/client.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              if (!result) return debug('Received invalid privateTransfer message');
                                        Severity: Major
                                        Found in lib/client.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                if (!result) return debug('Received invalid reinitializeDevice message');
                                          Severity: Major
                                          Found in lib/client.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                  if (!result) return debug('Received invalid EventNotify message');
                                            Severity: Major
                                            Found in lib/client.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                    if (!result) return debug('Received invalid lifeSafetyOperation message');
                                              Severity: Major
                                              Found in lib/client.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                      if (!result) return debug('Received invalid subscribeCOV message');
                                                Severity: Major
                                                Found in lib/client.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                        if (!result) return debug('Received invalid deviceCommunicationControl message');
                                                  Severity: Major
                                                  Found in lib/client.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                          if (!result) return debug('Received invalid getEventInformation message');
                                                    Severity: Major
                                                    Found in lib/client.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                            if (!result) return debug('Received invalid readRange message');
                                                      Severity: Major
                                                      Found in lib/client.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                              if (!result) return debug('Received invalid atomicWriteFile message');
                                                        Severity: Major
                                                        Found in lib/client.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                if (!result) return debug('Received invalid atomicReadFile message');
                                                          Severity: Major
                                                          Found in lib/client.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                  if (!result) return debug('Received invalid getEntrollmentSummary message');
                                                            Severity: Major
                                                            Found in lib/client.js - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                    if (!result) return debug('Received invalid privateTransfer message');
                                                              Severity: Major
                                                              Found in lib/client.js - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                      if (!result) return debug('Received invalid addListElement message');
                                                                Severity: Major
                                                                Found in lib/client.js - About 30 mins to fix

                                                                  Parsing error: Invalid ecmaVersion.
                                                                  Open

                                                                  'use strict';
                                                                  Severity: Minor
                                                                  Found in lib/client.js by eslint

                                                                  For more information visit Source: http://eslint.org/docs/rules/

                                                                  There are no issues that match your filters.

                                                                  Category
                                                                  Status