pristineio/wsd

View on GitHub
lib/WebSocket.js

Summary

Maintainability
F
6 days
Test Coverage

File WebSocket.js has 577 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
//
// wsd
// Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
// MIT Licensed
Severity: Major
Found in lib/WebSocket.js - About 1 day to fix

    Function initAsClient has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

    function initAsClient(self, address, protocols, opts) {
      var options = {
        protocolVersion: protocolVersion,
        perMessageDeflate: true
      };
    Severity: Minor
    Found in lib/WebSocket.js - About 6 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 initAsClient has 163 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function initAsClient(self, address, protocols, opts) {
      var options = {
        protocolVersion: protocolVersion,
        perMessageDeflate: true
      };
    Severity: Major
    Found in lib/WebSocket.js - About 6 hrs to fix

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

      function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
        var upgradeHead = u;
        var called = false;
      
        socket.setTimeout(0);
      Severity: Major
      Found in lib/WebSocket.js - About 2 hrs to fix

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

        WebSocket.prototype.send = function send(data, options, cb) {
          var self = this;
          if(typeof options === 'function') {
            cb = options;
            options = {};
        Severity: Major
        Found in lib/WebSocket.js - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

            if(!options.binary) {
              options.binary = (
                data instanceof ArrayBuffer ||
                data instanceof Buffer ||
                data instanceof Uint8Array ||
          Severity: Critical
          Found in lib/WebSocket.js - About 2 hrs to fix

            Function upgrade has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              req.once('upgrade', function upgrade(res, socket, upgradeHead) {
                if(self.readyState === WebSocket.CLOSED) {
                  self.emit('close');
                  self.removeAllListeners();
                  return socket.end();
            Severity: Minor
            Found in lib/WebSocket.js - About 1 hr to fix

              Function sendStream has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

              function sendStream(instance, stream, options, cb) {
                stream.on('data', function incoming(data) {
                  if(instance.readyState !== WebSocket.OPEN) {
                    if(typeof cb === 'function') {
                      cb(new Error('not opened'));
              Severity: Minor
              Found in lib/WebSocket.js - 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 stream has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              WebSocket.prototype.stream = function stream(options, cb) {
                if(typeof options === 'function') {
                  cb = options;
                  options = {};
                }
              Severity: Minor
              Found in lib/WebSocket.js - 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 send has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              WebSocket.prototype.send = function send(data, options, cb) {
                var self = this;
                if(typeof options === 'function') {
                  cb = options;
                  options = {};
              Severity: Minor
              Found in lib/WebSocket.js - 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 stream has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              WebSocket.prototype.stream = function stream(options, cb) {
                if(typeof options === 'function') {
                  cb = options;
                  options = {};
                }
              Severity: Minor
              Found in lib/WebSocket.js - About 1 hr to fix

                Function cleanupWebsocketResources has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function cleanupWebsocketResources(self, error) {
                  if(self.readyState === WebSocket.CLOSED) {
                    return;
                  }
                
                
                Severity: Minor
                Found in lib/WebSocket.js - About 1 hr to fix

                  Function cleanupWebsocketResources has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function cleanupWebsocketResources(self, error) {
                    if(self.readyState === WebSocket.CLOSED) {
                      return;
                    }
                  
                  
                  Severity: Minor
                  Found in lib/WebSocket.js - 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 close has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  WebSocket.prototype.close = function(code, data) {
                    switch(this.readyState) {
                      case WebSocket.CLOSED:
                        return;
                      case WebSocket.CONNECTING:
                  Severity: Minor
                  Found in lib/WebSocket.js - About 1 hr to fix

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

                    function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
                      var upgradeHead = u;
                      var called = false;
                    
                      socket.setTimeout(0);
                    Severity: Minor
                    Found in lib/WebSocket.js - 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 sendStream has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function sendStream(instance, stream, options, cb) {
                      stream.on('data', function incoming(data) {
                        if(instance.readyState !== WebSocket.OPEN) {
                          if(typeof cb === 'function') {
                            cb(new Error('not opened'));
                    Severity: Minor
                    Found in lib/WebSocket.js - About 1 hr to fix

                      Function initAsServerClient has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      function initAsServerClient(self, req, socket, upgradeHead, opts) {
                      Severity: Minor
                      Found in lib/WebSocket.js - About 35 mins to fix

                        Function establishConnection has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
                        Severity: Minor
                        Found in lib/WebSocket.js - About 35 mins to fix

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

                          function WebSocket(address, protocols, options) {
                            if('string' === typeof protocols) {
                              protocols = [protocols];
                            } else if(!Array.isArray(protocols)) {
                              if(typeof protocols === 'object') {
                          Severity: Minor
                          Found in lib/WebSocket.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

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

                          function buildHostHeader(isSecure, hostname, port) {
                            var headerHost = hostname;
                            if(hostname) {
                              if((isSecure && port !== 443) || (!isSecure && port !== 80)) {
                                headerHost = headerHost + ':' + port;
                          Severity: Minor
                          Found in lib/WebSocket.js - 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

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                              if(instance.readyState !== WebSocket.OPEN) {
                                if(typeof cb === 'function') {
                                  cb(new Error('not opened'));
                                } else {
                                  delete instance.queue;
                          Severity: Major
                          Found in lib/WebSocket.js and 1 other location - About 1 hr to fix
                          lib/WebSocket.js on lines 621..629

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 73.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                              if(instance.readyState !== WebSocket.OPEN) {
                                if(typeof cb === 'function') {
                                  cb(new Error('not opened'));
                                } else {
                                  delete instance.queue;
                          Severity: Major
                          Found in lib/WebSocket.js and 1 other location - About 1 hr to fix
                          lib/WebSocket.js on lines 635..643

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 73.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                          Object.defineProperty(WebSocket.prototype, 'bufferedAmount', {
                            get: function get() {
                              return !this.socket ? 0 : this.socket.bufferSize;
                            }
                          });
                          Severity: Minor
                          Found in lib/WebSocket.js and 1 other location - About 55 mins to fix
                          lib/BufferPool.js on lines 26..30

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 53.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                            if(opts) {
                              Object.keys(opts).forEach(function(k) {
                                options[k] = opts[k];
                              });
                            }
                          Severity: Minor
                          Found in lib/WebSocket.js and 1 other location - About 35 mins to fix
                          lib/WebSocket.js on lines 290..294

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 47.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                            if(opts) {
                              Object.keys(opts).forEach(function(k) {
                                options[k] = opts[k];
                              });
                            }
                          Severity: Minor
                          Found in lib/WebSocket.js and 1 other location - About 35 mins to fix
                          lib/WebSocket.js on lines 314..318

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 47.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          There are no issues that match your filters.

                          Category
                          Status