File core.js
has 857 lines of code (exceeds 250 allowed). Consider refactoring. Open
(function(core) {
var _ = require('underscore'),
request = require('request'),
urlLib = require('url');
Function run
has 146 lines of code (exceeds 25 allowed). Consider refactoring. Open
var run = core.run = function(uri, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
Function getPluginsSet
has 111 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getPluginsSet(uri, options, usedParams) {
var initialPlugins = [],
usedDomains,
isDomainPluginsMode = false,
Function runMethods
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
function runMethods(methods, context, pluginsUrlMatches, options, asyncMethodCb) {
// Sync results list.
var results = [];
Function useResult
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
function useResult(usedMethods, context, pluginsContexts, allResults, result, options, asyncMethodCb) {
if (!result) {
return false;
}
Function prepareResultData
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
function prepareResultData(uri, result, options) {
if (!options.debug) {
// TODO: deep clean?
delete result.allData;
Function runPostPlugins
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
function runPostPlugins(link, dataRecord, usedMethods, context, pluginsContexts, asyncMethodCb) {
for(var i = 0; i < postPluginsList.length; i++) {
(function() {
Function findPluginMethods
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findPluginMethods(pluginId, loadedParams, pluginsUrlMatches, usedMethods, usedParams, methods, scannedPluginsIds, usedDomains, mandatoryParams) {
/*
* Params:
*
Function asyncMethodCb
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
asyncMethodCb = function(error, result) {
if (aborted) {
return;
}
Function sortLinks
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
core.sortLinks = function(links) {
// Sort links in order of REL according to CONFIG.REL_GROUPS.
function getRelIndex(rel) {
var rels = _.intersection(rel, CONFIG.REL_GROUPS);
Function callback
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
var callback = function(error, data) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
Function findPluginMethods
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
function findPluginMethods(pluginId, loadedParams, pluginsUrlMatches, usedMethods, usedParams, methods, scannedPluginsIds, usedDomains, mandatoryParams) {
Function finish
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
finish = function() {
// Abort request.
if (context.htmlparser && context.htmlparser.request) {
context.htmlparser.request.abort();
Function runPluginsIteration
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
function runPluginsIteration(requiredPlugins, context, pluginsUrlMatches, usedMethods, usedParams, usedDomains, options, asyncMethodCb) {
Function useResult
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function useResult(usedMethods, context, pluginsContexts, allResults, result, options, asyncMethodCb) {
Avoid deeply nested control flow statements. Open
if (!(key in context) || key === 'whitelistRecord') {
context[key] = r.data[key];
hasNewData = true;
}
Function runPostPlugins
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function runPostPlugins(link, dataRecord, usedMethods, context, pluginsContexts, asyncMethodCb) {
Avoid deeply nested control flow statements. Open
while (!match && j < res.length) {
match = uri.match(res[j]);
j++;
}
Avoid deeply nested control flow statements. Open
if (idx === -1 || ((idx > 0) && domain.charAt(idx - 1) !== '.')) {
// Break if not found, or not dot separation.
continue;
}
Avoid deeply nested control flow statements. Open
if (match) {
registerDomainPlugin(plugin, null);
}
Avoid deeply nested control flow statements. Open
if (match) {
// Store match for plugin.
registerDomainPlugin(plugin, match);
pluginsUrlMatches[plugin.id] = match;
continue;
Avoid deeply nested control flow statements. Open
if (!exists) {
initialPlugins.push(plugins[foundPluginId]);
}
Avoid deeply nested control flow statements. Open
for(var key in r.data) {
var v = r.data[key];
// TODO: postprocessing meta plugins.
Consider simplifying this complex logical expression. Open
if (canonical && link.href && typeof link.href === 'string' && link.rel && link.rel.indexOf(CONFIG.R.file) === -1 && link.rel.indexOf(CONFIG.R.iframely) === -1) {
// Remove last / from url.
var link1 = link.href.replace(/\/+$/, '');
Consider simplifying this complex logical expression. Open
if ((hasGetLinkMethod && getLinkMethodUsed)
|| (r.method.name === 'getData' && r.data.safe_html)
|| (!hasGetLinkMethod && r.method.name === 'getMeta')) {
hasDomainData = true;
}
Function runMethods
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function runMethods(methods, context, pluginsUrlMatches, options, asyncMethodCb) {
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return -1;
Avoid too many return
statements within this function. Open
return 1;
Avoid too many return
statements within this function. Open
return 1;
Avoid too many return
statements within this function. Open
return 0;
Avoid too many return
statements within this function. Open
return 1;
Avoid too many return
statements within this function. Open
return -1;
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (r.error && r.error[SYS_ERRORS.responseStatusCode]) {
sysUtils.log(' -- response (by "' + r.method.pluginId + '")', r.error[SYS_ERRORS.responseStatusCode]);
return r.error[SYS_ERRORS.responseStatusCode];
}
- 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 82.
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
if (r.error && r.error[SYS_ERRORS.redirect]) {
sysUtils.log(' -- plugin redirect (by "' + r.method.pluginId + '")', r.error[SYS_ERRORS.redirect]);
return r.error[SYS_ERRORS.redirect];
}
- 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 82.
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