jaredhanson/locomotive

View on GitHub
lib/controller.js

Summary

Maintainability
F
3 days
Test Coverage

Function render has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

Controller.prototype.render = function(template, options, fn) {
  if (typeof options === 'function') {
    fn = options;
    options = undefined;
  } else if (typeof template === 'function') {
Severity: Minor
Found in lib/controller.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 respondWith has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

Controller.prototype.respondWith = function(obj) {
  var req = this.__req
    , res = this.__res
    , format = this.__req.params.format;
  format = format ? mime.lookup(format) : undefined;
Severity: Minor
Found in lib/controller.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

File controller.js has 309 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Module dependencies.
 */
var router = require('actionrouter')
  , mime = require('express').mime
Severity: Minor
Found in lib/controller.js - About 3 hrs to fix

    Function _invoke has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    Controller.prototype._invoke = function(action) {
      if (typeof this[action] !== 'function') {
        return this.__next(new ControllerError(this.__id + '#' + action + ' is not a function'));
      }
      
    Severity: Minor
    Found in lib/controller.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 _devoke has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    Controller.prototype._devoke = function(err, cb) {
      if (this.__devoked) { return; }
      this.__devoked = true;
    
      var self = this
    Severity: Minor
    Found in lib/controller.js - About 2 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 render has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Controller.prototype.render = function(template, options, fn) {
      if (typeof options === 'function') {
        fn = options;
        options = undefined;
      } else if (typeof template === 'function') {
    Severity: Major
    Found in lib/controller.js - About 2 hrs to fix

      Function _invoke has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Controller.prototype._invoke = function(action) {
        if (typeof this[action] !== 'function') {
          return this.__next(new ControllerError(this.__id + '#' + action + ' is not a function'));
        }
        
      Severity: Major
      Found in lib/controller.js - About 2 hrs to fix

        Function respondWith has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Controller.prototype.respondWith = function(obj) {
          var req = this.__req
            , res = this.__res
            , format = this.__req.params.format;
          format = format ? mime.lookup(format) : undefined;
        Severity: Minor
        Found in lib/controller.js - About 1 hr to fix

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

          Controller.prototype._devoke = function(err, cb) {
            if (this.__devoked) { return; }
            this.__devoked = true;
          
            var self = this
          Severity: Minor
          Found in lib/controller.js - About 1 hr to fix

            Function iter has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              (function iter(err, data) {
                if (err) { return self.error(err); }
            
                filter = filters[i++];
                if (!filter) {
            Severity: Minor
            Found in lib/controller.js - About 1 hr to fix

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

                (function iter(err) {
                  filter = filters[i++];
                  if (!filter) {
                    // filters done
                    cb && cb(err);
              Severity: Minor
              Found in lib/controller.js - About 1 hr to fix

                Function before has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                Controller.prototype.before = function(action, fn) {
                  var i, len;
                  
                  // If an array of filters is passed as an argument, decompose the array into
                  // its constituent arguments.
                Severity: Minor
                Found in lib/controller.js - About 45 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 3 locations. Consider refactoring.
                Open

                  if (typeof options === 'function') {
                    fn = options;
                    options = undefined;
                  } else if (typeof template === 'function') {
                    fn = template;
                Severity: Major
                Found in lib/controller.js and 2 other locations - About 1 hr to fix
                lib/boot/httpserver.js on lines 28..35
                lib/boot/httpservercluster.js on lines 31..38

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

                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

                  } else if (fopts.extension) {
                    ext = fopts.extension;
                    if ('.' == ext[0]) { ext = ext.slice(1); }
                    comps = [ tmpl, ext ];
                  }
                Severity: Major
                Found in lib/controller.js and 1 other location - About 1 hr to fix
                lib/controller.js on lines 134..144

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

                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

                  } else if (options.extension) {
                    ext = options.extension;
                    if ('.' == ext[0]) { ext = ext.slice(1); }
                    comps = [ tmpl, ext ];
                  } else if (fopts.engine) {
                Severity: Major
                Found in lib/controller.js and 1 other location - About 1 hr to fix
                lib/controller.js on lines 140..144

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

                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