lib/common/index.js

Summary

Maintainability
D
2 days
Test Coverage

Function sanitize has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

common.sanitize = function (obj, proto, leavePrivate) {
  var cleanup = function (elem) {
    var result = {};
    Object.keys(elem).forEach(function (key) {
      if (!leavePrivate) {
Severity: Minor
Found in lib/common/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 flatGetSet has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

common.flatGetSet = function (obj, is, value) {
  if (typeof is == 'string') {
    return common.flatGetSet(obj, is.split('.'), value);
  }
  else if (is.length == 1 && value !== undefined) {
Severity: Minor
Found in lib/common/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

File index.js has 258 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: Minor
Found in lib/common/index.js - About 2 hrs to fix

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

    common.sanitize = function (obj, proto, leavePrivate) {
      var cleanup = function (elem) {
        var result = {};
        Object.keys(elem).forEach(function (key) {
          if (!leavePrivate) {
    Severity: Minor
    Found in lib/common/index.js - About 1 hr to fix

      Function typeof has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      common.typeof = function (obj) {
        if (typeof(obj) == "object") {
          if (obj === null) return "null";
          if (obj.constructor == (new Array).constructor) return "array";
          if (obj.constructor == (new Date).constructor) return "date";
      Severity: Minor
      Found in lib/common/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 flatGetSet has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      common.flatGetSet = function (obj, is, value) {
        if (typeof is == 'string') {
          return common.flatGetSet(obj, is.split('.'), value);
        }
        else if (is.length == 1 && value !== undefined) {
      Severity: Minor
      Found in lib/common/index.js - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  if (k.substring(0, 1) === '_' && k !== '_')
                    delete obj[k];
                  else
                    common.sanitize(obj[k]);
        Severity: Major
        Found in lib/common/index.js - About 45 mins to fix

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

          common.mixin = function (origin, add, overwrite) {
            // Don't do anything if add isn't an object
            if (!add || typeof add !== 'object') return origin;
          
            var keys = Object.keys(add);
          Severity: Minor
          Found in lib/common/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 too many return statements within this function.
          Open

              if (obj.constructor == (new RegExp).constructor) return "regex";
          Severity: Major
          Found in lib/common/index.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return common.objToArray(obj);
            Severity: Major
            Found in lib/common/index.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                return typeof(obj);
              Severity: Major
              Found in lib/common/index.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return "object";
                Severity: Major
                Found in lib/common/index.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return common.flatGetSet(obj[is[0]], is.slice(1), value);
                  Severity: Major
                  Found in lib/common/index.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return obj;
                    Severity: Major
                    Found in lib/common/index.js - About 30 mins to fix

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

                      common.hashPassword = function (plainPassword, salt) {
                        if (!plainPassword)
                          return null;
                        try {
                          if (!salt)
                      Severity: Major
                      Found in lib/common/index.js and 1 other location - About 4 hrs to fix
                      lib/common/auth.js on lines 726..739

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

                      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