zxing-js/library

View on GitHub
src/core/common/detector/CornerDetector.ts

Summary

Maintainability
F
4 days
Test Coverage

Function getCornerFromArea has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

    private getCornerFromArea(left: number, right: number, top: number, bottom: number, maximizeX: boolean, maximizeY: boolean): ResultPoint {
        let resX = maximizeX ? 0 : Number.MAX_VALUE;
        let resY = maximizeY ? 0 : Number.MAX_VALUE;
        for (let x = left; x < right; x++) {
            for (let y = top; y < bottom; y++) {
Severity: Minor
Found in src/core/common/detector/CornerDetector.ts - About 7 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 detect has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    public detect(): ResultPoint[] {

        let left = this.leftInit;
        let right = this.rightInit;
        let up = this.upInit;
Severity: Minor
Found in src/core/common/detector/CornerDetector.ts - About 6 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 detect has 82 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public detect(): ResultPoint[] {

        let left = this.leftInit;
        let right = this.rightInit;
        let up = this.upInit;
Severity: Major
Found in src/core/common/detector/CornerDetector.ts - About 3 hrs to fix

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

        private containsBlackPoint(a: number, b: number, fixed: number, horizontal: boolean): boolean {
    
            if (horizontal) {
                for (let x = a; x <= b; x++) {
                    if (this.image.get(x, fixed)) {
    Severity: Minor
    Found in src/core/common/detector/CornerDetector.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 getCornerFromArea has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private getCornerFromArea(left: number, right: number, top: number, bottom: number, maximizeX: boolean, maximizeY: boolean): ResultPoint {
            let resX = maximizeX ? 0 : Number.MAX_VALUE;
            let resY = maximizeY ? 0 : Number.MAX_VALUE;
            for (let x = left; x < right; x++) {
                for (let y = top; y < bottom; y++) {
    Severity: Minor
    Found in src/core/common/detector/CornerDetector.ts - About 1 hr to fix

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

          private findCorners(right: number, left: number, down: number, up: number): ResultPoint[] {
              //
              //      A------------              ------------B
              //      |           |      up      |           |
              //      |    -------|--------------|-------    |
      Severity: Minor
      Found in src/core/common/detector/CornerDetector.ts - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                                if (maximizeY) {
                                    if (y > resY) {
                                        resY = y;
                                    }
                                } else {
        Severity: Major
        Found in src/core/common/detector/CornerDetector.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if (maximizeX) {
                                      if (x > resX) {
                                          resX = x;
                                      }
                                  } else {
          Severity: Major
          Found in src/core/common/detector/CornerDetector.ts - About 45 mins to fix

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

                        while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < this.height) {
                            bottomBorderNotWhite = this.containsBlackPoint(left, right, down, true);
                            if (bottomBorderNotWhite) {
                                down++;
                                aBlackPointFoundOnBorder = true;
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 2 hrs to fix
            src/core/common/detector/CornerDetector.ts on lines 80..89

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

            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

                        while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < this.width) {
                            rightBorderNotWhite = this.containsBlackPoint(up, down, right, false);
                            if (rightBorderNotWhite) {
                                right++;
                                aBlackPointFoundOnBorder = true;
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 2 hrs to fix
            src/core/common/detector/CornerDetector.ts on lines 100..109

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

            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 4 locations. Consider refactoring.
            Open

                        while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) {
                            topBorderNotWhite = this.containsBlackPoint(left, right, up, true);
                            if (topBorderNotWhite) {
                                up--;
                                aBlackPointFoundOnBorder = true;
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 2 hrs to fix
            src/core/common/detector/CornerDetector.ts on lines 120..129
            src/core/common/detector/WhiteRectangleDetector.ts on lines 159..168
            src/core/common/detector/WhiteRectangleDetector.ts on lines 179..188

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

            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 4 locations. Consider refactoring.
            Open

                        while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) {
                            leftBorderNotWhite = this.containsBlackPoint(up, down, left, false);
                            if (leftBorderNotWhite) {
                                left--;
                                aBlackPointFoundOnBorder = true;
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 2 hrs to fix
            src/core/common/detector/CornerDetector.ts on lines 140..149
            src/core/common/detector/WhiteRectangleDetector.ts on lines 159..168
            src/core/common/detector/WhiteRectangleDetector.ts on lines 179..188

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

            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 (this.upInit < 0 || this.leftInit < 0 || this.downInit >= this.height || this.rightInit >= this.width) {
                        throw new NotFoundException();
                    }
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 1 hr to fix
            src/core/common/detector/WhiteRectangleDetector.ts on lines 75..77

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

            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 {
                        for (let y = a; y <= b; y++) {
                            if (this.image.get(fixed, y)) {
                                return true;
                            }
            Severity: Minor
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 274..280

            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 (horizontal) {
                        for (let x = a; x <= b; x++) {
                            if (this.image.get(x, fixed)) {
                                return true;
                            }
            Severity: Minor
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 280..286

            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 4 locations. Consider refactoring.
            Open

                    const bottomLeftCorner = this.getCornerFromArea(d.getX(), dp.getX(), dp.getY(), d.getY(), false, true);
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 209..209
            src/core/common/detector/CornerDetector.ts on lines 210..210
            src/core/common/detector/CornerDetector.ts on lines 211..211

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

            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 4 locations. Consider refactoring.
            Open

                    const topLeftCorner = this.getCornerFromArea(a.getX(), ap.getX(), a.getY(), ap.getY(), false, false);
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 210..210
            src/core/common/detector/CornerDetector.ts on lines 211..211
            src/core/common/detector/CornerDetector.ts on lines 212..212

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

            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 4 locations. Consider refactoring.
            Open

                    const bottomRightCorner = this.getCornerFromArea(cp.getX(), c.getX(), cp.getY(), c.getY(), true, true);
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 209..209
            src/core/common/detector/CornerDetector.ts on lines 210..210
            src/core/common/detector/CornerDetector.ts on lines 212..212

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

            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 4 locations. Consider refactoring.
            Open

                    const topRightCorner = this.getCornerFromArea(bp.getX(), b.getX(), b.getY(), bp.getY(), true, false);
            Severity: Major
            Found in src/core/common/detector/CornerDetector.ts and 3 other locations - About 40 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 209..209
            src/core/common/detector/CornerDetector.ts on lines 211..211
            src/core/common/detector/CornerDetector.ts on lines 212..212

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

            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 (maximizeY) {
                                        if (y > resY) {
                                            resY = y;
                                        }
                                    } else {
            Severity: Minor
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 35 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 233..241

            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 (maximizeX) {
                                        if (x > resX) {
                                            resX = x;
                                        }
                                    } else {
            Severity: Minor
            Found in src/core/common/detector/CornerDetector.ts and 1 other location - About 35 mins to fix
            src/core/common/detector/CornerDetector.ts on lines 242..250

            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