lib/net.js

Summary

Maintainability
F
1 wk
Test Coverage

File net.js has 1029 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
Severity: Major
Found in lib/net.js - About 2 days to fix

    Function listen has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    Server.prototype.listen = function() {
      var self = this;
    
      var lastArg = arguments[arguments.length - 1];
      if (util.isFunction(lastArg)) {
    Severity: Minor
    Found in lib/net.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 connect has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    Socket.prototype.connect = function(options, cb) {
      if (this.write !== Socket.prototype.write)
        this.write = Socket.prototype.write;
    
      if (!util.isObject(options)) {
    Severity: Minor
    Found in lib/net.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 connect has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Socket.prototype.connect = function(options, cb) {
      if (this.write !== Socket.prototype.write)
        this.write = Socket.prototype.write;
    
      if (!util.isObject(options)) {
    Severity: Major
    Found in lib/net.js - About 3 hrs to fix

      Function _createServerHandle has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          function(address, port, addressType, fd) {
        var err = 0;
        // assign handle in listen, and clean up if bind or listen fails
        var handle;
      
      
      Severity: Minor
      Found in lib/net.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 Socket has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function Socket(options) {
        if (!(this instanceof Socket)) return new Socket(options);
      
        this._connecting = false;
        this._hadError = false;
      Severity: Minor
      Found in lib/net.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 listen has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Server.prototype.listen = function() {
        var self = this;
      
        var lastArg = arguments[arguments.length - 1];
        if (util.isFunction(lastArg)) {
      Severity: Major
      Found in lib/net.js - About 2 hrs to fix

        Function _writeGeneric has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
          // If we are still connecting, then buffer this for later.
          // The Writable logic will buffer up any more writes while
          // waiting for this one to be done.
          if (this._connecting) {
        Severity: Minor
        Found in lib/net.js - About 1 hr to fix

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

              function(address, port, addressType, fd) {
            var err = 0;
            // assign handle in listen, and clean up if bind or listen fails
            var handle;
          
          
          Severity: Minor
          Found in lib/net.js - About 1 hr to fix

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

            Socket.prototype._destroy = function(exception, cb) {
              debug('destroy');
            
              var self = this;
            
            
            Severity: Minor
            Found in lib/net.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 Socket has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function Socket(options) {
              if (!(this instanceof Socket)) return new Socket(options);
            
              this._connecting = false;
              this._hadError = false;
            Severity: Minor
            Found in lib/net.js - About 1 hr to fix

              Function _destroy has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Socket.prototype._destroy = function(exception, cb) {
                debug('destroy');
              
                var self = this;
              
              
              Severity: Minor
              Found in lib/net.js - About 1 hr to fix

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

                Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
                  // If we are still connecting, then buffer this for later.
                  // The Writable logic will buffer up any more writes while
                  // waiting for this one to be done.
                  if (this._connecting) {
                Severity: Minor
                Found in lib/net.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 connect has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                function connect(self, address, port, addressType, localAddress, localPort) {
                  // TODO return promise from Socket.prototype.connect which
                  // wraps _connectReq.
                
                  assert.ok(self._connecting);
                Severity: Minor
                Found in lib/net.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 connect has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function connect(self, address, port, addressType, localAddress, localPort) {
                  // TODO return promise from Socket.prototype.connect which
                  // wraps _connectReq.
                
                  assert.ok(self._connecting);
                Severity: Minor
                Found in lib/net.js - About 1 hr to fix

                  Function _listen2 has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
                    debug('listen2', address, port, addressType, backlog);
                    var self = this;
                  
                    // If there is not yet a handle, we need to create one and bind.
                  Severity: Minor
                  Found in lib/net.js - About 1 hr to fix

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

                    function onread(nread, buffer) {
                      var handle = this;
                      var self = handle.owner;
                      assert(handle === self._handle, 'handle != self._handle');
                    
                    
                    Severity: Minor
                    Found in lib/net.js - About 1 hr to fix

                      Function Server has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function Server(options, connectionListener) {
                        if (!(this instanceof Server))
                          return new Server(options, connectionListener);
                      
                        events.EventEmitter.call(this);
                      Severity: Minor
                      Found in lib/net.js - About 1 hr to fix

                        Function close has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        Server.prototype.close = function(cb) {
                          function onSlaveClose() {
                            if (--left !== 0) return;
                        
                            self._connections = 0;
                        Severity: Minor
                        Found in lib/net.js - About 1 hr to fix

                          Function listen has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function listen(self, address, port, addressType, backlog, fd, exclusive) {
                            exclusive = !!exclusive;
                          
                            if (!cluster) cluster = require('cluster');
                          
                          
                          Severity: Minor
                          Found in lib/net.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 onread has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function onread(nread, buffer) {
                            var handle = this;
                            var self = handle.owner;
                            assert(handle === self._handle, 'handle != self._handle');
                          
                          
                          Severity: Minor
                          Found in lib/net.js - About 55 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 close has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                          Server.prototype.close = function(cb) {
                            function onSlaveClose() {
                              if (--left !== 0) return;
                          
                              self._connections = 0;
                          Severity: Minor
                          Found in lib/net.js - About 55 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 listen has 7 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          function listen(self, address, port, addressType, backlog, fd, exclusive) {
                          Severity: Major
                          Found in lib/net.js - About 50 mins to fix

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

                            function Server(options, connectionListener) {
                              if (!(this instanceof Server))
                                return new Server(options, connectionListener);
                            
                              events.EventEmitter.call(this);
                            Severity: Minor
                            Found in lib/net.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

                            Function connect has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            function connect(self, address, port, addressType, localAddress, localPort) {
                            Severity: Minor
                            Found in lib/net.js - About 45 mins to fix

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

                              Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
                              Severity: Minor
                              Found in lib/net.js - About 35 mins to fix

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

                                function afterConnect(status, handle, req, readable, writable) {
                                Severity: Minor
                                Found in lib/net.js - About 35 mins to fix

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

                                    exports._setSimultaneousAccepts = function(handle) {
                                      if (util.isUndefined(handle)) {
                                        return;
                                      }
                                  
                                  
                                  Severity: Minor
                                  Found in lib/net.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

                                        return 'closed';
                                  Severity: Major
                                  Found in lib/net.js - About 30 mins to fix

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

                                    Socket.prototype._getpeername = function() {
                                      if (!this._peername) {
                                        if (!this._handle || !this._handle.getpeername) {
                                          return {};
                                        }
                                    Severity: Minor
                                    Found in lib/net.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

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

                                    Socket.prototype.setTimeout = function(msecs, callback) {
                                      if (msecs === 0) {
                                        timers.unenroll(this);
                                        if (callback) {
                                          this.removeListener('timeout', callback);
                                    Severity: Minor
                                    Found in lib/net.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

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

                                    function normalizeConnectArgs(args) {
                                      var options = {};
                                    
                                      if (util.isObject(args[0])) {
                                        // connect(options, [cb])
                                    Severity: Minor
                                    Found in lib/net.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

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

                                    Object.defineProperty(Socket.prototype, 'readyState', {
                                      get: function() {
                                        if (this._connecting) {
                                          return 'opening';
                                        } else if (this.readable && this.writable) {
                                    Severity: Major
                                    Found in lib/net.js and 1 other location - About 4 hrs to fix
                                    lib/_tls_legacy.js on lines 508..522

                                    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 121.

                                    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