gfw-api/gfw-area

View on GitHub

Showing 126 of 126 total issues

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

        if (body.iso) {
            iso.country = body.iso ? body.iso.country : null;
            iso.region = body.iso ? body.iso.region : null;
        }
Severity: Major
Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
app/src/routes/api/v2/area.router.js on lines 404..407

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

        if (body.use) {
            use.id = body.use ? body.use.id : null;
            use.name = body.use ? body.use.name : null;
        }
Severity: Major
Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
app/src/routes/api/v2/area.router.js on lines 410..413

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

Function update has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async update(ctx) {
        logger.info(`Updating area with id ${ctx.params.id}`);
        const area = await AreaModel.findById(ctx.params.id);
        const { files } = ctx.request;
        if (ctx.request.body.application || !area.application) {
Severity: Minor
Found in app/src/routes/api/v1/area.router.js - About 1 hr to fix

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

    module.exports = (() => {
    
        const loadAPI = (app, path, pathApi) => {
            const routesFiles = fs.readdirSync(path);
            let existIndexRouter = false;
    Severity: Minor
    Found in app/src/loader.js - About 1 hr to fix

      Function get has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async get(ctx) {
              logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
      
              if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                  ctx.throw(404, 'Area not found');
      Severity: Minor
      Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

        Function getRequestBodyForSubscriptionFromArea has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static getRequestBodyForSubscriptionFromArea(area) {
                const body = {
                    name: area.name,
                    datasets: SubscriptionsService.getDatasetsForSubscription(area),
                    language: area.language,
        Severity: Minor
        Found in app/src/services/subscription.service.js - About 1 hr to fix

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

              static async get(ctx) {
                  logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
          
                  if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                      ctx.throw(404, 'Area not found');
          Severity: Minor
          Found in app/src/routes/api/v2/area.router.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 saveArea has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              static async saveArea(ctx, userId) {
                  logger.info('Saving area');
                  let image = '';
                  if (ctx.request.files && ctx.request.files.image && ctx.request.files.image.s3Url) {
                      image = ctx.request.files.image.s3Url;
          Severity: Minor
          Found in app/src/routes/api/v1/area.router.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 groupPoints has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              static groupPoints(dataViirs, dataGlad, precisionBbox) {
                  logger.debug('Group points', ' and precisionBbox ', precisionBbox);
                  const result = {};
                  if (dataViirs) {
                      for (let i = 0, { length } = dataViirs; i < length; i++) {
          Severity: Minor
          Found in app/src/services/alerts.service.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 groupPoints has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static groupPoints(dataViirs, dataGlad, precisionBbox) {
                  logger.debug('Group points', ' and precisionBbox ', precisionBbox);
                  const result = {};
                  if (dataViirs) {
                      for (let i = 0, { length } = dataViirs; i < length; i++) {
          Severity: Minor
          Found in app/src/services/alerts.service.js - About 1 hr to fix

            Function update has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async update(ctx, next) {
                    logger.debug('Validating body for update area');
                    ctx.checkBody('name').optional().len(2, 100);
                    ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
            
            
            Severity: Minor
            Found in app/src/validators/area.validatorV2.js - About 1 hr to fix

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

                  static async deleteByUserId(ctx) {
                      logger.info(`Deleting areas of user with id ${ctx.params.userId}`);
                      const userIdToDelete = ctx.params.userId;
              
                      try {
              Severity: Minor
              Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

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

                    static async delete(ctx) {
                        logger.info(`Deleting area with id ${ctx.params.id}`);
                        const areaToDelete = await AreaModel.findById(ctx.params.id);
                        if (areaToDelete) {
                            if (areaToDelete.subscriptionId) {
                Severity: Minor
                Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

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

                      static getFilteredQuery(query, ids = []) {
                          const areaAttributes = Object.keys(Area.schema.obj);
                          logger.debug(`[getFilteredQuery] areaAttributes: ${areaAttributes}`);
                          Object.keys(query).forEach((param) => {
                              if (areaAttributes.indexOf(param) < 0) {
                  Severity: Minor
                  Found in app/src/services/area.service.js - About 1 hr to fix

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

                        static async create(ctx, next) {
                            logger.debug('Validating body for create area');
                            ctx.checkBody('name').notEmpty().len(1, 100);
                            ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
                    
                    
                    Severity: Minor
                    Found in app/src/validators/area.validatorV2.js - About 1 hr to fix

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

                              try {
                                  await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
                              } catch (error) {
                                  ctx.throw(404, `User ${userIdToDelete} does not exist`);
                              }
                      Severity: Major
                      Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                      app/src/routes/api/v1/area.router.js on lines 235..239

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

                      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

                              try {
                                  await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
                              } catch (error) {
                                  ctx.throw(404, `User ${userIdToDelete} does not exist`);
                              }
                      Severity: Major
                      Found in app/src/routes/api/v1/area.router.js and 1 other location - About 1 hr to fix
                      app/src/routes/api/v2/area.router.js on lines 551..555

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

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

                          const loadAPI = (app, path, 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 saveArea has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            static async saveArea(ctx, userId) {
                                logger.info('Saving area');
                                let image = '';
                                if (ctx.request.files && ctx.request.files.image && ctx.request.files.image.s3Url) {
                                    image = ctx.request.files.image.s3Url;
                        Severity: Minor
                        Found in app/src/routes/api/v1/area.router.js - About 1 hr to fix

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

                              } else if (ctx.request.body.fields && ctx.request.body.fields.loggedUser) {
                                  ctx.state.loggedUser = JSON.parse(ctx.request.body.fields.loggedUser);
                                  delete ctx.request.body.loggedUser;
                              }
                          Severity: Major
                          Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                          app/src/routes/api/v1/area.router.js on lines 281..287

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

                          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