NationalMuseumofDenmark/natmus-samlinger

View on GitHub

Showing 35 of 35 total issues

Function thumbnail has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.thumbnail = function(req, res, next) {
  const size = req.params.size || null;
  return documentController.get(req, 'object').then(metadata => {
    // Filter out related assets without an id
    const relatedAssets = (
Severity: Minor
Found in controllers/types/object.js - About 1 hr to fix

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

    module.exports = (metadata) => {
      if(metadata.date) {
        Object.keys(metadata.date).forEach(function(type) {
          var dateInterval = metadata.date[type];
          if(dateInterval) {
    Severity: Minor
    Found in natmus-indexing/derive-timestamps.js - About 1 hr to fix

      Function documentTitle has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      helpers.documentTitle = (metadata, fallback) => {
        let title;
        let type;
      
        if (metadata.type === 'asset') {
      Severity: Minor
      Found in shared/helpers.js - About 55 mins 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 cleanDocumentId has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      helpers.cleanDocumentId = (id, fallbackCollection, asObject) => {
        let result = {};
      
        const match = documentIdRegExp.exec(id);
        if(match) {
      Severity: Minor
      Found in shared/helpers.js - About 45 mins 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 mapAssetValue has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function mapAssetValue(asset) {
        let baseName = '';
      
        if (asset.filename) {
          baseName = asset.filename;
      Severity: Minor
      Found in services/metadata-transforms/sort-related-assets.js - About 35 mins 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 generateSizeDownloadOption has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function generateSizeDownloadOption(optionKey, option) {
        return {
          label: metadata => {
            let dimensions = getFileDimensionsString(metadata, option.size);
            return option.labelPrefix + ' (' + dimensions + ') JPEG';
      Severity: Minor
      Found in shared/helpers.js - About 35 mins 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

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

        const relatedAssets = (
          (metadata.related && metadata.related.assets) || []
        ).filter(asset => asset.id);
      Severity: Minor
      Found in shared/helpers.js and 1 other location - About 35 mins to fix
      controllers/types/object.js on lines 86..88

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

      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 relatedAssets = (
            metadata.related && metadata.related.assets || []
          ).filter(asset => asset.id);
      Severity: Minor
      Found in controllers/types/object.js and 1 other location - About 35 mins to fix
      shared/helpers.js on lines 110..112

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

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

            new MenuItem.model({
              title: 'Hjælp',
              page: pages['hjaelp']._id,
              placement: 'main',
              order: 3
      Severity: Major
      Found in updates/0.0.3-pages-and-menu-items.js and 4 other locations - About 30 mins to fix
      updates/0.0.3-pages-and-menu-items.js on lines 54..59
      updates/0.0.3-pages-and-menu-items.js on lines 60..65
      updates/0.0.3-pages-and-menu-items.js on lines 85..90
      updates/0.0.3-pages-and-menu-items.js on lines 91..96

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

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

            new MenuItem.model({
              title: 'Om Nationalmuseets Samlinger Online',
              page: pages['om-os']._id,
              placement: 'main',
              order: 4
      Severity: Major
      Found in updates/0.0.3-pages-and-menu-items.js and 4 other locations - About 30 mins to fix
      updates/0.0.3-pages-and-menu-items.js on lines 54..59
      updates/0.0.3-pages-and-menu-items.js on lines 60..65
      updates/0.0.3-pages-and-menu-items.js on lines 79..84
      updates/0.0.3-pages-and-menu-items.js on lines 91..96

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

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

            new MenuItem.model({
              title: 'Kontakt',
              page: pages['kontakt']._id,
              placement: 'footer',
              order: 3
      Severity: Major
      Found in updates/0.0.3-pages-and-menu-items.js and 4 other locations - About 30 mins to fix
      updates/0.0.3-pages-and-menu-items.js on lines 54..59
      updates/0.0.3-pages-and-menu-items.js on lines 79..84
      updates/0.0.3-pages-and-menu-items.js on lines 85..90
      updates/0.0.3-pages-and-menu-items.js on lines 91..96

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

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

            new MenuItem.model({
              title: 'Kontakt',
              page: pages['kontakt']._id,
              placement: 'main',
              order: 5
      Severity: Major
      Found in updates/0.0.3-pages-and-menu-items.js and 4 other locations - About 30 mins to fix
      updates/0.0.3-pages-and-menu-items.js on lines 54..59
      updates/0.0.3-pages-and-menu-items.js on lines 60..65
      updates/0.0.3-pages-and-menu-items.js on lines 79..84
      updates/0.0.3-pages-and-menu-items.js on lines 85..90

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

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

            new MenuItem.model({
              title: 'Rettigheder og brug',
              page: pages['rettigheder-og-brug']._id,
              placement: 'footer',
              order: 2
      Severity: Major
      Found in updates/0.0.3-pages-and-menu-items.js and 4 other locations - About 30 mins to fix
      updates/0.0.3-pages-and-menu-items.js on lines 60..65
      updates/0.0.3-pages-and-menu-items.js on lines 79..84
      updates/0.0.3-pages-and-menu-items.js on lines 85..90
      updates/0.0.3-pages-and-menu-items.js on lines 91..96

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

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

        proxy: (req, res, next) => {
          let index = req.params.index || 'all';
          let action = req.params.action;
      
          if(index !== 'all') {
      Severity: Minor
      Found in controllers/api.js - About 25 mins 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 about has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        about: (req, metadata) => {
          if (metadata.type === 'asset') {
            const mediaTypes = helpers.determineMediaTypes(metadata);
            if (mediaTypes.indexOf('image') >= 0) {
              const relative = helpers.getThumbnailURL(metadata, 1280);
      Severity: Minor
      Found in shared/helpers.js - About 25 mins 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

      Severity
      Category
      Status
      Source
      Language