gfw-api/gfw-subscription-api

View on GitHub

Showing 76 of 129 total issues

Function getTask has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const getTask = async (task) => {
    logger.info(`[cronLoader] Publishing ${task.dataset}`);
    if (task.dataset === 'dataset') {
        redisClient.publish(CHANNEL, JSON.stringify({
            layer_slug: task.dataset
Severity: Minor
Found in app/src/cronLoader.js - About 1 hr to fix

    Function getTopSubscriptions has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async getTopSubscriptions(startDate, endDate, application) {
            logger.debug(`Obtaining getTopSubscriptions with startDate ${startDate}, endDate ${endDate} and application ${application}`);
            const topSubs = {};
            const defaultFilter = {
                createdAt: { $gte: startDate, $lt: endDate },
    Severity: Minor
    Found in app/src/services/statisticsService.js - About 1 hr to fix

      Function pathFor has 37 lines of code (exceeds 25 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 1 hr to fix

        Function getGeostoreIdByParams has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async getGeostoreIdByParams(params) {
                try {
                    let uri = '/geostore';
                    if (params.use && params.useid) {
                        uri += `/use/${params.use}/${params.useid}`;
        Severity: Minor
        Found in app/src/services/datasetService.js - About 1 hr to fix

          Function checkUpdated has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static async checkUpdated(dataset) {
                  logger.info(`Checking if dataset ${dataset} was updated`);
                  try {
                      const result = await ctRegisterMicroservice.requestToMicroservice({
                          uri: `/${dataset}/latest`,
          Severity: Minor
          Found in app/src/services/updateService.js - About 1 hr to fix

            Function getGeostoreIdByParams has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                static async getGeostoreIdByParams(params) {
                    try {
                        let uri = '/geostore';
                        if (params.use && params.useid) {
                            uri += `/use/${params.use}/${params.useid}`;
            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

            Function execute has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async execute(subscription, layerSlug, begin, end, forSubscription) {
            
                    logger.info('Executing analysis for', layerSlug, begin, end);
            
                    const period = `${formatDate(begin)},${formatDate(end)}`;
            Severity: Minor
            Found in app/src/services/analysisService.js - About 1 hr to fix

              Function generate has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static generate(subscription, layer, begin, end) {
                      const diffInDays = moment(begin).diff(moment(end), 'days');
              
                      const queryForUrl = {
                          lang: subscription.language || 'en',
              Severity: Minor
              Found in app/src/services/alertUrlService.js - About 1 hr to fix

                Function infoSubscriptions has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async infoSubscriptions(startDate, endDate, application) {
                        logger.debug(`Obtaining infoSubscriptions with startDate ${startDate}, endDate ${endDate} and application ${application}`);
                        const info = {};
                
                        const defaultFilter = {
                Severity: Minor
                Found in app/src/services/statisticsService.js - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                                  if (
                                      !data[i].params.iso
                                      && !data[i].params.id1
                                      && !data[i].params.wdpaid
                                      && !data[i].params.use
                  Severity: Critical
                  Found in app/src/migrate/migrate.js - About 1 hr to fix

                    Function transform has 33 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: Minor
                    Found in app/src/presenters/viirsPresenter.js - About 1 hr to fix

                      Function transform has 33 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: Minor
                      Found in app/src/presenters/gladPresenter.js - About 1 hr to fix

                        Function loadAPI has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            const loadAPI = (app, path = routersPath, pathApi) => {
                                const routesFiles = fs.readdirSync(path);
                                let existIndexRouter = false;
                                routesFiles.forEach((file) => {
                                    const newPath = path ? (`${path}/${file}`) : file;
                        Severity: Minor
                        Found in app/src/loader.js - About 1 hr to fix

                          Function overviewImage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              async overviewImage(subscription, slug, begin, end) {
                                  const query = await getQuery(subscription);
                                  if (!query) {
                                      return null;
                                  }
                          Severity: Minor
                          Found in app/src/services/imageService.js - About 1 hr to fix

                            Function processMessage has a Cognitive Complexity of 10 (exceeds 5 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: Minor
                            Found in app/src/queues/alert.queue.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 decorateWithArea has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                            const decorateWithArea = (results, subscription) => {
                                const params = subscription.params || {};
                            
                                if (params.iso && params.iso.country) {
                                    results.selected_area = `ISO Code: ${params.iso.country}`;
                            Severity: Minor
                            Found in app/src/presenters/analysisResultsPresenter.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 transform has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                static async transform(results) {
                                    results.alert_count = results.value;
                                    let uri = `/query${results.downloadUrls.csv.split('download')[1]}`;
                                    uri = uri.replace('ORDER BY year, day', ' ORDER BY day DESC, year DESC LIMIT 10').replace(/&format=(csv|json|xml)/g, '');
                            
                            
                            Severity: Minor
                            Found in app/src/presenters/terraiPresenter.js - About 1 hr to fix

                              Function findAllSubscriptions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  static async findAllSubscriptions(ctx) {
                                      logger.info(`[SubscriptionsRouter] Getting ALL subscriptions`);
                              
                                      const page = ctx.query.page && ctx.query.page.number ? parseInt(ctx.query.page.number, 10) : 1;
                                      const limit = ctx.query.page && ctx.query.page.size ? parseInt(ctx.query.page.size, 10) : 10;
                              Severity: Minor
                              Found in app/src/routes/api/v1/subscription.router.js - About 1 hr to fix

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

                                    static async transform(results, layer, subscription, begin, end) {
                                        const alerts = await analysisService.execute(subscription, layer.slug, begin, end, true);
                                        if (alerts && alerts.length && alerts.length > 0) {
                                            const alertsFormat = [];
                                            let length = 10;
                                Severity: Minor
                                Found in app/src/presenters/formaPresenter.js - About 1 hr to fix

                                  Function getBBoxOfGeojson has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function getBBoxOfGeojson(geojson) {
                                      const points = explode(geojson);
                                      let minx = 360;
                                      let
                                          miny = 360;
                                  Severity: Minor
                                  Found in app/src/services/imageService.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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language