zxing-js/library

View on GitHub
src/core/datamatrix/decoder/DecodedBitStreamParser.ts

Summary

Maintainability
F
1 wk
Test Coverage
D
63%

Function decodeTextSegment has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

  private static decodeTextSegment(bits: BitSource, result: StringBuilder): void {
    // Three Text values are encoded in a 16-bit value as
    // (1600 * C1) + (40 * C2) + C3 + 1
    // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time
    let upperShift = false;
Severity: Minor
Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 1 day 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 decodeC40Segment has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

  private static decodeC40Segment(bits: BitSource, result: StringBuilder): void {
    // Three C40 values are encoded in a 16-bit value as
    // (1600 * C1) + (40 * C2) + C3 + 1
    // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time
    let upperShift = false;
Severity: Minor
Found in src/core/datamatrix/decoder/DecodedBitStreamParser.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

File DecodedBitStreamParser.ts has 404 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import DecoderResult from '../../common/DecoderResult';
import BitSource from '../../common/BitSource';
import StringBuilder from '../../util/StringBuilder';

import StringEncoding from '../../util/StringEncoding';
Severity: Minor
Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 5 hrs to fix

    Function decodeTextSegment has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private static decodeTextSegment(bits: BitSource, result: StringBuilder): void {
        // Three Text values are encoded in a 16-bit value as
        // (1600 * C1) + (40 * C2) + C3 + 1
        // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time
        let upperShift = false;
    Severity: Major
    Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 3 hrs to fix

      Function decodeC40Segment has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private static decodeC40Segment(bits: BitSource, result: StringBuilder): void {
          // Three C40 values are encoded in a 16-bit value as
          // (1600 * C1) + (40 * C2) + C3 + 1
          // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time
          let upperShift = false;
      Severity: Major
      Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 3 hrs to fix

        Function decodeAsciiSegment has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

          private static decodeAsciiSegment(bits: BitSource,
                                                 result: StringBuilder,
                                                 resultTrailer: StringBuilder): Mode {
            let upperShift = false;
            do {
        Severity: Minor
        Found in src/core/datamatrix/decoder/DecodedBitStreamParser.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 decodeAsciiSegment has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private static decodeAsciiSegment(bits: BitSource,
                                                 result: StringBuilder,
                                                 resultTrailer: StringBuilder): Mode {
            let upperShift = false;
            do {
        Severity: Major
        Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 2 hrs to fix

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

            private static decodeAnsiX12Segment(bits: BitSource,
                                                     result: StringBuilder): void {
              // Three ANSI X12 values are encoded in a 16-bit value as
              // (1600 * C1) + (40 * C2) + C3 + 1
          
          
          Severity: Minor
          Found in src/core/datamatrix/decoder/DecodedBitStreamParser.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 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 decodeAnsiX12Segment has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private static decodeAnsiX12Segment(bits: BitSource,
                                                     result: StringBuilder): void {
              // Three ANSI X12 values are encoded in a 16-bit value as
              // (1600 * C1) + (40 * C2) + C3 + 1
          
          
          Severity: Minor
          Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 1 hr to fix

            Function decode has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static decode(bytes:  Uint8Array): DecoderResult {
                const bits = new BitSource(bytes);
                const result = new StringBuilder();
                const resultTrailer = new StringBuilder();
                const byteSegments = new Array<Uint8Array>();
            Severity: Minor
            Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 1 hr to fix

              Function decode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                static decode(bytes:  Uint8Array): DecoderResult {
                  const bits = new BitSource(bytes);
                  const result = new StringBuilder();
                  const resultTrailer = new StringBuilder();
                  const byteSegments = new Array<Uint8Array>();
              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 decodeBase256Segment has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                private static decodeBase256Segment(bits: BitSource,
                                                         result: StringBuilder,
                                                         byteSegments: Uint8Array[]): void {
                  // Figure out how long the Base 256 Segment is.
                  let codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
              Severity: Minor
              Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                              switch (cValue) {
                                case 27: // FNC1
                                  result.append(String.fromCharCode(29)); // translate as ASCII 29
                                  break;
                                case 30: // Upper Shift
                Severity: Major
                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                if (upperShift) {
                                  result.append(String.fromCharCode(c40char.charCodeAt(0) + 128));
                                  upperShift = false;
                                } else {
                                  result.append(c40char);
                  Severity: Major
                  Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if (oneByte !== 254 || bits.available() !== 0) {
                                  throw new FormatException();
                                }
                    Severity: Major
                    Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                      Function decodeBase256Segment has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        private static decodeBase256Segment(bits: BitSource,
                                                                 result: StringBuilder,
                                                                 byteSegments: Uint8Array[]): void {
                          // Figure out how long the Base 256 Segment is.
                          let codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
                      Severity: Minor
                      Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Avoid deeply nested control flow statements.
                      Open

                                    switch (cValue) {
                                      case 27: // FNC1
                                        result.append(String.fromCharCode(29)); // translate as ASCII 29
                                        break;
                                      case 30: // Upper Shift
                      Severity: Major
                      Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                      if (upperShift) {
                                        result.append(String.fromCharCode(c40char.charCodeAt(0) + 128));
                                        upperShift = false;
                                      } else {
                                        result.append(c40char);
                        Severity: Major
                        Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                        if (upperShift) {
                                          result.append(String.fromCharCode(textChar.charCodeAt(0) + 128));
                                          upperShift = false;
                                        } else {
                                          result.append(textChar);
                          Severity: Major
                          Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                          if (upperShift) {
                                            result.append(String.fromCharCode(textChar.charCodeAt(0) + 128));
                                            upperShift = false;
                                          } else {
                                            result.append(textChar);
                            Severity: Major
                            Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                            if (upperShift) {
                                              result.append(String.fromCharCode(textChar.charCodeAt(0) + 128));
                                              upperShift = false;
                                            } else {
                                              result.append(textChar);
                              Severity: Major
                              Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts - About 45 mins to fix

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

                                          case 0:
                                            if (cValue < 3) {
                                              shift = cValue + 1;
                                            } else if (cValue < this.TEXT_BASIC_SET_CHARS.length) {
                                              const textChar = this.TEXT_BASIC_SET_CHARS[cValue];
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 4 hrs to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 219..233

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

                                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

                                          case 0:
                                            if (cValue < 3) {
                                              shift = cValue + 1;
                                            } else if (cValue < this.C40_BASIC_SET_CHARS.length) {
                                              const c40char = this.C40_BASIC_SET_CHARS[cValue];
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 4 hrs to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 308..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 132.

                                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

                                          case 1:
                                            if (upperShift) {
                                              result.append(String.fromCharCode(cValue + 128));
                                              upperShift = false;
                                            } else {
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 1 hr to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 234..242

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

                                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

                                          case 1:
                                            if (upperShift) {
                                              result.append(String.fromCharCode(cValue + 128));
                                              upperShift = false;
                                            } else {
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 1 hr to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 323..331

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

                                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 (cValue < this.C40_SHIFT2_SET_CHARS.length) {
                                              const c40char = this.C40_SHIFT2_SET_CHARS[cValue];
                                              if (upperShift) {
                                                result.append(String.fromCharCode(c40char.charCodeAt(0) + 128));
                                                upperShift = false;
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 1 hr to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 334..353

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

                                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 (cValue < this.TEXT_SHIFT2_SET_CHARS.length) {
                                              const textChar = this.TEXT_SHIFT2_SET_CHARS[cValue];
                                              if (upperShift) {
                                                result.append(String.fromCharCode(textChar.charCodeAt(0) + 128));
                                                upperShift = false;
                                Severity: Major
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 1 hr to fix
                                src/core/datamatrix/decoder/DecodedBitStreamParser.ts on lines 244..263

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

                                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 unrandomize255State(randomizedBase256Codeword: number,
                                                                          base256CodewordPosition: number): number {
                                    const pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1;
                                    const tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
                                    return tempVariable >= 0 ? tempVariable : tempVariable + 256;
                                Severity: Minor
                                Found in src/core/datamatrix/decoder/DecodedBitStreamParser.ts and 1 other location - About 50 mins to fix
                                src/core/datamatrix/encoder/HighLevelEncoder.ts on lines 44..48

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

                                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