mysociety/popit-api

View on GitHub

Showing 97 of 97 total issues

Function esFilters has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function esFilters() {
  return {
    esFilter: function esFilter(doc, ret, options) {
      if (!doc) {
        return;
Severity: Major
Found in src/esfilter.js - About 2 hrs to fix

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

              if (err) {
                tidyUpInlineMembershipError(req, null, req.created_memberships, req.updated_memberships, function(innerErr) {
                  if ( innerErr ) {
                    return res.send(400, {errors: [innerErr]});
                  }
    Severity: Major
    Found in src/routes/1.0/document.put.js and 1 other location - About 2 hrs to fix
    src/routes/1.0/document.put.js on lines 86..94

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

    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 (err) {
                    tidyUpInlineMembershipError(req, null, req.created_memberships, req.updated_memberships, function(innerErr) {
                      if ( innerErr ) {
                        return res.send(400, {errors: [innerErr]});
                      }
    Severity: Major
    Found in src/routes/1.0/document.put.js and 1 other location - About 2 hrs to fix
    src/routes/1.0/document.put.js on lines 70..78

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

    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

    var mySocietySchemas = {
      "organization":               require('./popolo+mysociety/organization.json'),
      "person":                     require('./popolo+mysociety/person.json'),
      "membership":                 require('./popolo+mysociety/membership.json'),
      "post":                       require('./popolo+mysociety/post.json'),
    Severity: Major
    Found in schemas/index.js and 1 other location - About 2 hrs to fix
    schemas/index.js on lines 11..20

    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

    var popoloSchemas = {
      "contact_detail":             require('./popolo/contact_detail.json'),
      "identifier":                 require('./popolo/identifier.json'),
      "link":                       require('./popolo/link.json'),
      "membership":                 require('./popolo/membership.json'),
    Severity: Major
    Found in schemas/index.js and 1 other location - About 2 hrs to fix
    schemas/index.js on lines 22..31

    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

          doc.embedDocuments(req, true, function(err) {
            if (err instanceof InvalidEmbedError) {
              // Send a 400 error to indicate the client needs to alter their request
              return res.send(400, {errors: [err.message, err.explaination]});
            }
    Severity: Major
    Found in src/routes/1.0/document.get.js and 1 other location - About 2 hrs to fix
    src/routes/document.get.js on lines 37..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 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

          doc.embedDocuments(req, function(err) {
            if (err instanceof InvalidEmbedError) {
              // Send a 400 error to indicate the client needs to alter their request
              return res.send(400, {errors: [err.message, err.explaination]});
            }
    Severity: Major
    Found in src/routes/document.get.js and 1 other location - About 2 hrs to fix
    src/routes/1.0/document.get.js on lines 44..53

    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

    Function membershipFinder has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function membershipFinder(schema, options) {
    
      schema.methods.findMemberships = function findMemberships(callback) {
        var Membership = this.model('Membership');
        var modelName = this.constructor.modelName;
    Severity: Major
    Found in src/mongoose/membership-finder.js - About 2 hrs to fix

      Function setup has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function setup(app, options) {
        function importPopolo(req, res, next) {
          var queue = kue.createQueue({
            prefix: req.options.queuePrefix || 'popit-api-',
          });
      Severity: Major
      Found in src/routes/import.js - About 2 hrs to fix

        Function processMembership has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        function processMembership(membership, req, doc, done) {
          var existing = false;
          var Membership = req.db.model(models.memberships.modelName);
          async.waterfall([
            function callCheckMembership(cb) {
        Severity: Minor
        Found in src/inline-memberships.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 saveImagesMiddleware has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function saveImagesMiddleware(req, res, next) {
            function saveImages( doc, image, upload, dest_path, idx ) {
              var options = {};
              if ( typeof idx != 'undefined' ) {
                options = { clobber: true };
        Severity: Major
        Found in src/routes/image.js - About 2 hrs to fix

          Function saveImages has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function saveImages( doc, image, upload, dest_path, idx ) {
                var options = {};
                if ( typeof idx != 'undefined' ) {
                  options = { clobber: true };
                }
          Severity: Minor
          Found in src/routes/image.js - About 1 hr to fix

            Function toElasticsearch has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            MembershipSchema.methods.toElasticsearch = function(callback) {
              var Person = this.model('Person');
              var Organization = this.model('Organization');
              var Post = this.model('Post');
              var self = this;
            Severity: Minor
            Found in src/models.js - About 1 hr to fix

              Function processMembership has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function processMembership(membership, req, doc, done) {
                var existing = false;
                var Membership = req.db.model(models.memberships.modelName);
                async.waterfall([
                  function callCheckMembership(cb) {
              Severity: Minor
              Found in src/inline-memberships.js - About 1 hr to fix

                Function jsonSchemaFields has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                function jsonSchemaFields(jsonSchema) {
                  var fields = {};
                
                  for (var name in jsonSchema.properties) {
                    if (jsonSchema.properties.hasOwnProperty(name)) {
                Severity: Minor
                Found in src/mongoose/json-schema.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 i18n has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function i18n(objectWithLanguages, langs, defaultLang, includeTranslations) {
                  langs = langs || [];
                  includeTranslations = includeTranslations || false;
                  var obj = {};
                  // Detect keys that need translating
                Severity: Minor
                Found in src/i18n.js - About 1 hr to fix

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

                  module.exports = function(app) {
                  
                    /**
                     * Merge two people together.
                     *
                  Severity: Minor
                  Found in src/routes/merge.js - About 1 hr to fix

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

                    module.exports = exports = function mergePlugin(schema) {
                      schema.methods.merge = function merge(other, callback) {
                        var self = this;
                        var conflicts = [];
                        var pathsToMerge = Object.keys(other.toObject());
                    Severity: Minor
                    Found in src/mongoose/merge.js - About 1 hr to fix

                      Function exports has 42 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: Minor
                      Found in src/routes/document.put.js - About 1 hr to fix

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

                        module.exports = function(app) {
                        
                          app.post('/:collection', validateBody, function (req, res, next) {
                            var body = req.body;
                            // if there's an image and no body.images then add one as the popit front end uses
                        Severity: Minor
                        Found in src/routes/1.0/collection.post.js - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language