File dicomElementsWrapper.js
has 754 lines of code (exceeds 250 allowed). Consider refactoring. Open
import {
DicomParser,
getTransferSyntaxName
} from './dicomParser';
import {
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
- Read upRead up
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
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
- Read upRead up
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)
Function getDecayedDose
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
function getDecayedDose(elements) {
let warning = '';
let warn;
// SeriesDate (type1)
- Read upRead up
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
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');
- Read upRead up
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');
Consider simplifying this complex logical expression. Open
} else if (isOtherVR ||
dicomElement.vr === 'pi' ||
dicomElement.vr === 'UL' ||
dicomElement.vr === 'US' ||
dicomElement.vr === 'SL' ||
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();
- Read upRead up
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();
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) {
- Read upRead up
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';
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)';
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'];
- Read upRead up
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;
}
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';
- Read upRead up
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) {
- Read upRead up
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;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (typeof dirSeq[i]['00041500'] === 'undefined' ||
typeof dirSeq[i]['00041500'].value === 'undefined') {
continue;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76