ronalddddd/proxy-cache

View on GitHub

Showing 17 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

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

                            proxyCache.adapter.setCache(co.cacheKey, co)
                                .then(function(){
                                    console.log("[%s] Updated adapter cache", co.cacheKey);
                                })
                                .catch(function(err){
        Severity: Major
        Found in lib/ProxyCache.js and 1 other location - About 1 hr to fix
        lib/ProxyCache.js on lines 266..272

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

        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

                        return proxyCache.adapter.setCache(co.cacheKey, co)
                            .then(function(){
                                console.log("Saved to adapter cache storage: %s", co.cacheKey);
                            })
                            .catch(function(err){
        Severity: Major
        Found in lib/ProxyCache.js and 1 other location - About 1 hr to fix
        lib/ProxyCache.js on lines 217..223

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

        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

        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

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

                                adapter.cacheCollection = Promise.promisifyAll(adapter.db.collection(process.env.npm_config_mongodb_cache_collection || options.mongodb_cache_collection || 'ProxyCache'));
                    Severity: Minor
                    Found in lib/adapters/proxy-cache-mongo.js and 1 other location - About 45 mins to fix
                    lib/adapters/proxy-cache-mongo.js on lines 23..23

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

                    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

                                adapter.pubSchedule = Promise.promisifyAll(adapter.db.collection(process.env.npm_config_mongodb_schedule_collection || options.mongodb_schedule_collection || 'PublishSchedule'));
                    Severity: Minor
                    Found in lib/adapters/proxy-cache-mongo.js and 1 other location - About 45 mins to fix
                    lib/adapters/proxy-cache-mongo.js on lines 22..22

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

                    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

                    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