zxing-js/library

View on GitHub

Showing 958 of 958 total issues

Function updateStateForChar has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  private updateStateForChar(
    state: State,
    index: int,
    result: Collection<State>
  ): void {
Severity: Minor
Found in src/core/aztec/encoder/HighLevelEncoder.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

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

    if (codewordsRow < codewords.length - 2) {
      otherCodewords[9] = codewords[codewordsRow + 2];
      otherCodewords[12] = previousColumnCodewords[codewordsRow + 2];
      otherCodewords[13] = nextColumnCodewords[codewordsRow + 2];
    }
Severity: Major
Found in src/core/pdf417/decoder/DetectionResult.ts and 1 other location - About 2 hrs to fix
src/core/pdf417/decoder/DetectionResult.ts on lines 225..229

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

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 (codewordsRow < codewords.length - 1) {
      otherCodewords[1] = codewords[codewordsRow + 1];
      otherCodewords[6] = previousColumnCodewords[codewordsRow + 1];
      otherCodewords[7] = nextColumnCodewords[codewordsRow + 1];
    }
Severity: Major
Found in src/core/pdf417/decoder/DetectionResult.ts and 1 other location - About 2 hrs to fix
src/core/pdf417/decoder/DetectionResult.ts on lines 230..234

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

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

Function encodeChar has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  encodeChar(c: char, sb: StringBuilder): number {
    if (c === ' '.charCodeAt(0)) {
      sb.append(0o3);
      return 1;
    }
Severity: Major
Found in src/core/datamatrix/encoder/TextEncoder.ts - About 2 hrs to fix

    Function getC40Value has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      getC40Value(c40: boolean, setIndex: number, c: number, fnc1: number): number {
        if (c === fnc1) {
          if (!(setIndex === 2)) {
            throw new Error('FNC1 cannot be used in C40 shift 2');
          }
    Severity: Major
    Found in src/core/datamatrix/encoder/MinimalEncoder.ts - About 2 hrs to fix

      Function calculateBlackPoints has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static calculateBlackPoints(luminances: Uint8ClampedArray,
              subWidth: number /*int*/,
              subHeight: number /*int*/,
              width: number /*int*/,
              height: number /*int*/): Int32Array[] {
      Severity: Major
      Found in src/core/common/HybridBinarizer.ts - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if (c40) {
              return c <= 31
                ? c
                : c === 32
                ? 3
        Severity: Critical
        Found in src/core/datamatrix/encoder/MinimalEncoder.ts - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                          if (x + 6 < width &&
                              arrayY[x] === 1 &&
                              arrayY[x + 1] === 0 &&
                              arrayY[x + 2] === 1 &&
                              arrayY[x + 3] === 1 &&
          Severity: Critical
          Found in src/core/qrcode/encoder/MaskUtil.ts - About 2 hrs to fix

            Consider simplifying this complex logical expression.
            Open

                            if (y + 6 < height &&
                                array[y][x] === 1 &&
                                array[y + 1][x] === 0 &&
                                array[y + 2][x] === 1 &&
                                array[y + 3][x] === 1 &&
            Severity: Critical
            Found in src/core/qrcode/encoder/MaskUtil.ts - About 2 hrs to fix

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

                  public static encode(content: string,
                      ecLevel: ErrorCorrectionLevel,
                      hints: Map<EncodeHintType, any> = null): QRCode /*throws WriterException*/ {
              
                      // Determine what character encoding has been specified by the caller, if any
              Severity: Minor
              Found in src/core/qrcode/encoder/Encoder.ts - About 2 hrs to fix

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

                    public setHints(hints?: Map<DecodeHintType, any> | null): void {
                        this.hints = hints;
                
                        const tryHarder: boolean = hints !== null && hints !== undefined && undefined !== hints.get(DecodeHintType.TRY_HARDER);
                        /*@SuppressWarnings("unchecked")*/
                Severity: Minor
                Found in src/core/MultiFormatReader.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 constructor has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      constructor(stringToEncode: string, priorityCharset: Charset, fnc1: number) {
                        const neededEncoders: CharsetEncoder[] = [];
                    
                        // we always need the ISO-8859-1 encoder. It is the default encoding
                        neededEncoders.push(new CharsetEncoder(StandardCharsets.ISO_8859_1));
                    Severity: Minor
                    Found in src/core/common/ECIEncoderSet.ts - About 1 hr to fix

                      Function getEncodedData has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private static getEncodedData(correctedBits: boolean[]): string {
                              let endIndex: number = correctedBits.length;
                              let latchTable = Table.UPPER; // table most recently latched to
                              let shiftTable = Table.UPPER; // table to use for the next read
                              let result: string = '';
                      Severity: Minor
                      Found in src/core/aztec/decoder/Decoder.ts - About 1 hr to fix

                        Function extractPureBits has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          private static extractPureBits(image: BitMatrix): BitMatrix /*throws NotFoundException */ {
                        
                            const leftTopBlack: Int32Array = image.getTopLeftOnBit();
                            const rightBottomBlack: Int32Array = image.getBottomRightOnBit();
                            if (leftTopBlack === null || rightBottomBlack === null) {
                        Severity: Minor
                        Found in src/core/qrcode/QRCodeReader.ts - About 1 hr to fix

                          Function findRowsWithPattern has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            private static  findRowsWithPattern( matrix: BitMatrix,
                                                                              height: /*int*/ number,
                                                                              width: /*int*/ number,
                                                                              startRow: /*int*/ number,
                                                                              startColumn: /*int*/ number,
                          Severity: Minor
                          Found in src/core/pdf417/detector/Detector.ts - About 1 hr to fix

                            Function parseFieldsInGeneralPurpose has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              static parseFieldsInGeneralPurpose(rawInformation: string): string {
                                if (!rawInformation) {
                                  return null;
                                }
                            
                            
                            Severity: Minor
                            Found in src/core/oned/rss/expanded/decoders/FieldParser.ts - About 1 hr to fix

                              Function doDecode has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  private doDecode(image: BinaryBitmap, hints?: Map<DecodeHintType, any>): Result {
                                      const width = image.getWidth();
                                      const height = image.getHeight();
                                      let row = new BitArray(width);
                              
                              
                              Severity: Minor
                              Found in src/core/oned/OneDReader.ts - About 1 hr to fix

                                Function decodeEdifactSegment has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  private static decodeEdifactSegment(bits: BitSource, result: StringBuilder): void {
                                    do {
                                      // If there is only two or less bytes left then it will be encoded as ASCII
                                      if (bits.available() <= 16) {
                                        return;
                                Severity: Minor
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.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 decodeNumericSegment has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  private static decodeNumericSegment(bits: BitSource,
                                    result: StringBuilder,
                                    count: number /*int*/): void /*throws FormatException*/ {
                                    // Read three digits at a time
                                    while (count >= 3) {
                                Severity: Minor
                                Found in src/core/qrcode/decoder/DecodedBitStreamParser.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

                                Severity
                                Category
                                Status
                                Source
                                Language