File PDF417ScanningDecoder.ts
has 485 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*
* Copyright 2013 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Function decode
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public static decode(image: BitMatrix,
imageTopLeft: ResultPoint,
imageBottomLeft: ResultPoint,
imageTopRight: ResultPoint,
imageBottomRight: ResultPoint,
- 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 createBarcodeMatrix
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
private static createBarcodeMatrix(detectionResult: DetectionResult): BarcodeValue[][] {
// let barcodeMatrix: BarcodeValue[][] =
// new BarcodeValue[detectionResult.getBarcodeRowCount()][detectionResult.getBarcodeColumnCount() + 2];
let barcodeMatrix: BarcodeValue[][] =
Array.from({ length: detectionResult.getBarcodeRowCount() }, () => new Array(detectionResult.getBarcodeColumnCount() + 2));
- 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 getStartColumn
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private static getStartColumn(detectionResult: DetectionResult,
barcodeColumn: int,
imageRow: int,
leftToRight: boolean): int {
let offset: int = leftToRight ? 1 : -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
PDF417ScanningDecoder
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
export default /*public final*/ class PDF417ScanningDecoder {
/*final*/ static CODEWORD_SKEW_SIZE: int = 2;
/*final*/ static MAX_ERRORS: int = 3;
Function createDecoderResultFromAmbiguousValues
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
private static createDecoderResultFromAmbiguousValues(ecLevel: int,
codewords: Int32Array,
erasureArray: Int32Array,
ambiguousIndexes: Int32Array,
ambiguousIndexValues: Int32Array[]): DecoderResult {
- 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 decode
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static decode(image: BitMatrix,
imageTopLeft: ResultPoint,
imageBottomLeft: ResultPoint,
imageTopRight: ResultPoint,
imageBottomRight: ResultPoint,
Function getRowIndicatorColumn
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static getRowIndicatorColumn(image: BitMatrix,
boundingBox: BoundingBox,
startPoint: ResultPoint,
leftToRight: boolean,
minCodewordWidth: int,
- 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 getModuleBitCount
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static getModuleBitCount(image: BitMatrix,
minColumn: int,
maxColumn: int,
leftToRight: boolean,
startColumn: int,
- 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 getStartColumn
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static getStartColumn(detectionResult: DetectionResult,
barcodeColumn: int,
imageRow: int,
leftToRight: boolean): int {
let offset: int = leftToRight ? 1 : -1;
Function createDecoderResultFromAmbiguousValues
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static createDecoderResultFromAmbiguousValues(ecLevel: int,
codewords: Int32Array,
erasureArray: Int32Array,
ambiguousIndexes: Int32Array,
ambiguousIndexValues: Int32Array[]): DecoderResult {
Function adjustBoundingBox
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static adjustBoundingBox(rowIndicatorColumn: DetectionResultRowIndicatorColumn): BoundingBox {
if (rowIndicatorColumn == null) {
return null;
}
let rowHeights: Int32Array = rowIndicatorColumn.getRowHeights();
- 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 adjustCodewordStartColumn
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static adjustCodewordStartColumn(image: BitMatrix,
minColumn: int,
maxColumn: int,
leftToRight: boolean,
codewordStartColumn: int,
- 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 adjustBoundingBox
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static adjustBoundingBox(rowIndicatorColumn: DetectionResultRowIndicatorColumn): BoundingBox {
if (rowIndicatorColumn == null) {
return null;
}
let rowHeights: Int32Array = rowIndicatorColumn.getRowHeights();
Function detectCodeword
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static detectCodeword(image: BitMatrix,
minColumn: int,
maxColumn: int,
leftToRight: boolean,
startColumn: int,
Function createDecoderResult
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static createDecoderResult(detectionResult: DetectionResult): DecoderResult {
let barcodeMatrix: BarcodeValue[][] = PDF417ScanningDecoder.createBarcodeMatrix(detectionResult);
PDF417ScanningDecoder.adjustCodewordCount(detectionResult, barcodeMatrix);
let erasures /*Collection<Integer>*/ = new Array<number>();
let codewords: Int32Array = new Int32Array(detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount());
- 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 (rowNumber >= 0) {
if (rowNumber >= barcodeMatrix.length) {
// We have more rows than the barcode metadata allows for, ignore them.
continue;
}
Function toString
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static toString(barcodeMatrix: BarcodeValue[][]): String {
let formatter = new Formatter();
// try (let formatter = new Formatter()) {
for (let row /*int*/ = 0; row < barcodeMatrix.length; row++) {
formatter.format('Row %2d: ', row);
- 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 getBarcodeMetadata
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static getBarcodeMetadata(leftRowIndicatorColumn: DetectionResultRowIndicatorColumn,
rightRowIndicatorColumn: DetectionResultRowIndicatorColumn): BarcodeMetadata {
let leftBarcodeMetadata: BarcodeMetadata;
if (leftRowIndicatorColumn == null ||
(leftBarcodeMetadata = leftRowIndicatorColumn.getBarcodeMetadata()) == null) {
- 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 detectCodeword
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static detectCodeword(image: BitMatrix,
minColumn: int,
maxColumn: int,
leftToRight: boolean,
startColumn: int,
- 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 too many return
statements within this function. Open
return leftToRight ? detectionResult.getBoundingBox().getMinX() : detectionResult.getBoundingBox().getMaxX();
Function verifyCodewordCount
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static verifyCodewordCount(codewords: Int32Array, numECCodewords: int): void {
if (codewords.length < 4) {
// Codeword array size should be at least 4 allowing for
// Count CW, At least one Data CW, Error Correction CW, Error Correction CW
throw FormatException.getFormatInstance();
- 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 getBitCountForCodeword
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static getBitCountForCodeword(codeword: int): Int32Array {
let result: Int32Array = new Int32Array(8);
let previousValue: int = 0;
let i: int = result.length - 1;
while (true) {
- 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
public static decode(image: BitMatrix,
imageTopLeft: ResultPoint,
imageBottomLeft: ResultPoint,
imageTopRight: ResultPoint,
imageBottomRight: ResultPoint,
- 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 50.
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 (PDF417ScanningDecoder.isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) {
codeword = detectionResult.getDetectionResultColumn(barcodeColumn - offset).getCodewordNearby(imageRow);
}
- 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 47.
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 (PDF417ScanningDecoder.isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) {
codeword = detectionResult.getDetectionResultColumn(barcodeColumn - offset).getCodeword(imageRow);
}
- 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 47.
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