zxing-js/library

View on GitHub
src/core/datamatrix/detector/Detector.ts

Summary

Maintainability
D
3 days
Test Coverage
A
96%

File Detector.ts has 262 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import BitMatrix from '../../common/BitMatrix';
import WhiteRectangleDetector from '../../common/detector/WhiteRectangleDetector';
import DetectorResult from '../../common/DetectorResult';
import GridSamplerInstance from '../../common/GridSamplerInstance';
import NotFoundException from '../../NotFoundException';
Severity: Minor
Found in src/core/datamatrix/detector/Detector.ts - About 2 hrs to fix

    Function transitionsBetween has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

      private transitionsBetween(from: ResultPoint, to: ResultPoint): int {
        // See QR Code Detector, sizeOfBlackWhiteBlackRun()
        let fromX = Math.trunc(from.getX());
        let fromY = Math.trunc(from.getY());
        let toX = Math.trunc(to.getX());
    Severity: Minor
    Found in src/core/datamatrix/detector/Detector.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 transitionsBetween has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private transitionsBetween(from: ResultPoint, to: ResultPoint): int {
        // See QR Code Detector, sizeOfBlackWhiteBlackRun()
        let fromX = Math.trunc(from.getX());
        let fromY = Math.trunc(from.getY());
        let toX = Math.trunc(to.getX());
    Severity: Minor
    Found in src/core/datamatrix/detector/Detector.ts - About 1 hr to fix

      Function shiftToModuleCenter has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private shiftToModuleCenter(points: ResultPoint[]): ResultPoint[] {
          // A..D
          // |  :
          // B--C
          let pointA = points[0];
      Severity: Minor
      Found in src/core/datamatrix/detector/Detector.ts - About 1 hr to fix

        Function correctTopRight has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private correctTopRight(points: ResultPoint[]): ResultPoint {
            // A..D
            // |  :
            // B--C
            let pointA = points[0];
        Severity: Minor
        Found in src/core/datamatrix/detector/Detector.ts - About 1 hr to fix

          Function detectSolid1 has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private detectSolid1(cornerPoints: ResultPoint[]): ResultPoint[] {
              // 0  2
              // 1  3
              let pointA = cornerPoints[0];
              let pointB = cornerPoints[1];
          Severity: Minor
          Found in src/core/datamatrix/detector/Detector.ts - About 1 hr to fix

            Function detect has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public detect(): DetectorResult {
            
            
                const cornerPoints = this.rectangleDetector.detect();
            
            
            Severity: Minor
            Found in src/core/datamatrix/detector/Detector.ts - About 1 hr to fix

              Avoid too many return statements within this function.
              Open

                    return candidate2;
              Severity: Major
              Found in src/core/datamatrix/detector/Detector.ts - About 30 mins to fix

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

                  private correctTopRight(points: ResultPoint[]): ResultPoint {
                    // A..D
                    // |  :
                    // B--C
                    let pointA = points[0];
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.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

                    let candidate1 = new ResultPoint(
                      pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1),
                      pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1));
                Severity: Major
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 2 hrs to fix
                src/core/datamatrix/detector/Detector.ts on lines 225..227

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

                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

                      let candidate2 = new ResultPoint(
                      pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1),
                      pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1));
                Severity: Major
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 2 hrs to fix
                src/core/datamatrix/detector/Detector.ts on lines 222..224

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

                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 (min > trBC) {
                      min = trBC;
                      points[0] = pointA;
                      points[1] = pointB;
                      points[2] = pointC;
                Severity: Major
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 1 hr to fix
                src/core/datamatrix/detector/Detector.ts on lines 144..150

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

                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 (min > trCD) {
                      min = trCD;
                      points[0] = pointB;
                      points[1] = pointC;
                      points[2] = pointD;
                Severity: Major
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 1 hr to fix
                src/core/datamatrix/detector/Detector.ts on lines 137..143

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

                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

                    let centerX = (pointA.getX() + pointB.getX() + pointC.getX() + pointD.getX()) / 4;
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 45 mins to fix
                src/core/datamatrix/detector/Detector.ts on lines 282..282

                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

                  private static sampleGrid(image: BitMatrix,
                                                      topLeft: ResultPoint,
                                                      bottomLeft: ResultPoint,
                                                      bottomRight: ResultPoint,
                                                      topRight: ResultPoint,
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 45 mins to fix
                src/core/pdf417/decoder/PDF417ScanningDecoder.ts on lines 97..170

                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

                    let centerY = (pointA.getY() + pointB.getY() + pointC.getY() + pointD.getY()) / 4;
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 45 mins to fix
                src/core/datamatrix/detector/Detector.ts on lines 281..281

                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

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

                    if (steep) {
                      let temp = fromX;
                      fromX = fromY;
                      fromY = temp;
                      temp = toX;
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 40 mins to fix
                src/core/qrcode/detector/Detector.ts on lines 315..322

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

                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 (trBA < trCD) {
                      // solid sides: A-B-C
                      points[0] = pointA;
                      points[1] = pointB;
                      points[2] = pointC;
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 40 mins to fix
                src/core/datamatrix/detector/Detector.ts on lines 190..196

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

                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

                    } else {
                      // solid sides: B-C-D
                      points[0] = pointB;
                      points[1] = pointC;
                      points[2] = pointD;
                Severity: Minor
                Found in src/core/datamatrix/detector/Detector.ts and 1 other location - About 40 mins to fix
                src/core/datamatrix/detector/Detector.ts on lines 184..190

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

                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