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];
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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) {
- Read upRead up
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) {
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;
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
- Read upRead up
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;
- Read upRead up
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>
- Read upRead up
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;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (temp > 9) {
total += Math.floor(temp / 10) + (temp % 10);
} else {
total += temp;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
Consider simplifying this complex logical expression. Open
if (
checkDigit === Number(vat.slice(7, 9)) &&
no < 9990001 &&
(no < 100000 || no > 999999) &&
(no < 9490001 || no > 9700000)
Function _increase
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function _increase(value: number, vat: string, from: number, to: number, incr: number): number {
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 {
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++) {
- Read upRead up
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;
Avoid too many return
statements within this function. Open
if (additional[3].test(vat)) return isPersonalKtoX(vat);
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) {
- Read upRead up
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;
- Read upRead up
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"