gfw-api/gfw-forma-alerts-api

View on GitHub

Showing 25 of 25 total issues

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

        if (geostore) {
            if (forSubscription && data.rows) {
                return data.rows;
            }
            if (data.rows && data.rows.length > 0) {
Severity: Major
Found in src/services/cartoDBService.ts and 3 other locations - About 4 hrs to fix
src/services/cartoDBService.ts on lines 137..151
src/services/cartoDBService.ts on lines 170..184
src/services/cartoDBService.ts on lines 235..249

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

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 4 locations. Consider refactoring.
Open

        if (geostore) {
            if (forSubscription && data.rows) {
                return data.rows;
            }
            if (data.rows && data.rows.length > 0) {
Severity: Major
Found in src/services/cartoDBService.ts and 3 other locations - About 4 hrs to fix
src/services/cartoDBService.ts on lines 137..151
src/services/cartoDBService.ts on lines 203..217
src/services/cartoDBService.ts on lines 235..249

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

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 4 locations. Consider refactoring.
Open

        if (geostore) {
            if (forSubscription && data.rows) {
                return data.rows;
            }
            if (data.rows && data.rows.length > 0) {
Severity: Major
Found in src/services/cartoDBService.ts and 3 other locations - About 4 hrs to fix
src/services/cartoDBService.ts on lines 170..184
src/services/cartoDBService.ts on lines 203..217
src/services/cartoDBService.ts on lines 235..249

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

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 4 locations. Consider refactoring.
Open

        if (geostore) {
            if (forSubscription && data.rows) {
                return data.rows;
            }
            if (data.rows && data.rows.length > 0) {
Severity: Major
Found in src/services/cartoDBService.ts and 3 other locations - About 4 hrs to fix
src/services/cartoDBService.ts on lines 137..151
src/services/cartoDBService.ts on lines 170..184
src/services/cartoDBService.ts on lines 203..217

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

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

        const data: Record<string, any> | void = await CartoDBService.getNational(
            ctx.params.iso,
            ctx.request.query.forSubscription as string,
            ctx.request.query.period as string,
            ctx.request.headers['x-api-key'] as string
Severity: Major
Found in src/routes/formaAlerts.router.ts and 1 other location - About 2 hrs to fix
src/routes/formaAlerts.router.ts on lines 81..86

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

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

        const data: Record<string, any> | void = await CartoDBService.getWdpa(
            ctx.params.id,
            ctx.request.query.forSubscription as string,
            ctx.request.query.period as string,
            ctx.request.headers['x-api-key'] as string
Severity: Major
Found in src/routes/formaAlerts.router.ts and 1 other location - About 2 hrs to fix
src/routes/formaAlerts.router.ts on lines 17..22

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

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 init has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const init: () => Promise<IInit> = async (): Promise<IInit> => {
    return new Promise((resolve: (value: IInit | PromiseLike<IInit>) => void
    ) => {

        const app: Koa = new Koa();
Severity: Major
Found in src/app.ts - About 2 hrs to fix

    File cartoDBService.ts has 262 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import config from 'config';
    import logger from 'logger';
    import Mustache from 'mustache';
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    Severity: Minor
    Found in src/services/cartoDBService.ts - About 2 hrs to fix

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

          static async getGeostoreByUse(useTable: string, id: string, apiKey: string): Promise<Record<string, any>> {
              logger.debug('Getting geostore by use');
              return await GeostoreService.getGeostore(`use/${useTable}/${id}`, apiKey);
          }
      Severity: Major
      Found in src/services/geostoreService.ts and 1 other location - About 2 hrs to fix
      src/services/geostoreService.ts on lines 38..41

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

      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

          static async getGeostoreByIsoAndId(iso: string, id1: string, apiKey: string): Promise<Record<string, any>> {
              logger.debug('Getting geostore by iso and region');
              return await GeostoreService.getGeostore(`admin/${iso}/${id1}`, apiKey);
          }
      Severity: Major
      Found in src/services/geostoreService.ts and 1 other location - About 2 hrs to fix
      src/services/geostoreService.ts on lines 43..46

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

      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

          static async getGeostoreByIso(iso: string, apiKey: string): Promise<Record<string, any>> {
              logger.debug('Getting geostore by iso');
              return await GeostoreService.getGeostore(`admin/${iso}`, apiKey);
          }
      Severity: Major
      Found in src/services/geostoreService.ts and 1 other location - About 1 hr to fix
      src/services/geostoreService.ts on lines 48..51

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

      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

          static async getGeostoreByWdpa(wdpaid: string, apiKey: string): Promise<Record<string, any>> {
              logger.debug('Getting geostore by use');
              return await GeostoreService.getGeostore(`wdpa/${wdpaid}`, apiKey);
          }
      Severity: Major
      Found in src/services/geostoreService.ts and 1 other location - About 1 hr to fix
      src/services/geostoreService.ts on lines 33..36

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

      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

          return `${today.getFullYear().toString()}-${(today.getMonth() + 1).toString()}-${today.getDate().toString()}`;
      Severity: Major
      Found in src/services/cartoDBService.ts and 1 other location - About 1 hr to fix
      src/services/cartoDBService.ts on lines 75..75

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

      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

          return `${yesterday.getFullYear().toString()}-${(yesterday.getMonth() + 1).toString()}-${yesterday.getDate().toString()}`;
      Severity: Major
      Found in src/services/cartoDBService.ts and 1 other location - About 1 hr to fix
      src/services/cartoDBService.ts on lines 70..70

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

      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 use has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async use(ctx: Context): Promise<void> {
              logger.info('Obtaining use data with name %s and id %s', ctx.params.name, ctx.params.id);
              let useTable: string = null;
              switch (ctx.params.name) {
      
      
      Severity: Minor
      Found in src/routes/formaAlerts.router.ts - About 1 hr to fix

        Function getSubnational has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async getSubnational(iso: string, id1: string, forSubscription: string, period: string = defaultDate(), apiKey: string): Promise<Record<string, any> | void> {
                logger.debug('Obtaining subnational of iso %s and id1', iso, id1);
                const periods: string[] = period.split(',');
                const params: { iso: any; id1: any; end: string; begin: string } = {
                    iso,
        Severity: Minor
        Found in src/services/cartoDBService.ts - About 1 hr to fix

          Function getUse has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async getUse(useName: string, useTable: string, id: string, forSubscription: string, period: string = defaultDate(), apiKey: string): Promise<Record<string, any> | void> {
                  logger.debug('Obtaining use with id %s', id);
                  const periods: string[] = period.split(',');
                  const params: { pid: any; end: string; useTable: any; begin: string } = {
                      useTable,
          Severity: Minor
          Found in src/services/cartoDBService.ts - About 1 hr to fix

            Function getNational has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async getNational(iso: string, forSubscription: string, period: string = defaultDate(), apiKey: string): Promise<Record<string, any> | void> {
                    logger.debug('Obtaining national of iso %s', iso);
                    const periods: string[] = period.split(',');
                    const params: { iso: string; end: string; begin: string } = {
                        iso,
            Severity: Minor
            Found in src/services/cartoDBService.ts - About 1 hr to fix

              Function getWdpa has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async getWdpa(wdpaid: string, forSubscription: string, period: string = defaultDate(), apiKey: string): Promise<Record<string, any> | void> {
                      logger.debug('Obtaining wpda of id %s', wdpaid);
                      const periods: string[] = period.split(',');
                      const params: { end: string; begin: string; wdpaid: any } = {
                          wdpaid,
              Severity: Minor
              Found in src/services/cartoDBService.ts - About 1 hr to fix

                Function getWorldWithGeojson has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    async getWorldWithGeojson(geojson: Record<string, any>, forSubscription: string, period: string = defaultDate(), areaHa: string = null): Promise<Record<string, any> | void> {
                        logger.debug('Executing query in cartodb with geojson', geojson);
                        const periods: string[] = period.split(',');
                        const params: { geojson: string; end: string; begin: string } = {
                            geojson: JSON.stringify(geojson.features[0].geometry),
                Severity: Minor
                Found in src/services/cartoDBService.ts - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language