tantalim/tantalim-server

View on GitHub
app/services/modelCompiler.js

Summary

Maintainability
F
3 days
Test Coverage

Function compile has 203 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function compile(modelDefinition) {
    var ARTIFACT = pageService.ARTIFACT; // Easy alias

    logger.info('Starting model compile', modelDefinition.name);

Severity: Major
Found in app/services/modelCompiler.js - About 1 day to fix

    Function compile has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    function compile(modelDefinition) {
        var ARTIFACT = pageService.ARTIFACT; // Easy alias
    
        logger.info('Starting model compile', modelDefinition.name);
    
    
    Severity: Minor
    Found in app/services/modelCompiler.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 buildSteps has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function buildSteps(modelDefinition, todo) {
            if (_.isEmpty(modelDefinition.steps)) {
                return;
            }
    
    
    Severity: Major
    Found in app/services/modelCompiler.js - About 2 hrs to fix

      Function mapFields has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function mapFields(modelDefinition) {
              if (!modelDefinition.fields) {
                  logger.warn('Model had no fields');
                  return;
              }
      Severity: Major
      Found in app/services/modelCompiler.js - About 2 hrs to fix

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

            function parseAndCompile(modelDefinition) {
                logger.info('Running parseAndCompile for ' + modelDefinition.name);
                //logger.debug(modelDefinition);
                var todo = [];
        
        
        Severity: Minor
        Found in app/services/modelCompiler.js - About 1 hr to fix

          Function columns has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                                  step.join.columns = _.map(join.columns, function (onClause) {
                                      var fromColumn;
                                      if (onClause.from) {
                                          fromColumn = _.find(fromTable.columns, function (column) {
                                              if (column.name === onClause.from) {
          Severity: Minor
          Found in app/services/modelCompiler.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                                            if (!fromColumn) {
                                                throw Error('Failed to find from join column ' + onClause.from +
                                                ' in table ' + fromTable.name);
                                            }
            Severity: Major
            Found in app/services/modelCompiler.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                                  if (column.name === onClause.from) {
                                                      return column;
                                                  }
              Severity: Major
              Found in app/services/modelCompiler.js - About 45 mins to fix

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

                            if (modelDefinition.basisTable in tables) {
                                var tableDefinition = tables[modelDefinition.basisTable];
                                modelDefinition.basisTable = {
                                    name: tableDefinition.name,
                                    dbName: tableDefinition.dbName
                Severity: Major
                Found in app/services/modelCompiler.js and 1 other location - About 1 hr to fix
                app/services/modelCompiler.js on lines 114..160

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

                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 (join.table in tables) {
                                        var toTable = tables[join.table];
                                        step.join = {
                                            name: step.join,
                                            table: {
                Severity: Major
                Found in app/services/modelCompiler.js and 1 other location - About 1 hr to fix
                app/services/modelCompiler.js on lines 179..190

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

                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 (!findField(child.fields, link.childField)) {
                                    throw Error('Child model ' + child.name + ' is missing childField named ' + link.childField);
                                }
                Severity: Minor
                Found in app/services/modelCompiler.js and 1 other location - About 40 mins to fix
                app/services/modelCompiler.js on lines 205..207

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

                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 (!findField(modelDefinition.fields, link.parentField)) {
                                    throw Error('Parent model ' + modelDefinition.name + ' is missing parentField named ' + link.parentField);
                                }
                Severity: Minor
                Found in app/services/modelCompiler.js and 1 other location - About 40 mins to fix
                app/services/modelCompiler.js on lines 208..210

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

                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 5 locations. Consider refactoring.
                Open

                                    var step = _.find(modelDefinition.steps, function (step) {
                                        if (step.name === field.step) {
                                            return step;
                                        }
                                    });
                Severity: Major
                Found in app/services/modelCompiler.js and 4 other locations - About 40 mins to fix
                app/controllers/pageController.js on lines 54..58
                app/services/modelCompiler.js on lines 103..107
                app/services/modelCompiler.js on lines 140..144
                app/services/pageCompiler.js on lines 74..78

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

                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 5 locations. Consider refactoring.
                Open

                                            var toColumn = _.find(toTable.columns, function (column) {
                                                if (column.name === onClause.to) {
                                                    return column;
                                                }
                                            });
                Severity: Major
                Found in app/services/modelCompiler.js and 4 other locations - About 40 mins to fix
                app/controllers/pageController.js on lines 54..58
                app/services/modelCompiler.js on lines 47..51
                app/services/modelCompiler.js on lines 103..107
                app/services/pageCompiler.js on lines 74..78

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

                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 5 locations. Consider refactoring.
                Open

                                    var join = _.find(fromTable.joins, function (join) {
                                        if (join.name === step.join) {
                                            return join;
                                        }
                                    });
                Severity: Major
                Found in app/services/modelCompiler.js and 4 other locations - About 40 mins to fix
                app/controllers/pageController.js on lines 54..58
                app/services/modelCompiler.js on lines 47..51
                app/services/modelCompiler.js on lines 140..144
                app/services/pageCompiler.js on lines 74..78

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

                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