File DisplayedCircuit.js
has 1126 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
DisplayedCircuit
has 61 functions (exceeds 20 allowed). Consider refactoring. Open
class DisplayedCircuit {
/**
*
* @param {!number} top
* @param {!CircuitDefinition} circuitDefinition
Function _drawWires
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
_drawWires(painter, showLabels, hand) {
let drawnWireCount = Math.min(this.circuitDefinition.numWires, (this._extraWireStartIndex || Infinity) + 1);
// Initial value labels
if (showLabels) {
Function _drawWires
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
_drawWires(painter, showLabels, hand) {
let drawnWireCount = Math.min(this.circuitDefinition.numWires, (this._extraWireStartIndex || Infinity) + 1);
// Initial value labels
if (showLabels) {
- 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 _drawHintLabels
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
_drawHintLabels(painter, stats) {
let gridRect = this._rectForSuperpositionDisplay();
// Amplitude hint.
painter.print(
Function _drawColumnSurvivalRate
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
_drawColumnSurvivalRate(painter, gateColumn, col, stats) {
if (gateColumn.indexOfNonUnitaryGate() === undefined) {
return;
}
Function _drawHintLabels
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
_drawHintLabels(painter, stats) {
let gridRect = this._rectForSuperpositionDisplay();
// Amplitude hint.
painter.print(
- 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 _previewDropMovedGate
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
_previewDropMovedGate(hand) {
let modificationPoint = this.findModificationIndex(hand);
if (modificationPoint === undefined) {
return this;
}
Function fromTextDiagram
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
static fromTextDiagram(gateMap, diagramText) {
let lines = diagramText.split('\n').map(e => {
let p = e.split('|');
if (p.length !== 2) {
throw new DetailedError('Bad diagram', {diagramText, gateMap});
Function _highlightStatusAt
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
_highlightStatusAt(col, row, focusPosPts) {
if (this._highlightedSlot !== undefined) {
if (this._highlightedSlot.col === col && this._highlightedSlot.row === row) {
return {
isResizeShowing: true,
Function _drawColumn
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
_drawColumn(painter, gateColumn, col, hand, stats) {
this._drawColumnControlWires(painter, col);
this._drawColumnDragHighlight(painter, col);
for (let row = 0; row < this.circuitDefinition.numWires; row++) {
Function drawCircuitTooltip
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function drawCircuitTooltip(painter, circuitDefinition, rect, showWires, time) {
let displayed = new DisplayedCircuit(
0,
circuitDefinition,
undefined,
Function _previewResizedGate
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
_previewResizedGate(hand) {
if (hand.resizingGateSlot === undefined || hand.pos === undefined) {
return this;
}
let gate = this.circuitDefinition.gateInSlot(hand.resizingGateSlot.x, hand.resizingGateSlot.y);
Function _tryGrabGate
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
_tryGrabGate(hand, duplicate, alt) {
if (hand.isBusy() || hand.pos === undefined) {
return undefined;
}
Function _tryGrabResizeTab
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
_tryGrabResizeTab(hand) {
if (hand.isBusy() || hand.pos === undefined) {
return undefined;
}
- 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 _drawColumnSurvivalRate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
_drawColumnSurvivalRate(painter, gateColumn, col, stats) {
if (gateColumn.indexOfNonUnitaryGate() === undefined) {
return;
}
- 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 _drawLabelsReasonablyFast
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _drawLabelsReasonablyFast(painter, dy, n, labeller, boundingWidth) {
let ctx = painter.ctx;
ctx.save();
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
Function _highlightStatusAt
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
_highlightStatusAt(col, row, focusPosPts) {
if (this._highlightedSlot !== undefined) {
if (this._highlightedSlot.col === col && this._highlightedSlot.row === row) {
return {
isResizeShowing: true,
- 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 _previewDropMovedRow
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
_previewDropMovedRow(hand) {
if (hand.pos === undefined) {
return this;
}
let handWire = this.wireIndexAt(hand.pos.y);
- 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 findModificationIndex
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
findModificationIndex(hand) {
let loc = this._findModificationIndex_helperColRow(hand);
if (loc === undefined) {
return undefined;
}
- 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 _drawColumn
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
_drawColumn(painter, gateColumn, col, hand, stats) {
this._drawColumnControlWires(painter, col);
this._drawColumnDragHighlight(painter, col);
for (let row = 0; row < this.circuitDefinition.numWires; row++) {
- 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 _drawLabelsReasonablyFast
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function _drawLabelsReasonablyFast(painter, dy, n, labeller, boundingWidth) {
Function drawCircuitTooltip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function drawCircuitTooltip(painter, circuitDefinition, rect, showWires, time) {
Function _previewDropMovedGateColumn
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
_previewDropMovedGateColumn(hand) {
if (hand.pos === undefined) {
return this;
}
let handWire = this.wireIndexAt(hand.pos.y);
- 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 _shiftAndSpliceColumn
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
_shiftAndSpliceColumn(rowShift, gatesOfCol, insertCol, isInsert) {
// Move gates upward.
while (rowShift < 0 && gatesOfCol[0] === undefined) {
gatesOfCol.shift();
gatesOfCol.push(undefined);
- 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 previewDrop
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
previewDrop(hand) {
return hand.heldRow !== undefined ? this._previewDropMovedRow(hand) :
hand.heldColumn !== undefined ? this._previewDropMovedGateColumn(hand) :
hand.heldGate !== undefined ? this._previewDropMovedGate(hand) :
this._previewResizedGate(hand);
- 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 GATE_CIRCUIT_DRAWER
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
let GATE_CIRCUIT_DRAWER = args => {
let circuit = args.gate.knownCircuit;
if (circuit === undefined || args.gate.symbol !== '') {
if (args.gate.stableDuration() === Infinity) {
GatePainting.DEFAULT_DRAWER(args);
- 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 tryGrab
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
tryGrab(hand, duplicate=false, wholeColumn=false, ignoreResizeTabs=false, alt=false) {
if (wholeColumn) {
let grabRowResult = this._tryGrabRow(hand, alt);
if (grabRowResult !== undefined) {
return grabRowResult;
- 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
if (measured) {
painter.strokeLine(new Point(x+1, y1), new Point(x+1, y2));
painter.strokeLine(new Point(x-1, y1), new Point(x-1, y2));
} else {
painter.strokeLine(new Point(x, y1), new Point(x, y2));
- 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 93.
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
if (args.isHighlighted) {
args.painter.ctx.save();
args.painter.ctx.globalAlpha *= 0.9;
args.painter.fillRect(args.rect, Config.HIGHLIGHTED_GATE_FILL_COLOR);
args.painter.ctx.restore();
- 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 90.
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
(c, r, v) => `mag²:${(v.norm2()*100).toFixed(4)}%, phase:${forceSign(v.phase() * 180 / Math.PI)}°`);
- 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 62.
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