Mirroar/hivemind

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

Summary

Maintainability
F
4 days
Test Coverage

File brawler.ts has 313 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global RoomPosition MOVE ATTACK HEAL RANGED_ATTACK ATTACK_POWER
RANGED_ATTACK_POWER HEAL_POWER RESOURCE_ENERGY */

import BodyBuilder from 'creep/body-builder';
import cache from 'utils/cache';
Severity: Minor
Found in src/spawn-role/brawler.ts - About 3 hrs to fix

    Function getRemoteDefenseSpawnOptions has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        getRemoteDefenseSpawnOptions(room: Room, options: BrawlerSpawnOption[]) {
            const harvestPositions: RoomPosition[] = room.getRemoteHarvestSourcePositions();
            for (const pos of harvestPositions) {
                const operation = Game.operationsByType.mining['mine:' + pos.roomName];
    
    
    Severity: Minor
    Found in src/spawn-role/brawler.ts - About 2 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 getDefenseCreepSize has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        getDefenseCreepSize(room: Room, enemyData: EnemyData): number {
            // Default defense creep has 4 attack and 3 heal parts.
            const defaultAttack = 5;
            const defaultHeal = 3;
    
    
    Severity: Major
    Found in src/spawn-role/brawler.ts - About 2 hrs to fix

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

          getCreepBody(room: Room, option: BrawlerSpawnOption): BodyPartConstant[] {
              if (option.responseType) {
                  switch (option.responseType) {
                      case RESPONSE_MINI_BRAWLER:
                      case RESPONSE_FULL_BRAWLER:
      Severity: Minor
      Found in src/spawn-role/brawler.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 getDefenseCreepSize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          getDefenseCreepSize(room: Room, enemyData: EnemyData): number {
              // Default defense creep has 4 attack and 3 heal parts.
              const defaultAttack = 5;
              const defaultHeal = 3;
      
      
      Severity: Minor
      Found in src/spawn-role/brawler.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 getCreepMemory has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getCreepMemory(room: Room, option: BrawlerSpawnOption): CreepMemory {
              const memory = {
                  target: option.targetPos || encodePosition(room.controller.pos),
                  pathTarget: option.pathTarget,
                  operation: option.operation,
      Severity: Minor
      Found in src/spawn-role/brawler.ts - About 1 hr to fix

        Function getCreepBody has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            getCreepBody(room: Room, option: BrawlerSpawnOption): BodyPartConstant[] {
                if (option.responseType) {
                    switch (option.responseType) {
                        case RESPONSE_MINI_BRAWLER:
                        case RESPONSE_FULL_BRAWLER:
        Severity: Minor
        Found in src/spawn-role/brawler.ts - About 1 hr to fix

          Function canReclaimRoom has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              canReclaimRoom(targetRoom: Room, room: Room): boolean {
                  if (!targetRoom.needsReclaiming()) return false;
                  if (!targetRoom.isSafeForReclaiming()) return false;
                  if (!targetRoom.roomPlanner) return false;
          
          
          Severity: Minor
          Found in src/spawn-role/brawler.ts - 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

                      if (responseType === RESPONSE_NONE) return;
          Severity: Major
          Found in src/spawn-role/brawler.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        if (_.size(brawlers) > 0) return;
            Severity: Major
            Found in src/spawn-role/brawler.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

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

                Avoid too many return statements within this function.
                Open

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

                  Avoid too many return statements within this function.
                  Open

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

                    Avoid too many return statements within this function.
                    Open

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

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

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

                            Avoid too many return statements within this function.
                            Open

                                    if (route.incomplete) return false;
                            Severity: Major
                            Found in src/spawn-role/brawler.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

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

                                Avoid too many return statements within this function.
                                Open

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

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

                                      getReclaimSpawnOptions(room: Room, options: BrawlerSpawnOption[]) {
                                          if (room.getEffectiveAvailableEnergy() < 10_000) return;
                                  
                                          for (const targetRoom of Game.myRooms) {
                                              if (room.name === targetRoom.name) continue;
                                  Severity: Minor
                                  Found in src/spawn-role/brawler.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

                                      getBlinkyCreepBody(room: Room, maxAttackParts?: number): BodyPartConstant[] {
                                          return (new BodyBuilder())
                                              .setWeights({[RANGED_ATTACK]: 7, [HEAL]: 3})
                                              .setPartLimit(RANGED_ATTACK, maxAttackParts)
                                              .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
                                  Severity: Major
                                  Found in src/spawn-role/brawler.ts and 1 other location - About 4 hrs to fix
                                  src/spawn-role/brawler.ts on lines 340..347

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

                                  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

                                      getBrawlerCreepBody(room: Room, maxAttackParts?: number): BodyPartConstant[] {
                                          return (new BodyBuilder())
                                              .setWeights({[ATTACK]: 2, [HEAL]: 1})
                                              .setPartLimit(ATTACK, maxAttackParts)
                                              .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
                                  Severity: Major
                                  Found in src/spawn-role/brawler.ts and 1 other location - About 4 hrs to fix
                                  src/spawn-role/brawler.ts on lines 349..356

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

                                  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

                                      getAttackCreepBody(room: Room): BodyPartConstant[] {
                                          return (new BodyBuilder())
                                              .setWeights({[ATTACK]: 1})
                                              .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
                                              .setMoveBufferRatio(0.4)
                                  Severity: Major
                                  Found in src/spawn-role/brawler.ts and 1 other location - About 3 hrs to fix
                                  src/spawn-role/brawler.ts on lines 366..372

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

                                  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

                                      getRangedCreepBody(room: Room): BodyPartConstant[] {
                                          return (new BodyBuilder())
                                              .setWeights({[RANGED_ATTACK]: 1})
                                              .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
                                              .setMoveBufferRatio(0.4)
                                  Severity: Major
                                  Found in src/spawn-role/brawler.ts and 1 other location - About 3 hrs to fix
                                  src/spawn-role/brawler.ts on lines 358..364

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

                                  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