pristineio/wsd

View on GitHub
lib/WebSocketServer.js

Summary

Maintainability
D
3 days
Test Coverage

Function handleUpgrade has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

WebSocketServer.prototype.handleUpgrade = function(req, socket, u, cb) {
  var upgradeHead = u;
  if(this.options.path) {
    u = url.parse(req.url);
    if(u && u.pathname !== this.options.path) {
Severity: Minor
Found in lib/WebSocketServer.js - About 7 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 handleUpgrade has 152 lines of code (exceeds 25 allowed). Consider refactoring.
Open

WebSocketServer.prototype.handleUpgrade = function(req, socket, u, cb) {
  var upgradeHead = u;
  if(this.options.path) {
    u = url.parse(req.url);
    if(u && u.pathname !== this.options.path) {
Severity: Major
Found in lib/WebSocketServer.js - About 6 hrs to fix

    Function completeHybiUpgrade2 has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      var completeHybiUpgrade2 = function(protocol) {
        var originalKey = req.headers['sec-websocket-key'];
        var clientKey = originalKey;
        var key = crypto.createHash('sha1')
          .update(originalKey + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')
    Severity: Major
    Found in lib/WebSocketServer.js - About 2 hrs to fix

      File WebSocketServer.js has 269 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

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

        Function WebSocketServer has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        function WebSocketServer(options, callback) {
          options.perMessageDeflate = true;
        
          if(!('port' in options) && !('server' in options) && !options.noServer) {
            throw new TypeError('`port` or a `server` must be provided');
        Severity: Minor
        Found in lib/WebSocketServer.js - About 2 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 WebSocketServer has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function WebSocketServer(options, callback) {
          options.perMessageDeflate = true;
        
          if(!('port' in options) && !('server' in options) && !options.noServer) {
            throw new TypeError('`port` or a `server` must be provided');
        Severity: Major
        Found in lib/WebSocketServer.js - About 2 hrs to fix

          Avoid too many return statements within this function.
          Open

                return abortConnection(socket, 401);
          Severity: Major
          Found in lib/WebSocketServer.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return this.options.verifyClient(info, function(result, code) {
                    if(!code) {
                      code = 401;
                    }
                    if(!result) {
            Severity: Major
            Found in lib/WebSocketServer.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status