enricostara/telegram-mt-node

View on GitHub

Showing 37 of 37 total issues

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

PQFinder.prototype.findPQ = function () {
    if (!this._pq) {
        var num = this._pqNumber;
        var prime;
        for (var i = 0; i < 3; i++) {
Severity: Minor
Found in lib/security/pq-finder.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

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

                } else if (setClientDHParamsAnswer.instanceOf('mtproto.type.Dh_gen_retry')) {
                    logger.warn('\'Dh_gen_retry\' received from Telegram!');
                    callback(createError(JSON.stringify(setClientDHParamsAnswer), 'EDHPARAMRETRY'));
                } else if (setClientDHParamsAnswer.instanceOf('mtproto.type.Dh_gen_fail')) {
                    logger.warn('\'Dh_gen_fail\' received from Telegram!');
Severity: Major
Found in lib/auth/set-client-dh-params.js and 1 other location - About 2 hrs to fix
lib/auth/request-dh-params.js on lines 84..98

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

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

                if (serverDHParams.instanceOf('mtproto.type.Server_DH_params_ok')) {
                    if (logger.isDebugEnabled()) {
                        logger.debug('\'Server_DH_params_ok\' received from Telegram.');
                    }
                    context.serverDHParams = serverDHParams;
Severity: Major
Found in lib/auth/request-dh-params.js and 1 other location - About 2 hrs to fix
lib/auth/set-client-dh-params.js on lines 103..113

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

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

Function setClientDHParams has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

function setClientDHParams(callback, context) {
    mtproto.service.set_client_DH_params({
        props: {
            nonce: context.resPQ.nonce,
            server_nonce: context.resPQ.server_nonce,
Severity: Minor
Found in lib/auth/set-client-dh-params.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 parse has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

MessageParser.prototype.parse = function (message, duration) {
    if(!message || !message.getTypeName) {
        logger.error('Message undefined or unknown', message);
        return;
    }
Severity: Minor
Found in lib/message/message-parser.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 requestDHParams has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

function requestDHParams(callback, context) {
    var resPQ = context.resPQ;
    mtproto.service.req_DH_params({
        props: {
            nonce: resPQ.nonce,
Severity: Minor
Found in lib/auth/request-dh-params.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 callMethod has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

EncryptedRpcChannel.prototype.callMethod = function (method, callback) {
    if (!this._open) {
        callback(new Error('Channel is closed'));
        return;
    }
Severity: Minor
Found in lib/net/encrypted-rpc-channel.js - About 1 hr to fix

    Function findPQ has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    PQFinder.prototype.findPQ = function () {
        if (!this._pq) {
            var num = this._pqNumber;
            var prime;
            for (var i = 0; i < 3; i++) {
    Severity: Minor
    Found in lib/security/pq-finder.js - About 1 hr to fix

      Function read has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      TcpConnection.prototype.read = function (callback) {
          var self = this;
          var buffers = [];
          var timer;
          if (logger.isDebugEnabled()) {
      Severity: Minor
      Found in lib/net/tcp-connection.js - About 1 hr to fix

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

        RpcChannel.prototype._executeCall = function (reqMsg, callback) {
            var conn = this._connection;
            var start = new Date().getTime();
            var self = this;
            conn.write(reqMsg.serialize(), function (ex) {
        Severity: Minor
        Found in lib/net/rpc-channel.js - About 1 hr to fix

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

          TcpConnection.prototype.connect = function (callback) {
              var self = this;
              if (logger.isDebugEnabled()) {
                  logger.debug('Connecting to %s', self._config);
              }
          Severity: Minor
          Found in lib/net/tcp-connection.js - About 1 hr to fix

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

            TcpConnection.prototype.close = function (callback) {
                var self = this;
                var socket = this._socket;
                if (socket) {
                    if (logger.isDebugEnabled()) {
            Severity: Minor
            Found in lib/net/tcp-connection.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 EncryptedMessage has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            function EncryptedMessage(options) {
                var opts = options ? options : {};
                this.constructor.super_.call(this, opts.buffer, opts.offset);
                this.authKey = opts.authKey;
                if (opts.message) {
            Severity: Minor
            Found in lib/message/encrypted-message.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 callMethod has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            EncryptedRpcChannel.prototype.callMethod = function (method, callback) {
                if (!this._open) {
                    callback(new Error('Channel is closed'));
                    return;
                }
            Severity: Minor
            Found in lib/net/encrypted-rpc-channel.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 setClientDHParams has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function setClientDHParams(callback, context) {
                mtproto.service.set_client_DH_params({
                    props: {
                        nonce: context.resPQ.nonce,
                        server_nonce: context.resPQ.server_nonce,
            Severity: Minor
            Found in lib/auth/set-client-dh-params.js - About 1 hr to fix

              Function write has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              TcpConnection.prototype.write = function (data, callback) {
                  var self = this;
                  var socket = this._socket;
                  if (!socket && callback) {
                      callback(createError('Not yet connected', 'ENOTCONNECTED'));
              Severity: Minor
              Found in lib/net/tcp-connection.js - About 1 hr to fix

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

                function requestDHParams(callback, context) {
                    var resPQ = context.resPQ;
                    mtproto.service.req_DH_params({
                        props: {
                            nonce: resPQ.nonce,
                Severity: Minor
                Found in lib/auth/request-dh-params.js - About 1 hr to fix

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

                  HttpConnection.prototype._createRequest = function (options, callback) {
                      var request = http.request(options, function (res) {
                              if (logger.isDebugEnabled()) {
                                  logger.debug('reading from %s\nstatus: %s\nheaders: %s',
                                      this._config, res.statusCode, JSON.stringify(res.headers));
                  Severity: Minor
                  Found in lib/net/http-connection.js - About 1 hr to fix

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

                    MessageParser.prototype.parse = function (message, duration) {
                        if(!message || !message.getTypeName) {
                            logger.error('Message undefined or unknown', message);
                            return;
                        }
                    Severity: Minor
                    Found in lib/message/message-parser.js - About 1 hr to fix

                      Function _call has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      EncryptedRpcChannel.prototype._call = function (reqMsg, directCallback) {
                          var self = this;
                          var callback = directCallback || this._callbackMap[reqMsg.messageId];
                          try {
                              this.constructor.super_.prototype._call.call(this, reqMsg, function (ex, result, duration) {
                      Severity: Minor
                      Found in lib/net/encrypted-rpc-channel.js - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language