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'),
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;
- Read upRead up
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;
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;
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){
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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){
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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) : {},
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]);
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
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.");
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;
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);
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);
- Read upRead up
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) : {},
- Read upRead up
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'));
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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'));
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- Read upRead up
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"