se-panfilov/jsvat

View on GitHub

Showing 38 of 38 total issues

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

    for (let i = 0; i < 10; i++) {
      total += Number(vat.charAt(i)) * rules.multipliers.m_1[i];
    }
Severity: Major
Found in src/lib/countries/russia.ts and 2 other locations - About 1 hr to fix
src/lib/countries/russia.ts on lines 46..48
src/lib/countries/russia.ts on lines 56..58

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

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 _check12DigitINN has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

function _check12DigitINN(vat: string, rules: Rules): boolean {
  let total1 = 0;
  let total2 = 0;

  if (vat.length === 12) {
Severity: Minor
Found in src/lib/countries/russia.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 extractAndMultiplyByCounter has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function extractAndMultiplyByCounter(vat: string, total: number): number {
  let result = total;
  for (let i = 0; i < 8; i++) {
    let temp = Number(vat.charAt(i));
    if (i % 2 === 0) {
Severity: Minor
Found in src/lib/countries/cyprus.ts - About 1 hr to fix

    Function isStandardOrCommercialNumber has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function isStandardOrCommercialNumber(vat: string, multipliers: ReadonlyArray<number>): boolean {
      let total = 0;
    
      // 0 VAT numbers disallowed!
      if (Number(vat.slice(0)) === 0) return false;
    Severity: Minor
    Found in src/lib/countries/unitedKingdom.ts - About 1 hr to fix

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

        calcFn: (vat: string): boolean => {
          let total = 0;
          let temp;
      
          // The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
      Severity: Minor
      Found in src/lib/countries/italy.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

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

        calcFn: (vat: string): boolean => {
          const { typeFormats, multipliers } = ireland.rules;
          if (!typeFormats || !typeFormats.first) return false;
          let total: string | number = 0;
      
      
      Severity: Minor
      Found in src/lib/countries/ireland.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

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

      function isIndividualType2(
        vat: string,
        multipliers: ReadonlyArray<number>,
        additional: ReadonlyArray<RegExp>,
        lookup?: ReadonlyArray<number>
      Severity: Minor
      Found in src/lib/countries/czechRepublic.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

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

          if (temp > 9) {
            result += Math.floor(temp / 10) + (temp % 10);
          } else {
            result += temp;
          }
      Severity: Minor
      Found in src/lib/countries/spain.ts and 1 other location - About 40 mins to fix
      src/lib/countries/austria.ts on lines 12..16

      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 (temp > 9) {
              total += Math.floor(temp / 10) + (temp % 10);
            } else {
              total += temp;
            }
      Severity: Minor
      Found in src/lib/countries/austria.ts and 1 other location - About 40 mins to fix
      src/lib/countries/spain.ts on lines 43..47

      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

      Consider simplifying this complex logical expression.
      Open

          if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
            let total = _increase2(0, vat, 0, 9, physicalMultipliers);
            // Establish check digit.
            total = total % 11;
            if (total === 10) total = 0;
      Severity: Major
      Found in src/lib/countries/bulgaria.ts - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

          if (
            checkDigit === Number(vat.slice(7, 9)) &&
            no < 9990001 &&
            (no < 100000 || no > 999999) &&
            (no < 9490001 || no > 9700000)
        Severity: Major
        Found in src/lib/countries/unitedKingdom.ts - About 40 mins to fix

          Function _increase has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function _increase(value: number, vat: string, from: number, to: number, incr: number): number {
          Severity: Minor
          Found in src/lib/countries/bulgaria.ts - About 35 mins to fix

            Function _increase2 has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function _increase2(value: number, vat: string, from: number, to: number, multipliers: ReadonlyArray<number>): number {
            Severity: Minor
            Found in src/lib/countries/bulgaria.ts - About 35 mins to fix

              Function isLegalEntities has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function isLegalEntities(vat: string, multipliers: ReadonlyArray<number>, additional: ReadonlyArray<RegExp>): boolean {
                let total = 0;
                if (additional[0].test(vat)) {
                  // Extract the next digit and multiply by the counter.
                  for (let i = 0; i < 7; i++) {
              Severity: Minor
              Found in src/lib/countries/czechRepublic.ts - About 35 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 too many return statements within this function.
              Open

                  return false;
              Severity: Major
              Found in src/lib/countries/spain.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    if (additional[3].test(vat)) return isPersonalKtoX(vat);
                Severity: Major
                Found in src/lib/countries/spain.ts - About 30 mins to fix

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

                  function extractAndMultiplyByCounter(vat: string, total: number): number {
                    let result = total;
                    for (let i = 0; i < 8; i++) {
                      let temp = Number(vat.charAt(i));
                      if (i % 2 === 0) {
                  Severity: Minor
                  Found in src/lib/countries/cyprus.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 calcFn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    calcFn: (input: string): boolean => {
                      const vat = input.replace(/[\ \-\_]/g, '').toUpperCase();
                  
                      const { additional, multipliers } = netherlands.rules;
                      if (!additional) return false;
                  Severity: Minor
                  Found in src/lib/countries/netherlands.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

                  Severity
                  Category
                  Status
                  Source
                  Language