lib/dispatch/index.js

Summary

Maintainability
F
6 days
Test Coverage

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

/**
 *  @title joola
 *  @overview the open-source data analytics framework
 *  @copyright Joola Smart Solutions, Ltd. <info@joo.la>
 *  @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
Severity: Major
Found in lib/dispatch/index.js - About 1 day to fix

    Function init has 194 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    dispatch.init = function (callback) {
      try {
        var self = dispatch;
    
        self.namespace = 'dispatch';
    Severity: Major
    Found in lib/dispatch/index.js - About 7 hrs to fix

      Function init has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      dispatch.init = function (callback) {
        try {
          var self = dispatch;
      
          self.namespace = 'dispatch';
      Severity: Minor
      Found in lib/dispatch/index.js - About 3 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 stompConnect has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            var stompConnect = function () {
              var stompArgs = {
                host: stompSettings.host,
                port: stompSettings.port,
                login: stompSettings.user,
      Severity: Major
      Found in lib/dispatch/index.js - About 2 hrs to fix

        Function processRequest has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        dispatch.processRequest = function (message, headers) {
          message = message[0];
          message = JSON.parse(message).message;
        
          var _result;
        Severity: Major
        Found in lib/dispatch/index.js - About 2 hrs to fix

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

          dispatch.once = function (channel, callback, next) {
            callback = callback || function () {
            };
          
            var exists = _.find(dispatch.listeners, function (listener) {
          Severity: Minor
          Found in lib/dispatch/index.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 processResponse has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          dispatch.processResponse = function (message, headers) {
            message = message[0];
            message = JSON.parse(message);
            var listeners = _.filter(dispatch.listeners, function (l) {
              return l._dispatch.message === headers.subscription.replace('/temp-queue/joola.dispatch.', '').replace('.', ':').replace('.done', '');
          Severity: Minor
          Found in lib/dispatch/index.js - About 1 hr to fix

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

            dispatch.on = function (channel, callback, next) {
              callback = callback || function () {
              };
              var exists = _.find(dispatch.listeners, function (listener) {
                return listener._dispatch.message == channel && (listener._dispatch.cb ? listener._dispatch.cb.toString() : null) == (callback ? callback.toString() : null);
            Severity: Minor
            Found in lib/dispatch/index.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 once has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            dispatch.once = function (channel, callback, next) {
              callback = callback || function () {
              };
            
              var exists = _.find(dispatch.listeners, function (listener) {
            Severity: Minor
            Found in lib/dispatch/index.js - About 1 hr to fix

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

              dispatch.on = function (channel, callback, next) {
                callback = callback || function () {
                };
                var exists = _.find(dispatch.listeners, function (listener) {
                  return listener._dispatch.message == channel && (listener._dispatch.cb ? listener._dispatch.cb.toString() : null) == (callback ? callback.toString() : null);
              Severity: Minor
              Found in lib/dispatch/index.js - About 1 hr to fix

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

                dispatch.request = function (token, channel, params, callback) {
                  var self = dispatch;
                  var compiled = {
                    id: joola.common.uuid(),
                    timestamp: new Date().getTime(),
                Severity: Minor
                Found in lib/dispatch/index.js - About 1 hr to fix

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

                  dispatch.setup = function (fn, callback) {
                    var details = fn._dispatch;
                  
                    if (!details)
                      return process.nextTick(function () {
                  Severity: Minor
                  Found in lib/dispatch/index.js - About 1 hr to fix

                    Function hook has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                    dispatch.hook = function () {
                      fs.readdirSync(path.join(__dirname, './')).forEach(function (file) {
                        if (file != 'index.js' && file != 'index2.js' && file != 'prototypes') {
                          try {
                            var module = require('./' + file);
                    Severity: Minor
                    Found in lib/dispatch/index.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 setup has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                    dispatch.setup = function (fn, callback) {
                      var details = fn._dispatch;
                    
                      if (!details)
                        return process.nextTick(function () {
                    Severity: Minor
                    Found in lib/dispatch/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

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

                          dispatch.publishMessage = function (client, message, queueName, routingKey, replyTo) {
                    Severity: Minor
                    Found in lib/dispatch/index.js - About 35 mins to fix

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

                        var exists = _.find(dispatch.listeners, function (listener) {
                          return listener._dispatch.message == channel && (listener._dispatch.cb ? listener._dispatch.cb.toString() : null) == (callback ? callback.toString() : null);
                        });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 2 hrs to fix
                      lib/dispatch/index.js on lines 526..528

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

                      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

                        var exists = _.find(dispatch.listeners, function (listener) {
                          return listener._dispatch.message == channel && (listener._dispatch.cb ? listener._dispatch.cb.toString() : null) == (callback ? callback.toString() : null);
                        });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 2 hrs to fix
                      lib/dispatch/index.js on lines 568..570

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

                      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.subscriber.on('connect', function () {
                              joola.logger.debug('[subscriber] Connected to redis @ ' + self.host + ':' + self.port + '#' + self.db);
                              joola.state.set('subscriber', 'working', 'redis [subscriber] is up.');
                            });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 2 hrs to fix
                      lib/dispatch/index.js on lines 73..76

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

                      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.publisher.on('connect', function () {
                              joola.logger.debug('[publisher] Connected to redis @ ' + self.host + ':' + self.port + '#' + self.db);
                              joola.state.set('publisher', 'working', 'redis [publisher] is up.');
                            });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 2 hrs to fix
                      lib/dispatch/index.js on lines 82..85

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

                      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.publisher.on('error', function (err) {
                              joola.state.set('publisher', 'failure', 'redis [publisher] is down: ' + (typeof(err) === 'object' ? err.message : err));
                            });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 1 hr to fix
                      lib/dispatch/index.js on lines 87..89

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

                      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.subscriber.on('error', function (err) {
                              joola.state.set('subscriber', 'failure', 'redis [subscriber] is down: ' + (typeof(err) === 'object' ? err.message : err));
                            });
                      Severity: Major
                      Found in lib/dispatch/index.js and 1 other location - About 1 hr to fix
                      lib/dispatch/index.js on lines 79..81

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

                      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.keys(result.message).forEach(function (key) {
                                args.push(result.message[key]);
                              });
                      Severity: Minor
                      Found in lib/dispatch/index.js and 1 other location - About 35 mins to fix
                      lib/webserver/routes/index.js on lines 308..310

                      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