TooAngel/screeps

View on GitHub
src/prototype_creep_resources.js

Summary

Maintainability
F
4 days
Test Coverage

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);
};
Severity: Major
Found in src/prototype_creep_resources.js - About 1 day to fix

    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]);
    Severity: Minor
    Found in src/prototype_creep_resources.js - About 1 hr to fix

    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;
      }
    
    
    Severity: Minor
    Found in src/prototype_creep_resources.js - About 1 hr to fix

    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:
    Severity: Minor
    Found in src/prototype_creep_resources.js - About 1 hr to fix

    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
    Severity: Minor
    Found in src/prototype_creep_resources.js - About 1 hr to fix

    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;
      }
    
    
    Severity: Minor
    Found in src/prototype_creep_resources.js - About 1 hr to fix

      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:
      Severity: Minor
      Found in src/prototype_creep_resources.js - About 1 hr to fix

        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]);
        Severity: Minor
        Found in src/prototype_creep_resources.js - About 1 hr to fix

          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;
            }
          
          
          Severity: Minor
          Found in src/prototype_creep_resources.js - About 1 hr to fix

            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;
            Severity: Minor
            Found in src/prototype_creep_resources.js - About 1 hr to fix

              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;
                }
              
              
              Severity: Minor
              Found in src/prototype_creep_resources.js - About 45 mins to fix

              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;
              Severity: Minor
              Found in src/prototype_creep_resources.js - About 45 mins to fix

              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;
              Severity: Minor
              Found in src/prototype_creep_resources.js - About 45 mins to fix

              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);
              Severity: Minor
              Found in src/prototype_creep_resources.js - About 45 mins to fix

              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;
                }
              
              
              Severity: Minor
              Found in src/prototype_creep_resources.js - About 35 mins to fix

              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);
              Severity: Major
              Found in src/prototype_creep_resources.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  return true;
                Severity: Major
                Found in src/prototype_creep_resources.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return false;
                  Severity: Major
                  Found in src/prototype_creep_resources.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return this.giveSourcersEnergy();
                    Severity: Major
                    Found in src/prototype_creep_resources.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return true;
                      Severity: Major
                      Found in src/prototype_creep_resources.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return true;
                        Severity: Major
                        Found in src/prototype_creep_resources.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                            return false;
                          Severity: Major
                          Found in src/prototype_creep_resources.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                              return this.getEnergyFromSource();
                            Severity: Major
                            Found in src/prototype_creep_resources.js - About 30 mins to fix

                              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;
                                }
                              Severity: Minor
                              Found in src/prototype_creep_resources.js - About 25 mins to fix

                              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)) {
                              Severity: Minor
                              Found in src/prototype_creep_resources.js - About 25 mins to fix

                              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);
                              Severity: Minor
                              Found in src/prototype_creep_resources.js - About 25 mins to fix

                              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) {
                              Severity: Minor
                              Found in src/prototype_creep_resources.js - About 25 mins to fix

                              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) {
                              Severity: Minor
                              Found in src/prototype_creep_resources.js - About 25 mins to fix

                              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);
                              Severity: Major
                              Found in src/prototype_creep_resources.js and 1 other location - About 4 hrs to fix
                              src/prototype_creep_resources.js on lines 142..155

                              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

                              Further Reading

                              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);
                              Severity: Major
                              Found in src/prototype_creep_resources.js and 1 other location - About 4 hrs to fix
                              src/prototype_creep_resources.js on lines 127..140

                              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

                              Further Reading

                              There are no issues that match your filters.

                              Category
                              Status