sideshowcoder/canned

View on GitHub
lib/canned.js

Summary

Maintainability
D
2 days
Test Coverage

File canned.js has 375 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

var url = require('url')
var fs = require('fs')
var util = require('util')
Severity: Minor
Found in lib/canned.js - About 5 hrs to fix

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

    Canned.prototype.responder = function(body, req, res) {
      var responseHandler
      var httpObj = {}
      var that = this
      var parsedurl = url.parse(req.url)
    Severity: Minor
    Found in lib/canned.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 _getFileFromRequest has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    Canned.prototype._getFileFromRequest = function(httpObj, files) {
    
      if (!files) return false
    
      var m, i, e, matchString, fileMatch, ctype
    Severity: Minor
    Found in lib/canned.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 responder has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Canned.prototype.responder = function(body, req, res) {
      var responseHandler
      var httpObj = {}
      var that = this
      var parsedurl = url.parse(req.url)
    Severity: Major
    Found in lib/canned.js - About 2 hrs to fix

      Function parseMetaData has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Canned.prototype.parseMetaData = function(response) {
        var metaData = {}
        // convert CR+LF => LF+LF, CR => LF, fixes line breaks causing issues in windows
        response = response.replace("\r", "\n");
        var lines = response.split("\n")
      Severity: Minor
      Found in lib/canned.js - About 1 hr to fix

        Function responseFilter has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Canned.prototype.responseFilter = function (req, res) {
          var that = this
          var body = ''
        
          // assemble response body if GET/POST/PUT
        Severity: Minor
        Found in lib/canned.js - About 1 hr to fix

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

          Canned.prototype._responseForFile = function (httpObj, files, cb) {
            var that = this
            var fileObject = this._getFileFromRequest(httpObj, files);
            httpObj.filename = fileObject.fname
            if (fileObject) {
          Severity: Minor
          Found in lib/canned.js - About 1 hr to fix

            Function _getFileFromRequest has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            Canned.prototype._getFileFromRequest = function(httpObj, files) {
            
              if (!files) return false
            
              var m, i, e, matchString, fileMatch, ctype
            Severity: Minor
            Found in lib/canned.js - About 1 hr to fix

              Function getSelectedResponse has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Canned.prototype.getSelectedResponse = function(responses, content, headers) {
                var that = this
                var inputObj
                var response = responses[0]
                var metaData = that.parseMetaData(response)
              Severity: Minor
              Found in lib/canned.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                          if(Response.content_types[type] === httpObj.accept[i].trim()){
                            httpObj.matchingContentTypes.push(type);
                          }
                Severity: Major
                Found in lib/canned.js - About 45 mins to fix

                  Function matchFileWithExactQuery has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  function matchFileWithExactQuery(matchString, fname, queryString, method, ctype) {
                  Severity: Minor
                  Found in lib/canned.js - About 35 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status