zxing-js/library

View on GitHub
src/core/common/BitMatrix.ts

Summary

Maintainability
F
3 days
Test Coverage
A
91%

Function getEnclosingRectangle has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    public getEnclosingRectangle(): Int32Array {
        const width = this.width;
        const height = this.height;
        const rowSize = this.rowSize;
        const bits = this.bits;
Severity: Minor
Found in src/core/common/BitMatrix.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 parseFromString has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public static parseFromString(stringRepresentation: string, setString: string, unsetString: string): BitMatrix {
        if (stringRepresentation === null) {
            throw new IllegalArgumentException('stringRepresentation cannot be null');
        }

Severity: Minor
Found in src/core/common/BitMatrix.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

File BitMatrix.ts has 295 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright 2007 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/common/BitMatrix.ts - About 3 hrs to fix

    BitMatrix has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class BitMatrix /*implements Cloneable*/ {
    
        /**
         * Creates an empty square {@link BitMatrix}.
         *
    Severity: Minor
    Found in src/core/common/BitMatrix.ts - About 2 hrs to fix

      Function parseFromString has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static parseFromString(stringRepresentation: string, setString: string, unsetString: string): BitMatrix {
              if (stringRepresentation === null) {
                  throw new IllegalArgumentException('stringRepresentation cannot be null');
              }
      
      
      Severity: Minor
      Found in src/core/common/BitMatrix.ts - About 2 hrs to fix

        Function getEnclosingRectangle has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public getEnclosingRectangle(): Int32Array {
                const width = this.width;
                const height = this.height;
                const rowSize = this.rowSize;
                const bits = this.bits;
        Severity: Minor
        Found in src/core/common/BitMatrix.ts - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                  while (((theBits << (31 - bit)) & 0xFFFFFFFF) === 0) {
                                      bit++;
                                  }
          Severity: Major
          Found in src/core/common/BitMatrix.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    while ((theBits >>> bit) === 0) {
                                        bit--;
                                    }
            Severity: Major
            Found in src/core/common/BitMatrix.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if ((x32 * 32 + bit) > right) {
                                          right = x32 * 32 + bit;
                                      }
              Severity: Major
              Found in src/core/common/BitMatrix.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if ((x32 * 32 + bit) < left) {
                                            left = x32 * 32 + bit;
                                        }
                Severity: Major
                Found in src/core/common/BitMatrix.ts - About 45 mins to fix

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

                      public setRegion(left: number /*int*/, top: number /*int*/, width: number /*int*/, height: number /*int*/): void {
                          if (top < 0 || left < 0) {
                              throw new IllegalArgumentException('Left and top must be nonnegative');
                          }
                          if (height < 1 || width < 1) {
                  Severity: Minor
                  Found in src/core/common/BitMatrix.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 constructor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public constructor(private width: number /*int*/, private height?: number /*int*/,
                          private rowSize?: number /*int*/, private bits?: Int32Array) {
                          if (undefined === height || null === height) {
                              height = width;
                          }
                  Severity: Minor
                  Found in src/core/common/BitMatrix.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 parseFromBooleanArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static parseFromBooleanArray(image: boolean[][]): BitMatrix {
                          const height = image.length;
                          const width = image[0].length;
                          const bits = new BitMatrix(width, height);
                          for (let i = 0; i < height; i++) {
                  Severity: Minor
                  Found in src/core/common/BitMatrix.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 buildToString has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private buildToString(setString: string, unsetString: string, lineSeparator: string) {
                          let result = new StringBuilder();
                          // result.append(lineSeparator);
                          for (let y = 0, height = this.height; y < height; y++) {
                              for (let x = 0, width = this.width; x < width; x++) {
                  Severity: Minor
                  Found in src/core/common/BitMatrix.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 flip(x: number /*int*/, y: number /*int*/): void {
                          const offset = y * this.rowSize + Math.floor(x / 32);
                          this.bits[offset] ^= ((1 << (x & 0x1f)) & 0xFFFFFFFF);
                      }
                  Severity: Major
                  Found in src/core/common/BitMatrix.ts and 1 other location - About 1 hr to fix
                  src/core/common/BitMatrix.ts on lines 193..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 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

                      public set(x: number /*int*/, y: number /*int*/): void {
                          const offset = y * this.rowSize + Math.floor(x / 32);
                          this.bits[offset] |= (1 << (x & 0x1f)) & 0xFFFFFFFF;
                      }
                  Severity: Major
                  Found in src/core/common/BitMatrix.ts and 1 other location - About 1 hr to fix
                  src/core/common/BitMatrix.ts on lines 209..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 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

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

                                      if (rowLength === -1) {
                                          rowLength = bitsPos - rowStartPos;
                                      } else if (bitsPos - rowStartPos !== rowLength) {
                                          throw new IllegalArgumentException('row lengths do not match');
                                      }
                  Severity: Minor
                  Found in src/core/common/BitMatrix.ts and 1 other location - About 35 mins to fix
                  src/core/common/BitMatrix.ts on lines 158..162

                  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

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

                              if (rowLength === -1) {
                                  rowLength = bitsPos - rowStartPos;
                              } else if (bitsPos - rowStartPos !== rowLength) {
                                  throw new IllegalArgumentException('row lengths do not match');
                              }
                  Severity: Minor
                  Found in src/core/common/BitMatrix.ts and 1 other location - About 35 mins to fix
                  src/core/common/BitMatrix.ts on lines 133..137

                  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

                          return this.width === other.width && this.height === other.height && this.rowSize === other.rowSize &&
                  Severity: Minor
                  Found in src/core/common/BitMatrix.ts and 1 other location - About 30 mins to fix
                  src/core/datamatrix/encoder/MinimalEncoder.ts on lines 785..787

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

                  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