nci-ats/fs-middlelayer-api

View on GitHub
src/controllers/basic.js

Summary

Maintainability
D
2 days
Test Coverage

File basic.js has 348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*

  ___ ___       ___               _ _       _   ___ ___ 
 | __/ __|  ___| _ \___ _ _ _ __ (_) |_    /_\ | _ \_ _|
 | _|\__ \ / -_)  _/ -_) '_| '  \| |  _|  / _ \|  _/| | 
Severity: Minor
Found in src/controllers/basic.js - About 4 hrs to fix

    Function postToBasic has 100 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function postToBasic(req, res, sch, body){
    
        return new Promise(function (fulfill, reject){
    
            const apiCallsObject = {
    Severity: Major
    Found in src/controllers/basic.js - About 4 hrs to fix

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

      function getBasicFields(fieldsToBasic, body, autoPopValues){
          const postObjs = {}, requestsObj = {};
          fieldsToBasic.forEach((field)=>{
              const key = Object.keys(field)[0];
              const whereToStore = field[key].store;
      Severity: Minor
      Found in src/controllers/basic.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 getBasicFields has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getBasicFields(fieldsToBasic, body, autoPopValues){
          const postObjs = {}, requestsObj = {};
          fieldsToBasic.forEach((field)=>{
              const key = Object.keys(field)[0];
              const whereToStore = field[key].store;
      Severity: Major
      Found in src/controllers/basic.js - About 2 hrs to fix

        Function buildAutoPopulatedFields has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function buildAutoPopulatedFields(fieldsToBuild, body){
            const output = {};
            fieldsToBuild.forEach((field)=>{
                const key = Object.keys(field)[0];
                const fieldMakeUp = [];
        Severity: Minor
        Found in src/controllers/basic.js - About 1 hr to fix

          Function createContact has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function createContact(fieldsObj, person, apiCallsObject){
              return new Promise(function(fulfill, reject){
                  let contactField, createPersonOrOrgURL, responseKey;
                  if (person){
                      contactField = fieldsObj['/contact/person'];
          Severity: Minor
          Found in src/controllers/basic.js - About 1 hr to fix

            Function getFromBasic has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getFromBasic(req, res, controlNumber){
            
                return new Promise(function (fulfill, reject){
            
                    const applicationCheck = `${SUDS_API_URL}/application/${controlNumber}`;
            Severity: Minor
            Found in src/controllers/basic.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                  if (field.fromIntake){
                                      splitPath.forEach((sp)=>{
                                          if (bodyField[sp]){
                                              bodyField = bodyField[sp];
                                          }
              Severity: Major
              Found in src/controllers/basic.js - About 45 mins to fix

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

                function postRequest(res, apiCallsObject, fieldsObj, responseKey, requestKey, requestPath){
                Severity: Minor
                Found in src/controllers/basic.js - About 45 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return createContact(fieldsObj, person, apiCallsObject);
                  Severity: Major
                  Found in src/controllers/basic.js - About 30 mins to fix

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

                            request(getContactOptions)
                            .then(function(res){
                                if (person){
                                    apiCallsObject.GET['/contact/lastname/{lastName}'].response = res;
                                }
                    Severity: Major
                    Found in src/controllers/basic.js and 1 other location - About 1 hr to fix
                    src/controllers/basic.js on lines 328..344

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

                    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

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

                            request(getApplicationOptions)
                            .then(function(response){
                                return fulfill(response);
                            })
                            .catch(function(err){
                    Severity: Major
                    Found in src/controllers/basic.js and 1 other location - About 1 hr to fix
                    src/controllers/basic.js on lines 391..458

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

                    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