zxing-js/library

View on GitHub
src/core/pdf417/decoder/PDF417ScanningDecoder.ts

Summary

Maintainability
F
5 days
Test Coverage
B
89%

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.
Severity: Minor
Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 7 hrs to fix

    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,
    Severity: Minor
    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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));
    Severity: Minor
    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 3 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 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;
    Severity: Minor
    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 3 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

    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;
    Severity: Minor
    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 3 hrs to fix

      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 {
      Severity: Minor
      Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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,
      Severity: Major
      Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 2 hrs to fix

        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,
        Severity: Minor
        Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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,
        Severity: Minor
        Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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;
        Severity: Minor
        Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 1 hr to fix

          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 {
          Severity: Minor
          Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 1 hr to fix

            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();
            Severity: Minor
            Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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,
            Severity: Minor
            Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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();
            Severity: Minor
            Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 1 hr to fix

              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,
              Severity: Minor
              Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 1 hr to fix

                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());
                Severity: Minor
                Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 (rowNumber >= 0) {
                              if (rowNumber >= barcodeMatrix.length) {
                                // We have more rows than the barcode metadata allows for, ignore them.
                                continue;
                              }
                Severity: Major
                Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 45 mins to fix

                  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);
                  Severity: Minor
                  Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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) {
                  Severity: Minor
                  Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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,
                  Severity: Minor
                  Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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

                  Avoid too many return statements within this function.
                  Open

                      return leftToRight ? detectionResult.getBoundingBox().getMinX() : detectionResult.getBoundingBox().getMaxX();
                  Severity: Major
                  Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - About 30 mins to fix

                    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();
                    Severity: Minor
                    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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 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) {
                    Severity: Minor
                    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts - 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

                      public static decode(image: BitMatrix,
                        imageTopLeft: ResultPoint,
                        imageBottomLeft: ResultPoint,
                        imageTopRight: ResultPoint,
                        imageBottomRight: ResultPoint,
                    Severity: Minor
                    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts and 1 other location - About 45 mins to fix
                    src/core/datamatrix/detector/Detector.ts on lines 308..337

                    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

                    Further Reading

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

                        if (PDF417ScanningDecoder.isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) {
                          codeword = detectionResult.getDetectionResultColumn(barcodeColumn - offset).getCodewordNearby(imageRow);
                        }
                    Severity: Minor
                    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts and 1 other location - About 35 mins to fix
                    src/core/pdf417/decoder/PDF417ScanningDecoder.ts on lines 450..452

                    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

                    Further Reading

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

                        if (PDF417ScanningDecoder.isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) {
                          codeword = detectionResult.getDetectionResultColumn(barcodeColumn - offset).getCodeword(imageRow);
                        }
                    Severity: Minor
                    Found in src/core/pdf417/decoder/PDF417ScanningDecoder.ts and 1 other location - About 35 mins to fix
                    src/core/pdf417/decoder/PDF417ScanningDecoder.ts on lines 460..462

                    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

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status