ronalddddd/proxy-cache

View on GitHub

Showing 13 of 17 total issues

File ProxyCache.js has 278 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var verboseLog = (process.env.npm_config_verbose_log)? console.log : function() {},
    format = require('util').format,
    Promise = require('bluebird'),
    httpProxy = require('http-proxy'),
    MobileDetect = require('mobile-detect'),
Severity: Minor
Found in lib/ProxyCache.js - About 2 hrs to fix

    Function handleRequest has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    ProxyCache.prototype.handleRequest = function(req, res){
        var proxyCache = this;
    
        if (proxyCache.options.spoofHostHeader){
            req.headers.host = proxyCache.proxyTarget;
    Severity: Minor
    Found in lib/ProxyCache.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 ProxyCache has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var ProxyCache = function(options){
        var proxyCache = this;
    
        proxyCache.options = options || {};
        proxyCache.options.memGiBThreshold = proxyCache.options.memGiBThreshold || 2;
    Severity: Minor
    Found in lib/ProxyCache.js - About 2 hrs to fix

      Function handleRequest has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      ProxyCache.prototype.handleRequest = function(req, res){
          var proxyCache = this;
      
          if (proxyCache.options.spoofHostHeader){
              req.headers.host = proxyCache.proxyTarget;
      Severity: Minor
      Found in lib/ProxyCache.js - About 1 hr to fix

        Function CacheObject has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        var CacheObject = function(cacheKey, input, req){
            var co = this,
                res = (input instanceof stream.Readable)? input : null,
                jsonString = (typeof input ===  'string')? input : null,
                deserialized = (jsonString)? JSON.parse(jsonString) : {},
        Severity: Minor
        Found in lib/CacheObject.js - About 1 hr to fix

          Function respondWithCacheObject has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          ProxyCache.prototype.respondWithCacheObject = function(req, res, co){
              var proxyCache = this;
          
              for(var headerKey in co.headers){
                  res.setHeader(headerKey, co.headers[headerKey]);
          Severity: Minor
          Found in lib/ProxyCache.js - About 1 hr to fix

            Function setProxyResponseStream has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            CacheObject.prototype.setProxyResponseStream = function(proxyRes) {
                var co = this,
                    _upstreamEndDefer = Promise.defer(); // TODO: consolidate with `.ready` promise
            
                // Reset buffer array
            Severity: Minor
            Found in lib/CacheObject.js - About 1 hr to fix

              Function checkIfStale has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              ProxyCacheMongoAdapter.prototype.checkIfStale = function(){
                  var adapter = this;
              
                  if(!adapter.lastPubDate){
                      verboseLog("Publish date not set.");
              Severity: Minor
              Found in lib/adapters/proxy-cache-mongo.js - About 1 hr to fix

                Function ProxyCacheMongoAdapter has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function ProxyCacheMongoAdapter(proxyCache, options){
                    var adapter = this;
                    options = options || {};
                
                    adapter.proxyCache = proxyCache;
                Severity: Minor
                Found in lib/adapters/proxy-cache-mongo.js - About 1 hr to fix

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

                  ProxyCache.prototype.clearAll = function(keyRegex){
                      var proxyCache = this,
                          shouldClearTest = (keyRegex && keyRegex instanceof RegExp)?
                              function regexTest(key){
                                  return keyRegex.test(key);
                  Severity: Minor
                  Found in lib/ProxyCache.js - About 1 hr to fix

                    Function clearAll has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    ProxyCache.prototype.clearAll = function(keyRegex){
                        var proxyCache = this,
                            shouldClearTest = (keyRegex && keyRegex instanceof RegExp)?
                                function regexTest(key){
                                    return keyRegex.test(key);
                    Severity: Minor
                    Found in lib/ProxyCache.js - About 1 hr 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 CacheObject has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    var CacheObject = function(cacheKey, input, req){
                        var co = this,
                            res = (input instanceof stream.Readable)? input : null,
                            jsonString = (typeof input ===  'string')? input : null,
                            deserialized = (jsonString)? JSON.parse(jsonString) : {},
                    Severity: Minor
                    Found in lib/CacheObject.js - About 1 hr 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 ProxyCache has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                    var ProxyCache = function(options){
                        var proxyCache = this;
                    
                        proxyCache.options = options || {};
                        proxyCache.options.memGiBThreshold = proxyCache.options.memGiBThreshold || 2;
                    Severity: Minor
                    Found in lib/ProxyCache.js - About 35 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

                    Severity
                    Category
                    Status
                    Source
                    Language