Mirroar/hivemind

View on GitHub
src/spawn-role/upgrader.ts

Summary

Maintainability
C
1 day
Test Coverage

Function getBaseUpgraderAmount has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    getBaseUpgraderAmount(room: Room): number {
        // Early on, builders will take care of upgrading once necessary
        // structures have been built.
        if (!room.storage && !room.terminal) return 0;

Severity: Minor
Found in src/spawn-role/upgrader.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

Avoid too many return statements within this function.
Open

        if (isFunneling && availableEnergy < 100_000) return 0;
Severity: Major
Found in src/spawn-role/upgrader.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            if (room.controller.level === 8 && !balancer.maySpendEnergyOnGpl()) return 0;
    Severity: Major
    Found in src/spawn-role/upgrader.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              if (availableEnergy < 150_000) return isFunneling ? 4 : 3;
      Severity: Major
      Found in src/spawn-role/upgrader.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return 1;
        Severity: Major
        Found in src/spawn-role/upgrader.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  if (availableEnergy < (room.controller.level === 7 ? 25_000 : 10_000)) return 0;
          Severity: Major
          Found in src/spawn-role/upgrader.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    if (availableEnergy < (room.controller.level === 7 ? 75_000 : 50_000)) return 1;
            Severity: Major
            Found in src/spawn-role/upgrader.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return isFunneling ? 5 : 4;
              Severity: Major
              Found in src/spawn-role/upgrader.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        if (availableEnergy < 100_000) return 2;
                Severity: Major
                Found in src/spawn-role/upgrader.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              if (availableEnergy < hivemind.settings.get('minEnergyToUpgradeAtRCL8')) return 0;
                  Severity: Major
                  Found in src/spawn-role/upgrader.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            if (availableEnergy < 125_000 && isFunneling) return 3;
                    Severity: Major
                    Found in src/spawn-role/upgrader.ts - About 30 mins to fix

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

                          getCreepBody(room: Room, option: UpgraderSpawnOption): BodyPartConstant[] {
                              const hasEasyEnergyAccess = room.memory.controllerContainer || room.memory.controllerLink;
                      
                              return (new BodyBuilder())
                                  .setWeights({[CARRY]: 1, [WORK]: hasEasyEnergyAccess ? 10 : 1})
                      Severity: Minor
                      Found in src/spawn-role/upgrader.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

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

                          getUpgraderAmount(room: Room): number {
                              const maxUpgraders = this.getBaseUpgraderAmount(room);
                      
                              if (maxUpgraders === 0) {
                                  // Even if no upgraders are needed, at least create one when the controller is getting close to being downgraded.
                      Severity: Minor
                      Found in src/spawn-role/upgrader.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

                      There are no issues that match your filters.

                      Category
                      Status