mysociety/popit-api

View on GitHub

Showing 97 of 97 total issues

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

module.exports = function(app) {

  app.delete('/:collection/:id/image', function (req, res, next) {
    var id = req.params.id;

Severity: Major
Found in src/routes/image.js - About 1 day to fix

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

        async.concatSeries(docs, function(doc, callback) {
          doc.toElasticsearch(function(err, result) {
            if (err) {
              return callback(err);
            }
    Severity: Major
    Found in src/mongoose/elasticsearch.js and 1 other location - About 1 day to fix
    src/mongoose/elasticsearch.js on lines 201..231

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

    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

          async.concatSeries(docs, function(doc, callback) {
            doc.toElasticsearch(function(err, result) {
              if (err) {
                return callback(err);
              }
    Severity: Major
    Found in src/mongoose/elasticsearch.js and 1 other location - About 1 day to fix
    src/mongoose/elasticsearch.js on lines 257..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 204.

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

    function elasticsearchPlugin(schema) {
    
      /**
       * Convert the document into a format suitable for indexing in
       * Elasticsearch. This uses the toJSON transform option to remove
    Severity: Major
    Found in src/mongoose/elasticsearch.js - About 7 hrs to fix

      Function esFilters has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function esFilters() {
        return {
          esFilter: function esFilter(doc, ret, options) {
            if (!doc) {
              return;
      Severity: Minor
      Found in src/esfilter.js - About 5 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

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

            if ( body.images ) {
              var images = [];
              body.images.forEach( function(img) {
                if (img.id) {
                  img._id = new mongoose.Types.ObjectId(img.id);
      Severity: Major
      Found in src/routes/1.0/document.put.js and 1 other location - About 5 hrs to fix
      src/routes/document.put.js on lines 36..47

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

      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 ( body.images ) {
              var images = [];
              body.images.forEach( function(img) {
                if (img.id) {
                  img._id = new mongoose.Types.ObjectId(img.id);
      Severity: Major
      Found in src/routes/document.put.js and 1 other location - About 5 hrs to fix
      src/routes/1.0/document.put.js on lines 40..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 144.

      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

            }, function(err) {
              if (err) {
                return next(err);
              }
      
      
      Severity: Major
      Found in src/routes/collection.get.js and 1 other location - About 4 hrs to fix
      src/routes/1.0/collection.get.js on lines 18..34

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

      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

            }, function(err) {
              if (err) {
                return next(err);
              }
      
      
      Severity: Major
      Found in src/routes/1.0/collection.get.js and 1 other location - About 4 hrs to fix
      src/routes/collection.get.js on lines 18..34

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

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

      function embedPlugin(schema) {
      
        /**
         * Taked the ?embed parameter and embeds any people, organizations or
         * memberships that have been requested.
      Severity: Major
      Found in src/mongoose/embed.js - About 4 hrs to fix

        Function embedDocuments has 102 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          schema.methods.embedDocuments = function embedDocuments(req, newEmbedNames, callback) {
            if (typeof newEmbedNames === 'function') {
              callback = newEmbedNames;
              newEmbedNames = false;
            }
        Severity: Major
        Found in src/mongoose/embed.js - About 4 hrs to fix

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

          module.exports = function(app) {
          
            app.put('/:collection/:id(*)', validateBody, function (req, res, next) {
          
              var id = req.params.id;
          Severity: Major
          Found in src/routes/1.0/document.put.js - About 3 hrs to fix

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

                  }, function(err) {
                    if (err) {
                      return next(err);
                    }
            
            
            Severity: Major
            Found in src/routes/search.js and 1 other location - About 3 hrs to fix
            src/routes/1.0/search.js on lines 29..40

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

            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

                  }, function(err) {
                    if (err) {
                      return next(err);
                    }
            
            
            Severity: Major
            Found in src/routes/1.0/search.js and 1 other location - About 3 hrs to fix
            src/routes/search.js on lines 29..40

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

            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

              app.use(function(err, req, res, next) {
                // This should always be an error, but jshint complains if we don't use all
                // arguments and express will only interpret this as an error handler if
                // the arity is 4.
                if (!err) {
            Severity: Major
            Found in src/versions/0.1.js and 1 other location - About 2 hrs to fix
            src/versions/1.0.0.js on lines 30..39

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

            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

              app.use(function(err, req, res, next) {
                // This should always be an error, but jshint complains if we don't use all
                // arguments and express will only interpret this as an error handler if
                // the arity is 4.
                if (!err) {
            Severity: Major
            Found in src/versions/1.0.0.js and 1 other location - About 2 hrs to fix
            src/versions/0.1.js on lines 31..40

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

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

            module.exports = function(app) {
              // Export all languages - can potentially produce invalid popolo
              app.get('/export.json', function(req, res, next) {
                exporter(req.db, req, function(err, exportObject) {
                  if (err) {
            Severity: Major
            Found in src/routes/export.js - About 2 hrs to fix

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

                } else if ( req.model.modelName == 'Organization' ) {
                  if ( !membership.organization_id ) {
                    membership.organization_id = doc.id;
                  } else if ( membership.organization_id != doc.id ) {
                    return done("organization id (" + membership.organization_id + ") in membership and organization id (" + doc.id + ") are mismatched");
              Severity: Major
              Found in src/inline-memberships.js and 2 other locations - About 2 hrs to fix
              src/inline-memberships.js on lines 62..80
              src/inline-memberships.js on lines 74..80

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

              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

                if ( req.model.modelName == 'Person' ) {
                  if ( !membership.person_id ) {
                    membership.person_id = doc.id;
                  } else if ( membership.person_id != doc.id ) {
                    return done("person id (" + membership.person_id + ") in membership and person id (" + doc.id + ") are mismatched");
              Severity: Major
              Found in src/inline-memberships.js and 2 other locations - About 2 hrs to fix
              src/inline-memberships.js on lines 68..80
              src/inline-memberships.js on lines 74..80

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

              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

                } else if ( req.model.modelName == 'Post' ) {
                  if ( !membership.post_id ) {
                    membership.post_id = doc.id;
                  } else if ( membership.post_id != doc.id ) {
                    return done("post id (" + membership.post_id + ") in membership and post id (" + doc.id + ") are mismatched");
              Severity: Major
              Found in src/inline-memberships.js and 2 other locations - About 2 hrs to fix
              src/inline-memberships.js on lines 62..80
              src/inline-memberships.js on lines 68..80

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

              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