balderdashy/waterline

View on GitHub
lib/waterline/methods/destroy.js

Summary

Maintainability
F
6 days
Test Coverage

Function destroy has 233 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function destroy(/* criteria, explicitCbMaybe, metaContainer */) {

  // Verify `this` refers to an actual Sails/Waterline model.
  verifyModelMethodContext(this);

Severity: Major
Found in lib/waterline/methods/destroy.js - About 1 day to fix

    Function _afterRunningBeforeLC has 164 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          })(function _afterRunningBeforeLC(err, query) {
            if (err) {
              return done(err);
            }
    
    
    Severity: Major
    Found in lib/waterline/methods/destroy.js - About 6 hrs to fix

      Function _afterPotentiallyLookingUpRecordsToCascade has 112 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              })(function _afterPotentiallyLookingUpRecordsToCascade(err, idsOfRecordsBeingDestroyedMaybe) {
                if (err) { return done(err); }
      
      
                // Now we'll actually perform the `destroy`.
      Severity: Major
      Found in lib/waterline/methods/destroy.js - About 4 hrs to fix

        Function _afterTalkingToAdapter has 109 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                  adapter.destroy(WLModel.datastore, query, function _afterTalkingToAdapter(err, rawAdapterResult) {
                    if (err) {
                      err = forgeAdapterError(err, omen, 'destroy', modelIdentity, orm);
                      return done(err);
                    }//-•
        Severity: Major
        Found in lib/waterline/methods/destroy.js - About 4 hrs to fix

          Function _afterPotentiallyWipingCollections has 65 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                      })(function _afterPotentiallyWipingCollections(err) {// ~∞%°
                        if (err) {
                          return done(err);
                        }
          
          
          Severity: Major
          Found in lib/waterline/methods/destroy.js - About 2 hrs to fix

            Function _maybeWipeAssociatedCollections has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        (function _maybeWipeAssociatedCollections(proceed) {
            
                          // If `cascade` meta key is NOT enabled, then just proceed.
                          if (!query.meta || !query.meta.cascade) {
                            return proceed();
            Severity: Minor
            Found in lib/waterline/methods/destroy.js - About 1 hr to fix

              Function _maybeTransformRecords has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                            (function _maybeTransformRecords(proceed){
              
                              // If `fetch` was not enabled, return.
                              if (!_.has(query.meta, 'fetch') || query.meta.fetch === false) {
              
              
              Severity: Minor
              Found in lib/waterline/methods/destroy.js - About 1 hr to fix

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

                        (function _maybeFindIdsToDestroy(proceed) {
                
                          // If `cascade` meta key is NOT enabled, then just proceed.
                          if (!query.meta || !query.meta.cascade) {
                            return proceed();
                Severity: Minor
                Found in lib/waterline/methods/destroy.js - About 1 hr to fix

                  Avoid too many return statements within this function.
                  Open

                                  } catch (e) { return proceed(e); }
                  Severity: Major
                  Found in lib/waterline/methods/destroy.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            } catch (e) { return done(e); }
                    Severity: Major
                    Found in lib/waterline/methods/destroy.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return proceed(undefined, transformedRecords);
                      Severity: Major
                      Found in lib/waterline/methods/destroy.js - About 30 mins to fix

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

                                        async.each(transformedRecordsMaybe, function _eachRecord(record, next) {
                        
                                          // If the `skipAllLifecycleCallbacks` meta flag was set, don't run any of
                                          // the methods.
                                          if (_.has(query.meta, 'skipAllLifecycleCallbacks') && query.meta.skipAllLifecycleCallbacks) {
                        Severity: Major
                        Found in lib/waterline/methods/destroy.js and 1 other location - About 6 hrs to fix
                        lib/waterline/methods/update.js on lines 413..443

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

                        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 (!_.isFunction(arguments[0])) {
                            query.criteria = arguments[0];
                            explicitCbMaybe = arguments[1];
                            query.meta = arguments[2];
                          }
                        Severity: Major
                        Found in lib/waterline/methods/destroy.js and 1 other location - About 4 hrs to fix
                        lib/waterline/methods/archive.js on lines 105..114

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

                        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 (!_.isArray(rawAdapterResult)) {
                                          return proceed(new Error(
                                            'Unexpected behavior in database adapter: Since `fetch: true` was enabled, this adapter '+
                                            '(for datastore `'+WLModel.datastore+'`) should have sent back an array of records as the 2nd argument when triggering '+
                                            'the callback from its `destroy` method.  But instead, got: '+util.inspect(rawAdapterResult, {depth:5})+''
                        Severity: Major
                        Found in lib/waterline/methods/destroy.js and 1 other location - About 2 hrs to fix
                        lib/waterline/methods/update.js on lines 354..361

                        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

                                  case 'E_NOOP':
                                    // Determine the appropriate no-op result.
                                    // If `fetch` meta key is set, use `[]`-- otherwise use `undefined`.
                                    //
                                    // > Note that future versions might simulate output from the raw driver.
                        Severity: Major
                        Found in lib/waterline/methods/destroy.js and 1 other location - About 1 hr to fix
                        lib/waterline/methods/update.js on lines 188..199

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

                                WLModel._callbacks.beforeDestroy(query.criteria, function (err){
                                  if (err) { return proceed(err); }
                                  return proceed(undefined, query);
                                });
                        Severity: Minor
                        Found in lib/waterline/methods/destroy.js and 2 other locations - About 35 mins to fix
                        lib/waterline/methods/create.js on lines 190..193
                        lib/waterline/methods/update.js on lines 222..225

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

                        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