File prototype_creep_resources.js
has 526 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict';
Creep.pickableResources = function(creep) {
return (object) => creep.pos.isNearTo(object);
};
Function universalBeforeStorage
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.universalBeforeStorage = function() {
this.creepLog(`universalBeforeStorage`);
if (this.store.getFreeCapacity() === 0 && this.store.getUsedCapacity(RESOURCE_ENERGY) === 0) {
const resourceToDrop = Object.keys(this.store)[0];
this.drop(resourceToDrop, this.store[resourceToDrop]);
- 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 pickupWhileMoving
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.pickupWhileMoving = function() {
if (this.inBase() && this.memory.routing.pathPos < 2) {
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"
Further reading
Function getEnergy
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.getEnergy = function() {
if (this.store.getFreeCapacity() === 0) {
return false;
}
/* State machine:
- 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 getTransferTargetStructure
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.getTransferTargetStructure = function() {
let structure = this.pos.findClosestStructureWithMissingEnergyByRange(
(object) => object.structureType !== STRUCTURE_STORAGE && object.structureType !== STRUCTURE_LINK,
);
// Universal should always prefer Spawn and Extensions
- 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 transferToStructures
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.transferToStructures = function() {
if (_.sum(this.store) === 0) {
return false;
}
Function getEnergy
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.getEnergy = function() {
if (this.store.getFreeCapacity() === 0) {
return false;
}
/* State machine:
Function universalBeforeStorage
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.universalBeforeStorage = function() {
this.creepLog(`universalBeforeStorage`);
if (this.store.getFreeCapacity() === 0 && this.store.getUsedCapacity(RESOURCE_ENERGY) === 0) {
const resourceToDrop = Object.keys(this.store)[0];
this.drop(resourceToDrop, this.store[resourceToDrop]);
Function pickupWhileMoving
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.pickupWhileMoving = function() {
if (this.inBase() && this.memory.routing.pathPos < 2) {
return false;
}
Function getEnergyFromSource
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Creep.prototype.getEnergyFromSource = function() {
let swarm = false;
let swarmSourcesFilter;
if (config.swarmSourceHarvestingMaxParts < this.body.filter((b) => b.type === WORK).length) {
swarm = true;
Function transferToStructures
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.transferToStructures = function() {
if (_.sum(this.store) === 0) {
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"
Further reading
Function transferAllResources
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.transferAllResources = function(structure) {
let transferred = false;
for (const resource in this.store) {
if (!resource) {
continue;
- 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 getEnergyFromSource
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.getEnergyFromSource = function() {
let swarm = false;
let swarmSourcesFilter;
if (config.swarmSourceHarvestingMaxParts < this.body.filter((b) => b.type === WORK).length) {
swarm = 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 construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.construct = function() {
let target;
if (this.memory.routing.targetId) {
target = Game.getObjectById(this.memory.routing.targetId);
this.creepLog('Use memory target', target);
- 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 filterTransferable
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
const filterTransferable = function(creep, object) {
if (!canStoreEnergy(object)) {
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"
Further reading
Avoid too many return
statements within this function. Open
return this.moveToSource(source, swarm);
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return this.giveSourcersEnergy();
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return this.getEnergyFromSource();
Function transferEnergy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.transferEnergy = function() {
const target = this.getTransferTarget();
if (!target) {
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"
Further reading
Function energyAcceptingLink
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
const energyAcceptingLink = function(object, room) {
if (object.structureType === STRUCTURE_LINK) {
for (let i = 0; i < 3; i++) {
const linkPos = room.data.positions.structure.link[i];
if (object.pos.isEqualTo(linkPos.x, linkPos.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 withdrawResourcesFromTargets
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.withdrawResourcesFromTargets = function(targets, onlyEnergy) {
let returnValue = false;
for (const target of targets) {
if (!returnValue) {
returnValue = onlyEnergy ? this.withdrawEnergyFromTarget(target) : this.withdrawResourcesFromTarget(target);
- 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 giveSourcersEnergy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.giveSourcersEnergy = function() {
let returnValue = false;
const sourcers = this.pos.findInRangeSourcer(1);
if (sourcers.length > 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 pickupEnergyFromGround
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Creep.prototype.pickupEnergyFromGround = function() {
const resources = this.pos.findInRange(FIND_DROPPED_RESOURCES, 1, {
filter: {resourceType: RESOURCE_ENERGY},
});
if (resources.length > 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
Creep.prototype.withdrawTombstone = function(onlyEnergy) {
onlyEnergy = onlyEnergy || false;
let returnValue = false;
// FIND_TOMBSTONES and get them empty first
const tombstones = this.pos.findInRange(FIND_TOMBSTONES, 1);
- 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 123.
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
Creep.prototype.withdrawRuin = function(onlyEnergy) {
onlyEnergy = onlyEnergy || false;
let returnValue = false;
// FIND_RUINS and get them empty first
const ruins = this.pos.findInRange(FIND_RUINS, 1);
- 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 123.
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