gfw-api/gfw-subscription-api

View on GitHub

Showing 76 of 129 total issues

Function runSubscriptionQuery has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    static async runSubscriptionQuery(subscription, queryType) {
        logger.info('Iterate over datasetsQuery of each subs');
        const queryData = [];
        for (let j = 0; j < subscription.datasetsQuery.length; j++) {
            try {
Severity: Minor
Found in app/src/services/datasetService.js - About 1 day 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

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

const Router = require('koa-router');
const UrlService = require('services/urlService');
const logger = require('logger');
const moment = require('moment');
const mongoose = require('mongoose');
Severity: Minor
Found in app/src/routes/api/v1/subscription.router.js - About 5 hrs to fix

    Function transformAndSaveData has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    const transformAndSaveData = async (data) => {
        logger.info('Saving data');
        if (data) {
            for (let i = 0, { length } = data; i < length; i++) {
                if (data[i].confirmed) {
    Severity: Minor
    Found in app/src/migrate/migrate.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 runSubscriptionQuery has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async runSubscriptionQuery(subscription, queryType) {
            logger.info('Iterate over datasetsQuery of each subs');
            const queryData = [];
            for (let j = 0; j < subscription.datasetsQuery.length; j++) {
                try {
    Severity: Major
    Found in app/src/services/datasetService.js - About 4 hrs to fix

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

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

        File datasetService.js has 311 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        /* eslint-disable no-continue */
        const Subscription = require('models/subscription');
        const ctRegisterMicroservice = require('ct-register-microservice-node');
        const MailService = require('services/mailService');
        const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
        Severity: Minor
        Found in app/src/services/datasetService.js - About 3 hrs to fix

          Function pathFor has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
          Open

              static pathFor(subscription, layerSlug) {
                  const params = subscription.params || {};
          
                  if (layerSlug === 'story') {
                      if (params.iso && params.iso.country) {
          Severity: Minor
          Found in app/src/services/analysisClassifier.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 onDbReady has 82 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async function onDbReady(mongoConnectionError) {
                      if (mongoConnectionError) {
                          if (retries >= 0) {
                              retries--;
                              logger.error(`Failed to connect to MongoDB uri ${mongoUri}, retrying...`);
          Severity: Major
          Found in app/src/app.js - About 3 hrs to fix

            Function infoGroupSubscriptions has 79 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async infoGroupSubscriptions(startDate, endDate, application) {
                    logger.debug(`Obtaining group subscriptions with startDate ${startDate}, endDate ${endDate} and application ${application}`);
                    const filter = {
                        createdAt: { $gte: startDate, $lt: endDate },
                        datasets: { $ne: [] },
            Severity: Major
            Found in app/src/services/statisticsService.js - About 3 hrs to fix

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

              module.exports = (() => {
                  const loadAPI = (app, path = routersPath, pathApi) => {
                      const routesFiles = fs.readdirSync(path);
                      let existIndexRouter = false;
                      routesFiles.forEach((file) => {
              Severity: Major
              Found in app/src/loader.js - About 2 hrs to fix

                Function transformAndSaveData has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const transformAndSaveData = async (data) => {
                    logger.info('Saving data');
                    if (data) {
                        for (let i = 0, { length } = data; i < length; i++) {
                            if (data[i].confirmed) {
                Severity: Major
                Found in app/src/migrate/migrate.js - About 2 hrs to fix

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

                      static async transform(results, layer, subscription, begin, end) {
                          EmailHelpersService.updateMonthTranslations();
                          moment.locale(subscription.language || 'en');
                  
                          try {
                  Severity: Major
                  Found in app/src/presenters/monthlySummaryPresenter.js - About 2 hrs to fix

                    Function processMessage has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        static async processMessage(channel, message) {
                            logger.info('[AlertQueue] Processing alert message');
                            logger.debug(`[AlertQueue] Processing alert message: ${message}`);
                    
                            if (JSON.parse(message).layer_slug === 'dataset') {
                    Severity: Major
                    Found in app/src/queues/alert.queue.js - About 2 hrs to fix

                      Function exports has 53 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

                        Consider simplifying this complex logical expression.
                        Open

                                    if (data[i].confirmed) {
                                        //  logger.debug('Saving data', data[i]);
                                        let userId = null;
                                        if (data[i].user_id) {
                                            userId = await obtainNewUserId(data[i].user_id);
                        Severity: Critical
                        Found in app/src/migrate/migrate.js - About 2 hrs to fix

                          Function getGeostoreIdByArea has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              static async getGeostoreIdByArea(idArea) {
                                  try {
                                      logger.info('Obtaining area with id: ', idArea);
                                      const areaResult = await ctRegisterMicroservice.requestToMicroservice({
                                          uri: `/area/${idArea}`,
                          Severity: Minor
                          Found in app/src/services/datasetService.js - About 1 hr to fix

                            Function getBBoxQuery has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            async function getBBoxQuery(client, subscription) {
                                if (subscription.params.iso && subscription.params.iso.country) {
                                    if (!subscription.params.iso.region) {
                            
                                        const data = await executeThunk(client, geoQuery.ISO_BBOX, {
                            Severity: Minor
                            Found in app/src/services/imageService.js - About 1 hr to fix

                              Function translateFrequency has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  static translateFrequency(status, lang = 'en') {
                                      const translationsMap = {
                                          en: {
                                              'unusually high': 'unusually high',
                                              high: 'high',
                              Severity: Minor
                              Found in app/src/services/emailHelpersService.js - About 1 hr to fix

                                Function getQuery has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                async function getQuery(subscription) {
                                    if (subscription.params.iso && subscription.params.iso.country) {
                                        if (!subscription.params.iso.region) {
                                            return Mustache.render(geoQuery.ISO, {
                                                iso: subscription.params.iso.country
                                Severity: Minor
                                Found in app/src/services/imageService.js - About 1 hr to fix

                                  Function getGeostoreIdByArea has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      static async getGeostoreIdByArea(idArea) {
                                          try {
                                              logger.info('Obtaining area with id: ', idArea);
                                              const areaResult = await ctRegisterMicroservice.requestToMicroservice({
                                                  uri: `/area/${idArea}`,
                                  Severity: Minor
                                  Found in app/src/services/datasetService.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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language