File creep.movement.ts
has 733 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* global Creep PowerCreep RoomVisual RoomPosition LOOK_CREEPS OK
LOOK_CONSTRUCTION_SITES ERR_NO_PATH LOOK_STRUCTURES LOOK_POWER_CREEPS */
import cache from 'utils/cache';
import container from 'utils/container';
Function getOntoCachedPath
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.getOntoCachedPath = function (this: Creep | PowerCreep) {
const creep = this;
const target = this.pos.findClosestByRange(this.getCachedPath(), {
filter: pos => {
// Try to move to a position on the path that is in the current room.
- 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 goTo
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.goTo = function (this: Creep | PowerCreep, target: RoomObject | RoomPosition, options: GoToOptions) {
if (!target) return false;
if (!options) options = {};
container.get('TrafficManager').setMoving(this);
- 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 moveUsingNavMesh
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.moveUsingNavMesh = function (this: Creep | PowerCreep, targetPos, options) {
if (!hivemind.segmentMemory.isReady()) return OK;
if (!options) options = {};
- 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 followCachedPath
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.followCachedPath = function (this: Creep | PowerCreep) {
drawCreepMovement(this);
container.get('TrafficManager').setMoving(this);
this.heapMemory._moveBlocked = 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"
Further reading
Function manageBlockingCreeps
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.manageBlockingCreeps = function (this: Creep | PowerCreep) {
const path = this.getCachedPath();
if (typeof this.memory.cachedPath.position === 'undefined' || this.memory.cachedPath.position === null) {
for (const pos of path) {
// @todo Look for the _furthest_ position that is in range 1.
- 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 getOntoCachedPath
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.getOntoCachedPath = function (this: Creep | PowerCreep) {
const creep = this;
const target = this.pos.findClosestByRange(this.getCachedPath(), {
filter: pos => {
// Try to move to a position on the path that is in the current room.
Function goTo
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.goTo = function (this: Creep | PowerCreep, target: RoomObject | RoomPosition, options: GoToOptions) {
if (!target) return false;
if (!options) options = {};
container.get('TrafficManager').setMoving(this);
Function moveUsingNavMesh
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.moveUsingNavMesh = function (this: Creep | PowerCreep, targetPos, options) {
if (!hivemind.segmentMemory.isReady()) return OK;
if (!options) options = {};
Function followCachedPath
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.followCachedPath = function (this: Creep | PowerCreep) {
drawCreepMovement(this);
container.get('TrafficManager').setMoving(this);
this.heapMemory._moveBlocked = false;
Function moveAroundObstacles
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.moveAroundObstacles = function (this: Creep | PowerCreep) {
const REMEMBER_POSITION_COUNT = 5;
// Record recent positions the creep has been on.
// @todo Using Game.time here is unwise in case the creep is being throttled.
Function drawCreepMovement
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function drawCreepMovement(creep: Creep | PowerCreep) {
if (!RoomVisual) return;
if (!settings.get('visualizeCreepMovement')) return;
if (settings.get('disableRoomVisuals')) 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 drawCreepMovement
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function drawCreepMovement(creep: Creep | PowerCreep) {
if (!RoomVisual) return;
if (!settings.get('visualizeCreepMovement')) return;
if (settings.get('disableRoomVisuals')) return;
Function moveAroundObstacles
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.moveAroundObstacles = function (this: Creep | PowerCreep) {
const REMEMBER_POSITION_COUNT = 5;
// Record recent positions the creep has been on.
// @todo Using Game.time here is unwise in case the creep is being throttled.
- 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 manageBlockingCreeps
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.manageBlockingCreeps = function (this: Creep | PowerCreep) {
const path = this.getCachedPath();
if (typeof this.memory.cachedPath.position === 'undefined' || this.memory.cachedPath.position === null) {
for (const pos of path) {
// @todo Look for the _furthest_ position that is in range 1.
Function interRoomTravel
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.interRoomTravel = function (this: Creep | PowerCreep, targetPos, allowDanger = false): boolean {
const isInTargetRoom = this.pos.roomName === targetPos.roomName;
if (!isInTargetRoom || (!this.isInRoom() && this.getNavMeshMoveTarget())) {
if (this.heapMemory.moveWithoutNavMesh) {
if (!this.moveToRoom(targetPos.roomName, allowDanger)) {
- 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 setCachedPath
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.setCachedPath = function (this: Creep | PowerCreep, path, reverse, distance) {
path = _.clone(path);
if (reverse || distance) {
const originalPath = deserializePositionPath(path);
if (reverse) {
- 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 canMoveOnto
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.canMoveOnto = function (this: Creep | PowerCreep, position) {
const creeps = position.lookFor(LOOK_CREEPS);
if (creeps.length > 0 && creeps[0].id !== this.id && !isMovingCreep(creeps[0])) return false;
const powerCreeps = position.lookFor(LOOK_POWER_CREEPS);
- 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 (costs.get(pos.x, pos.y) <= 20) {
costs.set(pos.x, pos.y, 20);
}
Function incrementCachedPathPosition
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.incrementCachedPathPosition = function (this: Creep | PowerCreep) {
// Check if we've already moved onto the next position.
const path = this.getCachedPath();
const next = path[this.memory.cachedPath.position + 1];
if (!next) {
- 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 OK;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
if (!pos || pos.roomName !== this.pos.roomName) return;
Avoid too many return
statements within this function. Open
if (!target) return;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return ERR_NO_PATH;
Avoid too many return
statements within this function. Open
if (this.moveAroundObstacles()) return;
Avoid too many return
statements within this function. Open
if (lineStartPos.roomName !== target.roomName) return;
Avoid too many return
statements within this function. Open
if (portalUsed) return OK;
Avoid too many return
statements within this function. Open
if (this.memory.cachedPath.arrived) return;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return OK;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return ERR_NO_PATH;
Avoid too many return
statements within this function. Open
return;
Function calculatePath
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.calculatePath = function (this: Creep | PowerCreep, target: RoomPosition, options?: GoToOptions): RoomPosition[] {
if (!options) options = {};
// @todo Properly type this.
const pfOptions: any = {};
- 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 moveToRoom
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.moveToRoom = function (this: Creep | PowerCreep, roomName, allowDanger) {
// Make sure we recalculate path if target changes.
if (this.heapMemory._mtrTarget !== roomName) {
delete this.heapMemory._mtrNextRoom;
this.heapMemory._mtrTarget = roomName;
- 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 (path[0].roomName === this.pos.roomName) {
this.move(this.pos.getDirectionTo(path[0]));
const creep = path[0].lookFor(LOOK_CREEPS)[0];
if (creep) container.get('TrafficManager').setBlockingCreep(this, creep);
- 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 167.
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 (path[0].roomName === this.pos.roomName) {
this.move(this.pos.getDirectionTo(path[0]));
const creep = path[0].lookFor(LOOK_CREEPS)[0];
if (creep) container.get('TrafficManager').setBlockingCreep(this, creep);
- 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 167.
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 (settings.get('visualizeCreepMovement') && !settings.get('disableRoomVisuals')) {
this.room.visual.poly(path, {
fill: 'transparent',
stroke: '#fff',
lineStyle: 'dashed',
- 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 75.
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 (settings.get('visualizeCreepMovement') && !settings.get('disableRoomVisuals')) {
this.room.visual.poly(path, {
fill: 'transparent',
stroke: '#f00',
lineStyle: 'dashed',
- 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 75.
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
_.each(Game.rooms[roomName].roomPlanner.getLocations('bay_center'), pos => {
if (costs.get(pos.x, pos.y) <= 20) {
costs.set(pos.x, pos.y, 20);
}
});
- 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 56.
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 (powerCreeps.length > 0 && powerCreeps[0].id !== this.id && !isMovingCreep(powerCreeps[0])) return false;
- 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 (creeps.length > 0 && creeps[0].id !== this.id && !isMovingCreep(creeps[0])) return false;
- 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 (pos.x === 0 || pos.x === 49 || pos.y === 0 || pos.y === 49) return false;
- 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 45.
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