Showing 122 of 2,019 total issues
Consider simplifying this complex logical expression. Open
if ((survey.active === false) ||
// Data required by the owner
(req.user && survey.owner.id === req.user.id) ||
// Survey is active and results are always public or shown after vote
(survey.active === true && (survey.public_results || survey.results_after_vote)) ||
Function getSurveyResponsesSql
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getSurveyResponsesSql(survey, type, getFilters, lang) {
var id = survey.id,
countryNamePromise,
provinceNamePromise,
municipalityNamePromise;
Function paginationTemplate
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
paginationTemplate: function(elementName) {
return function(result) {
function getPrevNextLink(prelink, url, next) {
return '<li class="pagination-' + (next ? 'next' : 'previous') + (url ? '' : ' disabled') + '"><a' + (url ? ' href="' + prelink + url + '"' : '') + '><span class="glyphicon glyphicon-menu-' + (next ? 'right' : 'left') + '"></span></a></li>';
}
Function createFromPost
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Survey.createFromPost = function(req) {
var survey;
return Survey.create({
owner_id : req.user.id,
title : trimSubstringField(req.body.survey_title, 150),
Consider simplifying this complex logical expression. Open
if (j !== 'name' && j !== 'total_responses' && j !== 'iso_code' &&
j !== 'country_id' && j !== 'adm_code' && j !== 'adm_type' &&
j !== 'country_iso_code' && j !== 'geojson') {
question = j.split('_')[0];
if (isNaN(question.replace('q', '')) ||
Consider simplifying this complex logical expression. Open
if ((survey.active === false) ||
// Data required by the owner
(req.user && survey.owner.id === req.user.id) ||
// Survey is active and results are always public
(survey.active === true && survey.public_results) ||
Function start
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
self.start = function() {
var options = {};
options.key = serverConfig.ssl.key ? fs.readFileSync(serverConfig.ssl.key) : fs.readFileSync('./test-key.pem');
options.cert = serverConfig.ssl.cert ? fs.readFileSync(serverConfig.ssl.cert) : fs.readFileSync('./test-cert.pem');
if (serverConfig.ssl.ca) {
Function getAnsweredSurveys
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
User.prototype.getAnsweredSurveys = function(query, order, pageSize, pageNr) {
var userId = this.id,
orders;
if (order === 'answer') {
orders = [[sequelize.fn('max', sequelize.col('vote_date')), 'DESC'], [models.Survey, 'id', 'DESC']];
Function updateFromPost
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Survey.updateFromPost = function(req) {
var survey;
return Survey.findByPk(req.body.survey_id).then(function(surv) {
survey = surv;
var markerPromise = Promise.resolve(survey.custom_single_marker_file_id);
Function generateExclusiveBtnAnswerHtml
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function generateExclusiveBtnAnswerHtml(answer, layout, question) {
var btnClass,
divClass,
btnContent,
style = '';
- 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 getInsertSql
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Question.prototype.getInsertSql = function(responses) {
var respField = 'q' + this.question_order + '.id';
switch (this.type) {
case 'list-radio-other':
if (respField in responses &&
Function takeSnapshot
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
takeSnapshot: function(url, imgPath, nativeWidth, nativeHeight, wait, minSize, retries, imgWidth, imgHeight) {
Function parseTagsFromPost
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function parseTagsFromPost(req) {
if (req.body.survey_tags && req.body.survey_tags.trim().length > 0) {
tags = req.body.survey_tags.substring(0, 150).trim();
var indivTags = tags.split(','),
indivTagsClean = [];
- 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 search
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
search: function(query, ordering) {
var params = {
where:
sequelize.where(
sequelize.fn('ts_match',
Function getUserFullResponses
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Survey.prototype.getUserFullResponses = function(userId) {
var surv = this,
id = this.id,
questions;
return this.getQuestions({ scope: 'includeSurvey' }).then(function(qstns) {
Function transformImage
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
transformImage: function(input, width, height, upscale, format, outputFile) {
var imgFormat = format ? format : null;
if (sharp) {
if (imgFormat && imgFormat.lastIndexOf('image/') === 0) {
imgFormat = imgFormat.replace('image/', '');
Function getPostInsertOperations
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Question.prototype.getPostInsertOperations = function(responses, answerId) {
var respField = 'q' + this.question_order + '.id',
question = this,
survey = this.Survey;
switch (this.type) {
Function findSurveys
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
Survey.findSurveys = function(userId, onlyPublic, status, query, tag, order, pageSize, pageNr) {
Function exports
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function(app) {
utils(app);
var oauthConfig = nconf.get('app').oAuth;
- 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 takeSnapshotRaw
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function takeSnapshotRaw(url, imgPath, width, height, wait, minSize, tries) {