RocketChat/Rocket.Chat

View on GitHub
packages/node-poplib/src/index.js

Summary

Maintainability
F
6 days
Test Coverage

File index.js has 553 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*

    Node.js POP3 client library

    Copyright (C) 2011-2013 by Ditesh Shashikant Gathani <ditesh@gathani.org>
Severity: Major
Found in packages/node-poplib/src/index.js - About 1 day to fix

    Function POP3Client has 186 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function POP3Client(port, host, options) {
        if (options === undefined) options = {};
    
        // Optional constructor arguments
        var enabletls = options.enabletls !== undefined ? options.enabletls : false;
    Severity: Major
    Found in packages/node-poplib/src/index.js - About 7 hrs to fix

      Function POP3Client has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

      function POP3Client(port, host, options) {
          if (options === undefined) options = {};
      
          // Optional constructor arguments
          var enabletls = options.enabletls !== undefined ? options.enabletls : false;
      Severity: Minor
      Found in packages/node-poplib/src/index.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 auth has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      POP3Client.prototype.auth = function (type, username, password) {
          type = type.toUpperCase();
          var self = this;
          var types = { 'PLAIN': 1, 'CRAM-MD5': 1 };
          var initialresp = '';
      Severity: Minor
      Found in packages/node-poplib/src/index.js - About 1 hr to fix

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

        POP3Client.prototype.list = function (msgnumber) {
            var self = this;
        
            if (self.getState() !== 2) self.emit('invalid-state', 'list');
            else if (self.getLocked() === true) self.emit('locked', 'list');
        Severity: Minor
        Found in packages/node-poplib/src/index.js - About 1 hr to fix

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

              this.starttls = function (options) {
                  var s = socket;
                  s.removeAllListeners('end');
                  s.removeAllListeners('data');
                  s.removeAllListeners('error');
          Severity: Minor
          Found in packages/node-poplib/src/index.js - About 1 hr to fix

            Function uidl has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            POP3Client.prototype.uidl = function (msgnumber) {
                var self = this;
            
                if (self.getState() !== 2) self.emit('invalid-state', 'uidl');
                else if (self.getLocked() === true) self.emit('locked', 'uidl');
            Severity: Minor
            Found in packages/node-poplib/src/index.js - About 1 hr to fix

              Function onData has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function onData(data) {
                      data = data.toString('ascii');
                      bufferedData += data;
              
                      if (debug) console.log('Server: ' + util.inspect(data));
              Severity: Minor
              Found in packages/node-poplib/src/index.js - About 1 hr to fix

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

                POP3Client.prototype.auth = function (type, username, password) {
                    type = type.toUpperCase();
                    var self = this;
                    var types = { 'PLAIN': 1, 'CRAM-MD5': 1 };
                    var initialresp = '';
                Severity: Minor
                Found in packages/node-poplib/src/index.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

                                        while (true) {
                                            if (offset > endOffset) break;
                
                                            newoffset = data.indexOf('\r\n', offset);
                
                
                Severity: Major
                Found in packages/node-poplib/src/index.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          while (offset < endOffset) {
                                              newoffset = data.indexOf('\r\n', offset);
                                              listitem = data.substr(offset, newoffset - offset);
                                              listitem = listitem.split(' ');
                                              returnValue[listitem[0]] = listitem[1];
                  Severity: Major
                  Found in packages/node-poplib/src/index.js - About 45 mins to fix

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

                    POP3Client.prototype.rset = function () {
                        var self = this;
                    
                        if (self.getState() !== 2) self.emit('invalid-state', 'rset');
                        else if (self.getLocked() === true) self.emit('locked', 'rset');
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 7 hrs to fix
                    packages/node-poplib/src/index.js on lines 647..663

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

                    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

                    POP3Client.prototype.noop = function () {
                        var self = this;
                    
                        if (self.getState() !== 2) self.emit('invalid-state', 'noop');
                        else if (self.getLocked() === true) self.emit('locked', 'noop');
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 7 hrs to fix
                    packages/node-poplib/src/index.js on lines 665..681

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

                    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

                                    self.setCallback(function (resp, data) {
                                        self.setLocked(false);
                                        self.setCallback(function () {});
                    
                                        if (resp !== false) self.setState(2);
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 2 hrs to fix
                    packages/node-poplib/src/index.js on lines 389..395

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

                    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

                            self.setCallback(function (resp, data) {
                                self.setLocked(false);
                                self.setCallback(function () {});
                    
                                if (resp === true) self.setState(2);
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 2 hrs to fix
                    packages/node-poplib/src/index.js on lines 298..304

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

                    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

                                } else if (multiline === false) {
                                    // Make a copy to avoid race conditions
                                    var responseCopy = response;
                                    var bufferedDataCopy = bufferedData;
                    
                    
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 1 hr to fix
                    packages/node-poplib/src/index.js on lines 216..238

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

                    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 (multiline === true && (response === false || bufferedData.substr(bufferedData.length - 5) === '\r\n.\r\n')) {
                                    // Make a copy to avoid race conditions
                                    var responseCopy = response;
                                    var bufferedDataCopy = bufferedData;
                    
                    
                    Severity: Major
                    Found in packages/node-poplib/src/index.js and 1 other location - About 1 hr to fix
                    packages/node-poplib/src/index.js on lines 227..238

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

                    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