BeameryHQ/Ditto

View on GitHub
ditto/mappers/map.js

Summary

Maintainability
D
2 days
Test Coverage

Function map has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

async function map(document, mappings, plugins) {

    /**
     * @function processMappings
     *
Severity: Minor
Found in ditto/mappers/map.js - About 1 day 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 map has 123 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function map(document, mappings, plugins) {

    /**
     * @function processMappings
     *
Severity: Major
Found in ditto/mappers/map.js - About 4 hrs to fix

    Function processMappings has 118 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function processMappings(mappings, document, result, parentKey) {
    
            _.each(mappings, function(path, key) {
    
                key = parentKey ? `${parentKey}.${key}` : key;
    Severity: Major
    Found in ditto/mappers/map.js - About 4 hrs to fix

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

              function getValue(path, subDocument) {
      
                  if (!path) return;
      
                  if (path === '!') return document;
      Severity: Minor
      Found in ditto/mappers/map.js - About 1 hr to fix

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

                            function parseMappings(result, innerResult, path, key, $value, $key) {
        Severity: Minor
        Found in ditto/mappers/map.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                          if (!!path.prerequisite) {
                                              if (!!eval(path.prerequisite)) _.set(result, fullPath, innerResult);
                                          } else _.set(result, fullPath, innerResult);
          Severity: Major
          Found in ditto/mappers/map.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                            if (!!path.prerequisite) {
                                                if (!!eval(path.prerequisite)) _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
                                            } else _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
            Severity: Major
            Found in ditto/mappers/map.js - About 45 mins to fix

              Avoid too many return statements within this function.
              Open

                              return _.isPlainObject(subDocument) ? _.get(subDocument, path) :  _.get(document, path);
              Severity: Major
              Found in ditto/mappers/map.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return plugins[functionCall].apply(null, paramteresValues);
                Severity: Major
                Found in ditto/mappers/map.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              } else return getValue(path, $value);
                  Severity: Major
                  Found in ditto/mappers/map.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return isValidValue ? applyTransformation(null, parameters.targetValue, null, subDocument) : null;
                    Severity: Major
                    Found in ditto/mappers/map.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return getValue(pathWithDefault[0], subDocument) || getValue(`${pathWithDefault[1]}`);
                      Severity: Major
                      Found in ditto/mappers/map.js - About 30 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status