Function parseDate
has a Cognitive Complexity of 340 (exceeds 5 allowed). Consider refactoring. Open
parseDate(
txt: string,
fmt: string,
nonLenient?: boolean,
refval?: DateImpl,
- 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 formatDate
has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring. Open
formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
if (!fmt) fmt = 'yyyy/MM/dd';
localizedSymbols ??= {
DOW_1ST: zk.DOW_1ST,
- 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
File datefmt.ts
has 642 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* datefmt.ts
Purpose:
Description:
Function parseDate
has 251 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseDate(
txt: string,
fmt: string,
nonLenient?: boolean,
refval?: DateImpl,
Function _parseTextToArray
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
function _parseTextToArray(txt: string, fmt: string): string[] | undefined {
//ZK-5423
var literals = extractLiteral(fmt); //extract literal token from format
//remove literal from format and text
fmt = fmt.replace(/'.*?'/g, ' '); //remove any string enclosed by single quotes
- 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 formatDate
has 115 lines of code (exceeds 25 allowed). Consider refactoring. Open
formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
if (!fmt) fmt = 'yyyy/MM/dd';
localizedSymbols ??= {
DOW_1ST: zk.DOW_1ST,
Function _parseTextToArray
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _parseTextToArray(txt: string, fmt: string): string[] | undefined {
//ZK-5423
var literals = extractLiteral(fmt); //extract literal token from format
//remove literal from format and text
fmt = fmt.replace(/'.*?'/g, ' '); //remove any string enclosed by single quotes
Consider simplifying this complex logical expression. Open
} else if ((mindex >= 0 && mindex <= i /*&& mmindex >= i location French will lose last char */)
|| (eindex >= 0 && eindex <= i) || (aa > -1 && aa <= i) || (gg > -1 && gg <= i)) {
if (c.match(/\w/)) {
ary.push(c);
} else {
Function parseDate
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
txt: string,
fmt: string,
nonLenient?: boolean,
refval?: DateImpl,
localizedSymbols?: zk.LocalizedSymbols,
Avoid deeply nested control flow statements. Open
if (len == 3)
symbols = localizedSymbols.SMON!;
else if (len == 4)
symbols = localizedSymbols.FMON!;
else
Function parseDate
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
parseDate(
txt: string,
fmt: string,
strict?: boolean,
refval?: DateImpl,
- 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 deeply nested control flow statements. Open
if (nosep)
token = _parseToken(token, ts, --i, token.length);//token.length: the length of French month is 4
Avoid deeply nested control flow statements. Open
} else if (len <= 2) {
if (nosep && token && token.length > 2) {//Bug 2560497 : if no separator, token must be assigned.
ts[--i] = token.substring(2);
token = token.substring(0, 2);
}
Avoid deeply nested control flow statements. Open
for (var index = symbols.length, brkswch; --index >= 0;) {
var monStr = symbols[index].toLowerCase();
if ((nonLenient && mon == monStr) || (!nonLenient && mon.startsWith(monStr))) {
var monStrLen = monStr.length;
Avoid deeply nested control flow statements. Open
if (ary.length) {
ts.push(ary.join(''));
ary = [];
}
Avoid deeply nested control flow statements. Open
if (fmt.charAt(k) == 'r') k++; // ZK-2964: for nl local uur
Avoid deeply nested control flow statements. Open
if (cc == 'm') min = nv;
else if (cc == 's') sec = nv;
else msec = nv;
Avoid deeply nested control flow statements. Open
if (!eraName) return; // no era match
Avoid deeply nested control flow statements. Open
if (len < 3) len = 2;
Avoid deeply nested control flow statements. Open
if (newY < 100 && newY === (y + ydelta) % 100) break; // assume yy is not modified
Avoid deeply nested control flow statements. Open
if (d < 0 || d > 31) //restrict since user might input year for day (ok to allow 0 and 31 for easy entry)
return; //failed
Avoid deeply nested control flow statements. Open
if (isNaN(nv = _parseInt(token)))
return; // failed, B50-3314513
Avoid deeply nested control flow statements. Open
while (f == fmt.charAt(i - 1) && f) {
f = fmt.charAt(++i);
}
Avoid deeply nested control flow statements. Open
if (token && token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
Avoid deeply nested control flow statements. Open
if (ydelta === 0 && newY < 100) { // only handle twoDigitYearStart with ISO calendar for now
// ZK-4235: Datefmt parseDate always return date between 1930-2029 when using yy format
var twoDigitYearStart = zk.TDYS,
lowerBoundary = (Math.floor(twoDigitYearStart / 100) * 100) + newY,
upperBoundary = lowerBoundary + 100;
Avoid deeply nested control flow statements. Open
if (brkswch)
break;
Consider simplifying this complex logical expression. Open
if (dt.getFullYear() != y || dt.getMonth() != m || dt.getDate() != d
|| dt.getHours() != hr || dt.getMinutes() != min || dt.getSeconds() != sec) //ignore msec (safer though not accurate)
return; //failed
Avoid too many return
statements within this function. Open
return; //failed
Avoid too many return
statements within this function. Open
if (l == 12) return; //failed
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
if (!eraName) return; // no era match
Avoid too many return
statements within this function. Open
return +dt == +refval ? refval : dt as DateImpl;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return; // failed, B50-3314513
Avoid too many return
statements within this function. Open
return;//failed
Avoid too many return
statements within this function. Open
if (!token) return; //failed
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return; //failed
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return; //failed
Function formatDate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
var d: LeapDay | undefined;
if (localizedSymbols) {
var localeDateTimeFormat = new Intl.DateTimeFormat(localizedSymbols.LAN_TAG, { year: 'numeric' });
this._offset = localizedSymbols.YDELTA || zk.fmt.Date.getYDelta(val._moment.toDate(), localeDateTimeFormat);
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
localizedSymbols ??= {
DOW_1ST: zk.DOW_1ST,
MINDAYS: zk.MINDAYS,
ERA: zk.ERA,
YDELTA: zk.YDELTA,
- 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 116.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
localizedSymbols ??= {
DOW_1ST: zk.DOW_1ST,
MINDAYS: zk.MINDAYS,
ERA: zk.ERA,
YDELTA: zk.YDELTA,
- 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 116.
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