NationalMuseumofDenmark/natmus-samlinger

View on GitHub

Showing 35 of 35 total issues

File helpers.js has 499 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const _ = require('lodash');
const moment = require('moment');

const config = require('collections-online/lib/config');
const helpers = require('collections-online/shared/helpers');
Severity: Minor
Found in shared/helpers.js - About 1 day to fix

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

    module.exports = function(done) {
      var pages = [
        new Page.model({
          title: 'Om os',
          slug: 'om-os',
    Severity: Major
    Found in updates/0.0.3-pages-and-menu-items.js - About 3 hrs to fix

      Function determinePlayers has 74 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      helpers.determinePlayers = metadata => {
        const players = [];
        // Get at list of related assets and filter out any without an id
        const relatedAssets = (
          (metadata.related && metadata.related.assets) || []
      Severity: Major
      Found in shared/helpers.js - About 2 hrs to fix

        File natmus-api.js has 282 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        'use strict';
        
        const assert = require('assert');
        const querystring = require('querystring');
        const Q = require('q');
        Severity: Minor
        Found in services/natmus-api.js - About 2 hrs to fix

          Function determinePlayers has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

          helpers.determinePlayers = metadata => {
            const players = [];
            // Get at list of related assets and filter out any without an id
            const relatedAssets = (
              (metadata.related && metadata.related.assets) || []
          Severity: Minor
          Found in shared/helpers.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 typeaheadSuggestions has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports.typeaheadSuggestions = (text) => {
            const ds = require('collections-online/lib/services/documents');
            return ds.search({
              'size': 0,
              'body': {
          Severity: Major
          Found in controllers/motif-tagging.js - About 2 hrs to fix

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

                  hits.forEach((hit) => {
                    // Insert
                    actions.push({
                      index: {
                        _index: toIndex,
            Severity: Major
            Found in es-indexing/index.js and 1 other location - About 2 hrs to fix
            natmus-indexing/index.js on lines 75..86

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 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

                hits.forEach((hit) => {
                  // Insert
                  actions.push({
                    index: {
                      _index: index,
            Severity: Major
            Found in natmus-indexing/index.js and 1 other location - About 2 hrs to fix
            es-indexing/index.js on lines 51..63

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

            function run(esHost, fromIndex, toIndex) {
              console.log('Hello from es-indexing');
            
              var es = new elasticsearch.Client({
                host: esHost,
            Severity: Major
            Found in es-indexing/index.js - About 2 hrs to fix

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

                removeTag: (metadata, tag) => {
                  // Is it there?
                  const tagIndex = metadata.tags.crowd.indexOf(tag);
                  if(tagIndex > -1) {
                    // Remove it
              Severity: Major
              Found in shared/helpers.js and 1 other location - About 1 hr to fix
              shared/helpers.js on lines 450..457

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

              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

                removeVisionTag: (metadata, tag) => {
                  // Is it there?
                  const tagIndex = metadata.tags.automated.indexOf(tag);
                  if(tagIndex > -1) {
                    // Remove it
              Severity: Major
              Found in shared/helpers.js and 1 other location - About 1 hr to fix
              shared/helpers.js on lines 442..449

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

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

                mget: (options) => {
                  if(!options.type) {
                    throw new Error('Expected a "type"');
                  }
                  if(!options.body || !options.body.ids) {
              Severity: Minor
              Found in services/natmus-api.js - About 1 hr to fix

                Function getMoreUntilDone has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  }, function getMoreUntilDone(error, response) {
                    if(error) {
                      console.error(error);
                    }
                    // collect the title from each response
                Severity: Minor
                Found in es-indexing/index.js - About 1 hr to fix

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

                  module.exports = function(done) {
                    var as = new GalleryItem.model({
                      title: 'Antiksamlingen',
                      description: '...',
                      link: '/?collection=AS'
                  Severity: Minor
                  Found in updates/0.0.2-galleries.js - About 1 hr to fix

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

                    function getObject(req) {
                      let deferred = Q.defer();
                      let id = req.params.id;
                      let collection = req.params.collection;
                    
                    
                    Severity: Minor
                    Found in controllers/types/object.js - About 1 hr to fix

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

                        getSource: (options) => {
                          if(options.index) {
                            console.warn('Calling the document service with index is not supported');
                          }
                          let type = options.type;
                      Severity: Minor
                      Found in services/natmus-api.js - About 1 hr to fix

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

                        function transformAndInsert(hits, index) {
                          // collect the title from each response
                          return Q.all(hits.map(function (hit) {
                            return TRANSFORMATIONS.reduce(Q.when, hit.data).then((metadata) => {
                              let type = (hit.meta.type || '').toLowerCase();
                        Severity: Minor
                        Found in natmus-indexing/index.js - About 1 hr to fix

                          Function generateSitemapElements has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          helpers.generateSitemapElements = (req, metadata) => {
                            const title = helpers.documentTitle(metadata);
                            const description = helpers.documentDescription(metadata);
                            const relativeThumbnailUrl = helpers.getThumbnailURL(metadata);
                            const thumbnailUrl = helpers.getAbsoluteURL(req, relativeThumbnailUrl);
                          Severity: Minor
                          Found in shared/helpers.js - About 1 hr to fix

                            Function pollForChange has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              pollForChange: (type, collectionAndId) => {
                                const key = type + '/' + collectionAndId;
                                // Start polling the index for changes, based on the meta.modified field
                                const startedPolling = new Date();
                                let interval;
                            Severity: Minor
                            Found in services/natmus-api.js - About 1 hr to fix

                              Function AVAILABLE_DOWNLOAD_OPTIONS has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                .map(optionKey => {
                                  const option = config.downloadOptions[optionKey];
                              
                                  if(option.size) {
                                    return generateSizeDownloadOption(optionKey, option);
                              Severity: Minor
                              Found in shared/helpers.js - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language