resource-watch/vocabulary-tag

View on GitHub

Showing 111 of 111 total issues

Function getRelationships has 93 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async getRelationships(vocabularies, apiKey, query = {}) {
        logger.info(`Getting relationships of vocabularies: ${vocabularies}`);

        let datasetIds = [];
        let layerIds = [];
Severity: Major
Found in app/src/services/relationship.service.js - About 3 hrs to fix

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

            if (ctx.request.body.application) {
                if (ctx.request.body.loggedUser.extraUserData.apps.indexOf(ctx.request.body.application) <= -1) {
                    ctx.throw(403, 'Forbidden');
                }
            } else {
    Severity: Major
    Found in app/src/validators/collection.validator.js and 1 other location - About 3 hrs to fix
    app/src/validators/favourite.validator.js on lines 20..26

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

    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 (ctx.request.body.application) {
                if (ctx.request.body.loggedUser.extraUserData.apps.indexOf(ctx.request.body.application) <= -1) {
                    ctx.throw(403, 'Forbidden');
                }
            } else {
    Severity: Major
    Found in app/src/validators/favourite.validator.js and 1 other location - About 3 hrs to fix
    app/src/validators/collection.validator.js on lines 36..42

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

    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 createAssociation(resource, tags, application, apiKey) {
            logger.info('[GraphService]: Associating tags in the graph db');
            let association;
            try {
                // weird construct needed to wait for any potential exception
    Severity: Major
    Found in app/src/services/graph.service.js and 1 other location - About 3 hrs to fix
    app/src/services/graph.service.js on lines 91..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 103.

    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 updateAssociation(resource, tags, application, apiKey) {
            logger.info('[GraphService]: Associating tags in the graph db');
            let association;
            try {
                // weird construct needed to wait for any potential exception
    Severity: Major
    Found in app/src/services/graph.service.js and 1 other location - About 3 hrs to fix
    app/src/services/graph.service.js on lines 74..89

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

    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 relationship.service.js has 298 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const logger = require('logger');
    const VocabularyService = require('services/vocabulary.service');
    const ResourceService = require('services/resource.service');
    const GraphService = require('services/graph.service');
    const RelationshipDuplicated = require('errors/relationship-duplicated.error');
    Severity: Minor
    Found in app/src/services/relationship.service.js - About 3 hrs to fix

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

              for (let i = 0, { length } = resource.vocabularies; i < length; i++) {
                  if (resource.vocabularies[i].id === vocabulary.id && resource.vocabularies[i].application === pVocabulary.application) {
                      position = i;
                      break;
                  }
      Severity: Major
      Found in app/src/services/relationship.service.js and 1 other location - About 3 hrs to fix
      app/src/services/relationship.service.js on lines 135..140

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

      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

              for (let i = 0, { length } = vocabulary.resources; i < length; i++) {
                  if (vocabulary.resources[i].type === resource.type && vocabulary.resources[i].id === resource.id) {
                      position = i;
                      break;
                  }
      Severity: Major
      Found in app/src/services/relationship.service.js and 1 other location - About 3 hrs to fix
      app/src/services/relationship.service.js on lines 158..163

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

      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 getAll has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          static async getAll(user, apiKey, query = {}) {
              logger.info(`[CollectionService - getAll]: Getting all collections`);
              const sort = query.sort || '';
              const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
              const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 9999999;
      Severity: Minor
      Found in app/src/services/collection.service.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

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

          static async get(resource, pQuery) {
              logger.debug(`Getting resources by vocabulary-tag`);
              const application = pQuery.application || pQuery.app;
              const query = VocabularyService.getQuery(pQuery);
              let vocabularies = Object.keys(query).map((vocabularyName) => Vocabulary.aggregate([
      Severity: Major
      Found in app/src/services/vocabulary.service.js - About 2 hrs to fix

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

        module.exports = (grunt) => {
        
            grunt.file.setBase('..');
            require('load-grunt-tasks')(grunt);
        
        
        Severity: Major
        Found in app/Gruntfile.js - About 2 hrs to fix

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

          const relationshipValidationMiddleware = async (ctx, next) => {
              try {
                  await RelationshipValidator.validate(ctx);
              } catch (err) {
                  if (err instanceof RelationshipNotValid) {
          Severity: Major
          Found in app/src/routes/api/v1/vocabulary.router.js and 2 other locations - About 2 hrs to fix
          app/src/routes/api/v1/vocabulary.router.js on lines 428..439
          app/src/routes/api/v1/vocabulary.router.js on lines 442..453

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

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

          const relationshipsValidationMiddleware = async (ctx, next) => {
              try {
                  await RelationshipsValidator.validate(ctx);
              } catch (err) {
                  if (err instanceof RelationshipsNotValid) {
          Severity: Major
          Found in app/src/routes/api/v1/vocabulary.router.js and 2 other locations - About 2 hrs to fix
          app/src/routes/api/v1/vocabulary.router.js on lines 414..425
          app/src/routes/api/v1/vocabulary.router.js on lines 442..453

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

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

          const vocabularyValidationMiddleware = async (ctx, next) => {
              try {
                  await VocabularyValidator.validate(ctx);
              } catch (err) {
                  if (err instanceof VocabularyNotValid) {
          Severity: Major
          Found in app/src/routes/api/v1/vocabulary.router.js and 2 other locations - About 2 hrs to fix
          app/src/routes/api/v1/vocabulary.router.js on lines 414..425
          app/src/routes/api/v1/vocabulary.router.js on lines 428..439

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

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

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

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

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

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

                      Object.keys(body).forEach((key) => {
                          if (key !== 'loggedUser') {
                              vocabularies.push({
                                  name: key,
                                  application: body[key].application,
              Severity: Major
              Found in app/src/routes/api/v1/vocabulary.router.js and 1 other location - About 2 hrs to fix
              app/src/routes/api/v1/vocabulary.router.js on lines 240..248

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

              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

                      Object.keys(body).forEach((key) => {
                          if (key !== 'loggedUser') {
                              vocabularies.push({
                                  name: key,
                                  application: body[key].application,
              Severity: Major
              Found in app/src/routes/api/v1/vocabulary.router.js and 1 other location - About 2 hrs to fix
              app/src/routes/api/v1/vocabulary.router.js on lines 195..203

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

              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 validationMiddleware = async (ctx, next) => {
                  logger.info(`[DatasetRouter] Validating`);
                  try {
                      await FavouriteValidator.validate(ctx);
                  } catch (err) {
              Severity: Major
              Found in app/src/routes/api/v1/favourite.router.js and 1 other location - About 2 hrs to fix
              app/src/routes/api/v1/collection.router.js on lines 210..218

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

              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 validationMiddleware = async (ctx, next) => {
                  logger.info(`[CollectionRouter] Validating`);
                  try {
                      await CollectionValidator.validate(ctx);
                  } catch (err) {
              Severity: Major
              Found in app/src/routes/api/v1/collection.router.js and 1 other location - About 2 hrs to fix
              app/src/routes/api/v1/favourite.router.js on lines 221..229

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

              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