Загрузка данных
Adaptability issue | Not focused
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
Cognitive Complexity of functions should not be too hightypescript:S3776
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Critical
Tags
brain-overload
+
Effort
10min
Introduced
1 hour ago
Where is the issue?
Why is this an issue?
Activity
More Info
moex-chartsrc/core/Drawings/sliderPosition/sliderPosition.ts
See all issues in this file
const formattedAmount = formatPrice(amount, 2) ?? '0';
return `${t('Stop')}: ${formattedDiff} (${formatPercent(percent)}), ${t('Amount')}: ${formattedAmount}`;
}
private getHandleTarget(point: Point): DragTarget {
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
const geometry = this.getGeometry();
if (!geometry) {
return null;
}
if (Math.abs(point.x - geometry.startX) <= HIT_TOLERANCE) {
const entryDistance = Math.abs(point.y - geometry.entryY);
if (entryDistance < 1) {
return 'entry';
}
const pointerSide = Math.sign(point.y - geometry.entryY);
const targetSide = Math.sign(geometry.targetY - geometry.entryY)
|| -Math.sign(geometry.stopY - geometry.entryY);
if (targetSide !== 0) {
const isTargetSide = pointerSide === targetSide;
const handleY = isTargetSide
? geometry.targetY : geometry.stopY;
const handleId: SliderHandleId = isTargetSide
? 'target' : 'stop';
if (Math.abs(point.y - handleY) <= HIT_TOLERANCE) {
return handleId;
}
}
if (entryDistance <= HIT_TOLERANCE) {
return 'entry';
}
}
const handle = this.getDrawingHandleAtPoint(point);
if (handle) {
return handle.id;
}
const bounds: Bounds = {
left: geometry.leftX,
right: geometry.rightX,
top: Math.min(geometry.targetY, geometry.stopY),
bottom: Math.max(geometry.targetY, geometry.stopY),
};
return isPointInBounds(point, bounds)
? 'body' : null;
}
private containsPoint(point: Point): boolean {
const geometry = this.getGeometry();
Adaptability issue | Not focused
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
Cognitive Complexity of functions should not be too hightypescript:S3776
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Critical
Tags
brain-overload
+
Effort
7min
Introduced
1 hour ago
Where is the issue?
Why is this an issue?
Activity
More Info
moex-chartsrc/core/Drawings/sliderPosition/sliderPosition.ts
See all issues in this file
amount: this.settings.accountSize,
settings: { ...this.settings },
};
}
public setState(state: unknown): void {
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
if (!state
|| typeof state !== 'object') {
return;
}
const next = state as Partial<SliderPositionState>;
const {
hidden = this.hidden,
mode = this.mode,
startTime = this.startTime,
endTime = this.endTime,
entryPrice = this.entryPrice,
} = next;
this.hidden = hidden;
this.mode = mode;
this.startTime = startTime;
this.endTime = endTime;
this.entryPrice = entryPrice;
if (next.stopPrice !== undefined) {
this.stopPrice =
next.stopPrice === null
|| entryPrice === null
? next.stopPrice
: this.normalizeStop(entryPrice, next.stopPrice);
}
if (next.targetPrice !== undefined) {
this.targetPrice =
next.targetPrice === null
|| entryPrice === null
? next.targetPrice
: this.normalizeTarget(entryPrice, next.targetPrice);
} else
if (
entryPrice !== null
&&
this.stopPrice !== null &&
typeof next.riskRewardRatio === 'number' &&
next.riskRewardRatio >= 0
) {
const risk = Math.abs(entryPrice - this.stopPrice);
const direction = this.side === 'long'
? 1 : -1;
this.targetPrice = this.normalizeTarget(entryPrice, entryPrice + risk * next.riskRewardRatio * direction);
}
if (next.settings) {
this.settings = {
...createDefaultSettings(),
...next.settings,
};
}
Covered code
New Code
if (typeof next.amount === 'number'
&& next.amount >= 0) {
this.settings.accountSize = next.amount;
}
this.render();
}