src/prototype_room_keeper.js
Function spawnKeepersEveryTicks
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
Open
Room.prototype.spawnKeepersEveryTicks = function(ticks) {
let returnValue = false;
const baseRoom = Game.rooms[this.data.base];
if (baseRoom && baseRoom.controller) {
if (baseRoom.controller.level >= config.keepers.minControllerLevel) {
- 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 spawnKeepers
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
Room.prototype.spawnKeepers = function() {
const room = this;
const keeperPositions = this.data.keepers;
const baseRoom = Game.rooms[this.data.base];
const amount = 1;
Avoid deeply nested control flow statements. Open
Open
if (returnValue && returnValue[0] && returnValue[0][0] && returnValue[0][0].success) {
this.log('spawnKeepers', JSON.stringify(returnValue[0]));
}
Function findKeepersAt
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
Room.prototype.findKeepersAt = function(roles, posId) {
const s = Game.getObjectById(posId);
const type = s.energy > 0 ? 'energy' : ((s.mineralAmount > 0) ? 'mineral' : 'offline');
const amount = (s.energy > 1000) ? s.energy : ((s.mineralAmount > 2000) ? s.mineralAmount : false);
const room = 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"