codenautas/backend-plus

View on GitHub
lib/table-def-adapt.js

Summary

Maintainability
F
5 days
Test Coverage

Function tableDefAdapt has 307 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function tableDefAdapt(tableDef, context){
    var be = this;
    var fieldDomain = be.fieldDomain || {};
    if(false && !be.fieldDomain){
        throw new Error('lack of fieldDomain in backend. postConfig must call super.postConfig');
Severity: Major
Found in lib/table-def-adapt.js - About 1 day to fix

    Function tableDefAdapt has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
    Open

    function tableDefAdapt(tableDef, context){
        var be = this;
        var fieldDomain = be.fieldDomain || {};
        if(false && !be.fieldDomain){
            throw new Error('lack of fieldDomain in backend. postConfig must call super.postConfig');
    Severity: Minor
    Found in lib/table-def-adapt.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

    File table-def-adapt.js has 351 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    "use strict";
    
    var likeAr = require('like-ar');
    var changing = require('best-globals').changing;
    var coalesce = require('best-globals').coalesce;
    Severity: Minor
    Found in lib/table-def-adapt.js - About 4 hrs to fix

      Consider simplifying this complex logical expression.
      Open

          if(resultTableDef.sql.policies.enabled==null){
              var pol = resultTableDef.sql.policies;
              pol.enabled = (
                  pol.all.using || pol.select.using || pol.insert.using || pol.update.using || pol.delete.using ||
                  pol.all.check || pol.select.check || pol.insert.check || pol.update.check || pol.delete.check ||
      Severity: Critical
      Found in lib/table-def-adapt.js - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if(context && !context.plainStructure){
                resultTableDef.foreignKeys.concat(resultTableDef.softForeignKeys).forEach(function(fkDef){
                    if(fkDef.definingSubclass){
                        return;
                    }
        Severity: Critical
        Found in lib/table-def-adapt.js - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                  if(pol && pol.enabled){
                      otherColumns.push(`(${(pol.enabled && (pol.update.using || pol.all.using) || 'true' )}) is true as "$allow.update"`);
                      otherColumns.push(`(${(pol.enabled && (pol.delete.using || pol.all.using) || 'true' )}) is true as "$allow.delete"`);
                  }
          Severity: Critical
          Found in lib/table-def-adapt.js - About 1 hr to fix

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

                resultTableDef.fields = resultTableDef.fields.map(function(fieldDef){
                    var resultFieldDef = changing(changing({
                        visible: true,
                        allow:{},
                        defaultForOtherFields: false,
            Severity: Minor
            Found in lib/table-def-adapt.js - About 1 hr to fix

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

              tableDefAdapt.forInsertOnly = function forInsertOnly(tableDef){
                  if(tableDef.forInsertOnlyMode){
                      tableDef.field = likeAr(tableDef.field).filter(function(fieldDef){
                          return fieldDef.orderForInsertOnly;
                      });
              Severity: Minor
              Found in lib/table-def-adapt.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

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

                  resultTableDef.softForeignKeys.map(function(sfk){
                      sfk.fields.forEach(function(pair, i, pairs){
                          if(typeof pair === "string"){
                              pairs[i] = {source: pair, target: pair};
                          }
              Severity: Major
              Found in lib/table-def-adapt.js and 1 other location - About 2 hrs to fix
              lib/table-def-adapt.js on lines 149..155

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

              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

                  resultTableDef.foreignKeys.map(function(fk){
                      fk.fields.forEach(function(pair, i, pairs){
                          if(typeof pair === "string"){
                              pairs[i] = {source: pair, target: pair};
                          }
              Severity: Major
              Found in lib/table-def-adapt.js and 1 other location - About 2 hrs to fix
              lib/table-def-adapt.js on lines 156..162

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

              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

                                  return be.db.quoteIdent(resultTableDef.alias)+'.'+be.db.quoteIdent(pair.source)
                                      + ' = ' + be.db.quoteIdent(fkDef.alias)+'.'+be.db.quoteIdent(pair.target);
              Severity: Major
              Found in lib/table-def-adapt.js and 1 other location - About 1 hr to fix
              lib/table-def-adapt.js on lines 350..350

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

              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

                                  be.db.quoteIdent(fieldDef.referencedAlias)+"."+be.db.quoteIdent(fieldDef.referencedName)+" as "+be.db.quoteIdent(fieldDef.name)
              Severity: Major
              Found in lib/table-def-adapt.js and 1 other location - About 1 hr to fix
              lib/table-def-adapt.js on lines 267..268

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

              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

                          otherColumns.push(`(${(pol.enabled && (pol.update.using || pol.all.using) || 'true' )}) is true as "$allow.update"`);
              Severity: Minor
              Found in lib/table-def-adapt.js and 1 other location - About 50 mins to fix
              lib/table-def-adapt.js on lines 237..237

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

              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

                          otherColumns.push(`(${(pol.enabled && (pol.delete.using || pol.all.using) || 'true' )}) is true as "$allow.delete"`);
              Severity: Minor
              Found in lib/table-def-adapt.js and 1 other location - About 50 mins to fix
              lib/table-def-adapt.js on lines 236..236

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

              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

                                          throw new Error('ERROR in tableDef '+JSON.stringify(resultTableDef.name)+' fk.fields.source '+JSON.stringify(fkDef.fields[lastPos].source)+' not found')
              Severity: Minor
              Found in lib/table-def-adapt.js and 1 other location - About 40 mins to fix
              lib/table-def-adapt.js on lines 307..307

              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

                                  throw new Error('ERROR in tableDef '+JSON.stringify(resultTableDef.name)+' in FKs, field '+JSON.stringify(fkDef.fields[lastPos].target)+' not present in table '+JSON.stringify(resultTableDef.name));
              Severity: Minor
              Found in lib/table-def-adapt.js and 1 other location - About 40 mins to fix
              lib/table-def-adapt.js on lines 313..313

              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

              There are no issues that match your filters.

              Category
              Status