Showing 122 of 2,019 total issues
Function facebookAuth
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function facebookAuth (req, profile, token) {
var usr;
return models.User.findOne({ where: { 'facebook_id' : profile.id } }).then(function(user) {
if (user === null) {
if (!('emails' in profile) || profile.emails.length === 0) {
Function parseAnswersFromPost
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function parseAnswersFromPost(req, questions, oldAnswers) {
var answers = [];
oldAnswers = oldAnswers || null;
for (var i = 1, iLen = questions.length; i<=iLen; i++) {
var question = questions[i-1];
Function saveFileFromPath
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
saveFileFromPath: function(srcPath, dstPath, fileName, defaultMime) {
var cleanDstPath = dstPath;
while(cleanDstPath.charAt(0) === path.sep) {
cleanDstPath = cleanDstPath.substr(1);
}
Function googleAuth
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function googleAuth (req, profile, token) {
var usr;
return models.User.findOne({ where: { 'google_id' : profile.id } }).then(function(user) {
if (user === null) {
// If we don't find it by google id, we try by email
Function saveFileFromBuffer
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
saveFileFromBuffer: function(buffer, dstPath, fileName, defaultMime) {
var cleanDstPath = dstPath;
while(cleanDstPath.charAt(0) === path.sep) {
cleanDstPath = cleanDstPath.substr(1);
}
Function getAnsweredSurveysWithAllDates
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
User.prototype.getAnsweredSurveysWithAllDates = function() {
var userId = this.id;
return Promise.reduce(this.getVotes({
include: [
{
Function getLegend
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
Survey.prototype.getLegend = function() {
var survey = this;
return this.getQuestions({
scope: 'includeAnswers'
}).then(function(questions) {
Function transform
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
transform: function(result) {
// First line is always the header, which doesn't need transforming
if (results.indexOf(result) === 0) {
return result;
}
Function exports
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
Open
module.exports = function(app) {
FileHelper = {
saveFileFromBuffer: function(buffer, dstPath, fileName, defaultMime) {
var cleanDstPath = dstPath;
- 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 checkValidAnswersFromPost
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function checkValidAnswersFromPost(req, questions) {
var answers = [];
for (var i = 1, iLen = questions.length; i<=iLen; i++) {
var question = questions[i-1];
switch(question.type) {
Function exports
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = function(sequelize, DataTypes) {
var Answer = sequelize.define('Answer', {
id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
answer: { type: DataTypes.STRING, allowNull: false },
img: { type: DataTypes.BLOB },
Function getFiltersSQL
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function getFiltersSQL(getFilters, questions) {
var sqls = [],
params = {};
if (getFilters) {
for (var param in getFilters) {
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
Open
if ((body.emapic_experience_comments && body.emapic_experience_comments !== 'null') ||
(body.emapic_experience_final_position_reason && body.emapic_experience_final_position_reason !== 'null') ||
(body.emapic_experience_geolocation_result && body.emapic_experience_geolocation_result !== 'null')) {
var strquery = 'INSERT INTO metadata.emapic_opinions (browser_os, geolocation_result, final_position_reason, comments, geom, "timestamp", accuracy) VALUES (?, ?, ?, ?, ST_SetSRID(ST_MakePoint(?, ?), 4326), now(), ?)',
precision = parseFloat(body.precision);
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
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)) ||
Consider simplifying this complex logical expression. Open
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)) ||