Mirroar/hivemind

View on GitHub
src/spawn-role/remote-mining.ts

Summary

Maintainability
F
3 days
Test Coverage

File remote-mining.ts has 419 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global MOVE CLAIM BODYPART_COST CONTROLLER_RESERVE_MAX RESOURCE_ENERGY */

import BodyBuilder, {MOVEMENT_MODE_PLAINS, MOVEMENT_MODE_ROAD} from 'creep/body-builder';
import hivemind from 'hivemind';
import settings from 'settings-manager';
Severity: Minor
Found in src/spawn-role/remote-mining.ts - About 6 hrs to fix

    Function addHarvesterOptionForPosition has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        addHarvesterOptionForPosition(room: Room, position: RoomPosition, options: RemoteMiningSpawnOption[]) {
            const targetPos = encodePosition(position);
            const operation = Game.operationsByType.mining['mine:' + position.roomName];
    
            // Don't spawn if enemies are in the room.
    Severity: Minor
    Found in src/spawn-role/remote-mining.ts - About 4 hrs 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 addClaimerSpawnOptions has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        addClaimerSpawnOptions(room: Room, options: RemoteMiningSpawnOption[]) {
            if (options.length > 0) return;
    
            // Only spawn claimers if they can have 2 or more claim parts.
            // @todo We could even do it with 1 part if the controller has multiple
    Severity: Minor
    Found in src/spawn-role/remote-mining.ts - About 3 hrs 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

    RemoteMiningSpawnRole has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class RemoteMiningSpawnRole extends SpawnRole {
        /**
         * Adds claimer spawn options for the given room.
         *
         * @param {Room} room
    Severity: Minor
    Found in src/spawn-role/remote-mining.ts - About 2 hrs to fix

      Function addHarvesterOptionForPosition has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          addHarvesterOptionForPosition(room: Room, position: RoomPosition, options: RemoteMiningSpawnOption[]) {
              const targetPos = encodePosition(position);
              const operation = Game.operationsByType.mining['mine:' + position.roomName];
      
              // Don't spawn if enemies are in the room.
      Severity: Major
      Found in src/spawn-role/remote-mining.ts - About 2 hrs to fix

        Function addSkKillerOptionForPosition has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            addSkKillerOptionForPosition(room: Room, roomName: string, options: RemoteMiningSpawnOption[]) {
                const roomIntel = getRoomIntel(roomName);
                if (roomIntel.isClaimable()) return;
                if (_.size(roomIntel.getStructures(STRUCTURE_KEEPER_LAIR)) == 0) return;
        
        
        Severity: Minor
        Found in src/spawn-role/remote-mining.ts - 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 addClaimerSpawnOptions has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            addClaimerSpawnOptions(room: Room, options: RemoteMiningSpawnOption[]) {
                if (options.length > 0) return;
        
                // Only spawn claimers if they can have 2 or more claim parts.
                // @todo We could even do it with 1 part if the controller has multiple
        Severity: Minor
        Found in src/spawn-role/remote-mining.ts - About 1 hr to fix

          Function getCreepMemory has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              getCreepMemory(room: Room, option: RemoteMiningSpawnOption): CreepMemory {
                  switch (option.unitType) {
                      case 'builder':
                          return {
                              role: 'builder.mines',
          Severity: Minor
          Found in src/spawn-role/remote-mining.ts - About 1 hr to fix

            Function addSkKillerOptionForPosition has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                addSkKillerOptionForPosition(room: Room, roomName: string, options: RemoteMiningSpawnOption[]) {
                    const roomIntel = getRoomIntel(roomName);
                    if (roomIntel.isClaimable()) return;
                    if (_.size(roomIntel.getStructures(STRUCTURE_KEEPER_LAIR)) == 0) return;
            
            
            Severity: Minor
            Found in src/spawn-role/remote-mining.ts - About 1 hr to fix

              Avoid too many return statements within this function.
              Open

                      if (!body || body.length < MAX_CREEP_SIZE) return;
              Severity: Major
              Found in src/spawn-role/remote-mining.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return true;
                Severity: Major
                Found in src/spawn-role/remote-mining.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          if (harvesters.length >= freeSpots) return;
                  Severity: Major
                  Found in src/spawn-role/remote-mining.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            if (workParts >= operation.getHarvesterSize(targetPos) * requestedSaturation) return;
                    Severity: Major
                    Found in src/spawn-role/remote-mining.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              if (activeSkKillers.length > 0) return;
                      Severity: Major
                      Found in src/spawn-role/remote-mining.ts - About 30 mins to fix

                        Function addHaulerSpawnOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            addHaulerSpawnOptions(room: Room, options: RemoteMiningSpawnOption[]) {
                                // @todo Reduce needed carry parts to account for energy spent on road maintenance.
                                // @todo Reduce needed carry parts to account for higher throughput with relays.
                                const maximumNeededCarryParts = this.getMaximumCarryParts(room);
                                const maxHaulerSize = this.getMaximumHaulerSize(room, maximumNeededCarryParts);
                        Severity: Minor
                        Found in src/spawn-role/remote-mining.ts - 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

                            getSkKillerCreepBody(room: Room, option: SkKillerSpawnOption): BodyPartConstant[] {
                                return (new BodyBuilder())
                                    .setWeights({[ATTACK]: 4, [HEAL]: 1})
                                    .setMovementMode(MOVEMENT_MODE_PLAINS)
                                    .setMoveBufferRatio(1)
                        Severity: Major
                        Found in src/spawn-role/remote-mining.ts and 1 other location - About 2 hrs to fix
                        src/spawn-role/harvester.minerals.ts on lines 68..75

                        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 94.

                        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