gfw-api/gfw-forms-api

View on GitHub

Showing 63 of 63 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

function* loggedUserToState(next) {
    if (this.query && this.query.loggedUser) {
        this.state.loggedUser = JSON.parse(this.query.loggedUser);
        delete this.query.loggedUser;
    } else if (this.request.body && (this.request.body.loggedUser || (this.request.body.fields && this.request.body.fields.loggedUser))) {
Severity: Major
Found in app/src/routes/api/v1/questionnaireAnswer.router.js and 1 other location - About 1 day to fix
app/src/routes/api/v1/answers.router.js on lines 176..193

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 329.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

function* loggedUserToState(next) {
    if (this.query && this.query.loggedUser) {
        this.state.loggedUser = JSON.parse(this.query.loggedUser);
        delete this.query.loggedUser;
    } else if (this.request.body && (this.request.body.loggedUser || (this.request.body.fields && this.request.body.fields.loggedUser))) {
Severity: Major
Found in app/src/routes/api/v1/answers.router.js and 1 other location - About 1 day to fix
app/src/routes/api/v1/questionnaireAnswer.router.js on lines 110..127

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 329.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

function* loggedUserToState(next) {
    if (this.query && this.query.loggedUser) {
        this.state.loggedUser = JSON.parse(this.query.loggedUser);
        delete this.query.loggedUser;
    } else if (this.request.body && this.request.body.loggedUser) {
Severity: Major
Found in app/src/routes/api/v1/reports.router.js and 1 other location - About 6 hrs to fix
app/src/routes/api/v1/questionnaire.router.js on lines 103..115

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 174.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

function* loggedUserToState(next) {
    if (this.query && this.query.loggedUser) {
        this.state.loggedUser = JSON.parse(this.query.loggedUser);
        delete this.query.loggedUser;
    } else if (this.request.body && this.request.body.loggedUser) {
Severity: Major
Found in app/src/routes/api/v1/questionnaire.router.js and 1 other location - About 6 hrs to fix
app/src/routes/api/v1/reports.router.js on lines 411..423

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 174.

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

Further Reading

File reports.router.js has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const Router = require('koa-router');
const logger = require('logger');
const ReportsSerializer = require('serializers/reportsSerializer');
const ReportsModel = require('models/reportsModel');
const ReportsValidator = require('validators/reportsValidator');
Severity: Minor
Found in app/src/routes/api/v1/reports.router.js - About 5 hrs to fix

    Function save has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        static* save() {
            logger.info('Saving answer');
            logger.debug(this.request.body);
    
            const { fields } = this.request.body;
    Severity: Minor
    Found in app/src/routes/api/v1/answers.router.js - About 4 hrs 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 save has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        static* save() {
            logger.info('Saving questionnaire');
            logger.debug(this.request.body);
    
            const answer = {
    Severity: Minor
    Found in app/src/routes/api/v1/questionnaireAnswer.router.js - About 4 hrs 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 create has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        static* create(next) {
            const request = this.request.body;
            logger.debug('Validating body for create template');
            this.checkBody('name').notEmpty();
            this.checkBody('questions').notEmpty();
    Severity: Minor
    Found in app/src/validators/reportsValidator.js - About 3 hrs 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 downloadAnswers has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static* downloadAnswers() {
            logger.info(`Downloading answers for report ${this.params.id}`);
            this.set('Content-disposition', `attachment; filename=${this.params.id}.csv`);
            this.set('Content-type', 'text/csv');
            this.body = passThrough();
    Severity: Major
    Found in app/src/routes/api/v1/reports.router.js - About 3 hrs to fix

      Function init has 81 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function init() {
          return new Promise((resolve, reject) => {
              async function onDbReady(err) {
                  if (err) {
                      if (retries >= 0) {
      Severity: Major
      Found in app/src/app.js - About 3 hrs to fix

        Function exports has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = (grunt) => {
        
            grunt.file.setBase('..');
            // eslint-disable-next-line import/no-extraneous-dependencies
            require('load-grunt-tasks')(grunt);
        Severity: Major
        Found in app/Gruntfile.js - About 2 hrs to fix

          Function onDbReady has 71 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async function onDbReady(err) {
                      if (err) {
                          if (retries >= 0) {
                              // eslint-disable-next-line no-plusplus
                              retries--;
          Severity: Major
          Found in app/src/app.js - About 2 hrs to fix

            Function patch has 70 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static* patch() {
                    logger.info(`Updating template with id ${this.params.id}...`);
            
                    const reportFilter = {
                        $and: [
            Severity: Major
            Found in app/src/routes/api/v1/reports.router.js - About 2 hrs to fix

              Function save has 70 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static* save() {
                      logger.info('Saving answer');
                      logger.debug(this.request.body);
              
                      const { fields } = this.request.body;
              Severity: Major
              Found in app/src/routes/api/v1/answers.router.js - About 2 hrs to fix

                Function create has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static* create(next) {
                        const request = this.request.body;
                        logger.debug('Validating body for create template');
                        this.checkBody('name').notEmpty();
                        this.checkBody('questions').notEmpty();
                Severity: Major
                Found in app/src/validators/reportsValidator.js - About 2 hrs to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  function* mapTemplateParamToId(next) {
                      if (this.params.id === config.get('legacyTemplateId') || this.params.id === 'default') {
                          this.params.id = config.get('defaultTemplateId');
                      }
                      yield next;
                  Severity: Major
                  Found in app/src/routes/api/v1/reports.router.js and 1 other location - About 2 hrs to fix
                  app/src/routes/api/v1/answers.router.js on lines 232..237

                  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 80.

                  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

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  function* mapTemplateParamToId(next) {
                      if (this.params.reportId === config.get('legacyTemplateId') || this.params.reportId === 'default') {
                          this.params.reportId = config.get('defaultTemplateId');
                      }
                      yield next;
                  Severity: Major
                  Found in app/src/routes/api/v1/answers.router.js and 1 other location - About 2 hrs to fix
                  app/src/routes/api/v1/reports.router.js on lines 404..409

                  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 80.

                  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

                  Further Reading

                  Function patch has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                      static* patch() {
                          logger.info(`Updating template with id ${this.params.id}...`);
                  
                          const reportFilter = {
                              $and: [
                  Severity: Minor
                  Found in app/src/routes/api/v1/reports.router.js - About 2 hrs 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

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                  function* queryToState(next) {
                      if (this.request.query && Object.keys(this.request.query).length > 0) {
                          this.state.query = this.request.query;
                      }
                      yield next;
                  Severity: Major
                  Found in app/src/routes/api/v1/answers.router.js and 1 other location - About 2 hrs to fix
                  app/src/routes/api/v1/reports.router.js on lines 425..430

                  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 75.

                  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

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          if (request.languages.length > 1) {
                              if (!request.defaultLanguage || request.languages.indexOf(request.defaultLanguage) === -1) {
                                  pushError('languages', `Languages: values do not match language options`);
                              }
                          }
                  Severity: Major
                  Found in app/src/validators/reportsValidator.js and 1 other location - About 2 hrs to fix
                  app/src/validators/reportsValidator.js on lines 102..106

                  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 75.

                  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

                  Further Reading

                  Severity
                  Category
                  Status
                  Source
                  Language