Emapic/emapic

View on GitHub

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)) ||
Severity: Critical
Found in routes/api-engine_routes.js - About 1 hr to fix

    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;
    Severity: Minor
    Found in models/survey.js - About 1 hr to fix

      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>';
                      }
      Severity: Minor
      Found in utils.js - About 1 hr to fix

        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),
        Severity: Minor
        Found in models/survey.js - About 1 hr to fix

          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', '')) ||
          Severity: Critical
          Found in routes/utils_api.js - About 1 hr to fix

            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) ||
            Severity: Critical
            Found in routes/api-engine_routes.js - About 1 hr to fix

              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) {
              Severity: Minor
              Found in server.js - About 1 hr to fix

                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']];
                Severity: Minor
                Found in models/user.js - About 1 hr to fix

                  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);
                  Severity: Minor
                  Found in models/survey.js - About 1 hr to fix

                    Function generateExclusiveBtnAnswerHtml has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function generateExclusiveBtnAnswerHtml(answer, layout, question) {
                        var btnClass,
                            divClass,
                            btnContent,
                            style = '';
                    Severity: Minor
                    Found in models/question.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 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 &&
                    Severity: Minor
                    Found in models/question.js - About 1 hr to fix

                      Function takeSnapshot has 9 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              takeSnapshot: function(url, imgPath, nativeWidth, nativeHeight, wait, minSize, retries, imgWidth, imgHeight) {
                      Severity: Major
                      Found in utils.js - About 1 hr to fix

                        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 = [];
                        Severity: Minor
                        Found in models/survey.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 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',
                        Severity: Minor
                        Found in models/survey.js - About 1 hr to fix

                          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) {
                          Severity: Minor
                          Found in models/survey.js - About 1 hr to fix

                            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/', '');
                            Severity: Minor
                            Found in utils.js - About 1 hr to fix

                              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) {
                              Severity: Minor
                              Found in models/question.js - About 1 hr to fix

                                Function findSurveys has 8 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    Survey.findSurveys = function(userId, onlyPublic, status, query, tag, order, pageSize, pageNr) {
                                Severity: Major
                                Found in models/survey.js - About 1 hr to fix

                                  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;
                                  
                                  
                                  Severity: Minor
                                  Found in routes/auth/index.js - About 55 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

                                  Function takeSnapshotRaw has 7 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  function takeSnapshotRaw(url, imgPath, width, height, wait, minSize, tries) {
                                  Severity: Major
                                  Found in utils.js - About 50 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language