ivmartel/dwv

View on GitHub
src/dicom/dicomElementsWrapper.js

Summary

Maintainability
F
1 wk
Test Coverage

File dicomElementsWrapper.js has 754 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import {
  DicomParser,
  getTransferSyntaxName
} from './dicomParser';
import {
Severity: Major
Found in src/dicom/dicomElementsWrapper.js - About 1 day to fix

    Function getElementAsString has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

    function getElementAsString(tag, dicomElement, prefix) {
      // default prefix
      prefix = prefix || '';
    
      // get tag anme from dictionary
    Severity: Minor
    Found in src/dicom/dicomElementsWrapper.js - About 1 day 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 getElementAsString has 159 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function getElementAsString(tag, dicomElement, prefix) {
      // default prefix
      prefix = prefix || '';
    
      // get tag anme from dictionary
    Severity: Major
    Found in src/dicom/dicomElementsWrapper.js - About 6 hrs to fix

      Function getElementValueAsString has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

      function getElementValueAsString(tag, dicomElement, pretty) {
        let str = '';
        const strLenLimit = 65;
      
        // dafault to pretty output
      Severity: Minor
      Found in src/dicom/dicomElementsWrapper.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

      Function getDecayedDose has 139 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getDecayedDose(elements) {
        let warning = '';
        let warn;
      
        // SeriesDate (type1)
      Severity: Major
      Found in src/dicom/dicomElementsWrapper.js - About 5 hrs to fix

        Function getDecayedDose has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

        function getDecayedDose(elements) {
          let warning = '';
          let warn;
        
          // SeriesDate (type1)
        Severity: Minor
        Found in src/dicom/dicomElementsWrapper.js - About 4 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 getElementValueAsString has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function getElementValueAsString(tag, dicomElement, pretty) {
          let str = '';
          const strLenLimit = 65;
        
          // dafault to pretty output
        Severity: Major
        Found in src/dicom/dicomElementsWrapper.js - About 2 hrs to fix

          Function getDimensionOrganization has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          export function getDimensionOrganization(dataElements) {
            // Dimension Organization Sequence (required)
            const orgSq = dataElements['00209221'];
            if (typeof orgSq === 'undefined' || orgSq.value.length !== 1) {
              throw new Error('Unsupported dimension organization sequence length');
          Severity: Minor
          Found in src/dicom/dicomElementsWrapper.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 getDimensionOrganization has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function getDimensionOrganization(dataElements) {
            // Dimension Organization Sequence (required)
            const orgSq = dataElements['00209221'];
            if (typeof orgSq === 'undefined' || orgSq.value.length !== 1) {
              throw new Error('Unsupported dimension organization sequence length');
          Severity: Minor
          Found in src/dicom/dicomElementsWrapper.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                } else if (isOtherVR ||
                    dicomElement.vr === 'pi' ||
                    dicomElement.vr === 'UL' ||
                    dicomElement.vr === 'US' ||
                    dicomElement.vr === 'SL' ||
            Severity: Critical
            Found in src/dicom/dicomElementsWrapper.js - About 1 hr to fix

              Function getFileListFromDicomDir has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getFileListFromDicomDir(data) {
                // parse file
                const parser = new DicomParser();
                parser.parse(data);
                const elements = parser.getDicomElements();
              Severity: Minor
              Found in src/dicom/dicomElementsWrapper.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 getFileListFromDicomDir has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function getFileListFromDicomDir(data) {
                // parse file
                const parser = new DicomParser();
                parser.parse(data);
                const elements = parser.getDicomElements();
              Severity: Minor
              Found in src/dicom/dicomElementsWrapper.js - About 1 hr to fix

                Function checkTag has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                function checkTag(element, name, values) {
                  let warning = '';
                  if (typeof element === 'undefined') {
                    warning += ' ' + name + ' is undefined,';
                  } else if (element.value.length === 0) {
                Severity: Minor
                Found in src/dicom/dicomElementsWrapper.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 dcmdump has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function dcmdump(dicomElements) {
                  const keys = Object.keys(dicomElements);
                  let result = '\n';
                  result += '# Dicom-File-Format\n';
                  result += '\n';
                Severity: Minor
                Found in src/dicom/dicomElementsWrapper.js - About 1 hr to fix

                  Function getSuvFactor has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function getSuvFactor(elements) {
                    let warning = '';
                  
                    // CorrectedImage (type2): must contain ATTN and DECY
                    const corrImageTagStr = 'Corrected Image (00280051)';
                  Severity: Minor
                  Found in src/dicom/dicomElementsWrapper.js - About 1 hr to fix

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

                    export function getPixelUnit(elements) {
                      let unit;
                      // 1. RescaleType
                      // 2. Units (for PET)
                      const keys = ['00281054', '00541001'];
                    Severity: Minor
                    Found in src/dicom/dicomElementsWrapper.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

                    Avoid deeply nested control flow statements.
                    Open

                            if (dicomElement.vr === 'OB') {
                              tmp = '00'.substring(0, 2 - tmp.length) + tmp;
                            } else {
                              tmp = '0000'.substring(0, 4 - tmp.length) + tmp;
                            }
                    Severity: Major
                    Found in src/dicom/dicomElementsWrapper.js - About 45 mins to fix

                      Function dcmdump has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function dcmdump(dicomElements) {
                        const keys = Object.keys(dicomElements);
                        let result = '\n';
                        result += '# Dicom-File-Format\n';
                        result += '\n';
                      Severity: Minor
                      Found in src/dicom/dicomElementsWrapper.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 getTime has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function getTime(element) {
                        if (typeof element === 'undefined') {
                          return undefined;
                        }
                        if (element.value.length !== 1) {
                      Severity: Minor
                      Found in src/dicom/dicomElementsWrapper.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

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

                          if (typeof dirSeq[i]['00041430'] === 'undefined' ||
                            typeof dirSeq[i]['00041430'].value === 'undefined') {
                            continue;
                          }
                      Severity: Minor
                      Found in src/dicom/dicomElementsWrapper.js and 1 other location - About 35 mins to fix
                      src/dicom/dicomElementsWrapper.js on lines 1046..1049

                      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

                            if (typeof dirSeq[i]['00041500'] === 'undefined' ||
                              typeof dirSeq[i]['00041500'].value === 'undefined') {
                              continue;
                            }
                      Severity: Minor
                      Found in src/dicom/dicomElementsWrapper.js and 1 other location - About 35 mins to fix
                      src/dicom/dicomElementsWrapper.js on lines 1031..1034

                      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

                      There are no issues that match your filters.

                      Category
                      Status