Mirroar/hivemind

View on GitHub
src/utils/cost-matrix.ts

Summary

Maintainability
F
3 days
Test Coverage

Function markBuildings has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
Open

function markBuildings(roomName: string, structures, constructionSites, roadCallback, blockerCallback, sourceKeeperCallback) {
    _.each(OBSTACLE_OBJECT_TYPES, structureType => {
        _.each(structures[structureType], structure => {
            // Can't walk through non-walkable buildings.
            blockerCallback(structure);
Severity: Minor
Found in src/utils/cost-matrix.ts - About 7 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 generateCombatCostMatrix has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function generateCombatCostMatrix(matrix: CostMatrix, roomName: string, blockDangerousTiles: boolean): CostMatrix {
    const newMatrix = matrix.clone();
    const terrain = new Room.Terrain(roomName);
    const dangerMatrix = new PathFinder.CostMatrix();

Severity: Minor
Found in src/utils/cost-matrix.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 markBuildings has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function markBuildings(roomName: string, structures, constructionSites, roadCallback, blockerCallback, sourceKeeperCallback) {
    _.each(OBSTACLE_OBJECT_TYPES, structureType => {
        _.each(structures[structureType], structure => {
            // Can't walk through non-walkable buildings.
            blockerCallback(structure);
Severity: Major
Found in src/utils/cost-matrix.ts - About 2 hrs to fix

    Function generateCombatCostMatrix has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function generateCombatCostMatrix(matrix: CostMatrix, roomName: string, blockDangerousTiles: boolean): CostMatrix {
        const newMatrix = matrix.clone();
        const terrain = new Room.Terrain(roomName);
        const dangerMatrix = new PathFinder.CostMatrix();
    
    
    Severity: Major
    Found in src/utils/cost-matrix.ts - About 2 hrs to fix

      Function getCostMatrix has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getCostMatrix(roomName: string, options?: CostMatrixOptions): CostMatrix {
          if (!options) {
              options = {};
          }
      
      
      Severity: Minor
      Found in src/utils/cost-matrix.ts - About 1 hr to fix

        Function generateQuadCostMatrix has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        function generateQuadCostMatrix(matrix: CostMatrix, roomName: string): CostMatrix {
            const newMatrix = matrix.clone();
            const terrain = new Room.Terrain(roomName);
        
            for (let x = 1; x < 49; x++) {
        Severity: Minor
        Found in src/utils/cost-matrix.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 getCostMatrix has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        function getCostMatrix(roomName: string, options?: CostMatrixOptions): CostMatrix {
            if (!options) {
                options = {};
            }
        
        
        Severity: Minor
        Found in src/utils/cost-matrix.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

        Consider simplifying this complex logical expression.
        Open

            if (
                matrix
                && !options.ignoreMilitary
                && !options.allowDanger
                && hivemind.segmentMemory.isReady()
        Severity: Major
        Found in src/utils/cost-matrix.ts - About 1 hr to fix

          Function generateSingleRoomCostMatrix has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function generateSingleRoomCostMatrix(matrix: CostMatrix, roomName: string): CostMatrix {
              const newMatrix = matrix.clone();
              const terrain = new Room.Terrain(roomName);
              for (let i = 1; i < 49; i++) {
                  if (terrain.get(i, 0) !== TERRAIN_MASK_WALL) newMatrix.set(i, 0, 50);
          Severity: Minor
          Found in src/utils/cost-matrix.ts - About 55 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 markBuildings has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function markBuildings(roomName: string, structures, constructionSites, roadCallback, blockerCallback, sourceKeeperCallback) {
          Severity: Minor
          Found in src/utils/cost-matrix.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (matrix.get(x, 49 - y) > 100) sourceKeeperCallback(x, y);
            Severity: Major
            Found in src/utils/cost-matrix.ts - About 45 mins to fix

              Avoid too many return statements within this function.
              Open

                          if (Game.rooms[roomName].roomPlanner.isPlannedLocation(newPos, 'wall')) return;
              Severity: Major
              Found in src/utils/cost-matrix.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            if (Game.rooms[roomName].roomPlanner.isPlannedLocation(newPos, 'wall')) return;
                Severity: Major
                Found in src/utils/cost-matrix.ts - About 30 mins to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                              else if (max < 5 && (
                                  terrain.get(x + 1, y) === TERRAIN_MASK_SWAMP
                                  || terrain.get(x, y + 1) === TERRAIN_MASK_SWAMP
                                  || terrain.get(x + 1, y + 1) === TERRAIN_MASK_SWAMP
                              )) {
                  Severity: Major
                  Found in src/utils/cost-matrix.ts and 1 other location - About 1 hr to fix
                  src/utils/cost-matrix.ts on lines 151..164

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

                  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

                              if (max < 255 && (
                                  terrain.get(x + 1, y) === TERRAIN_MASK_WALL
                                  || terrain.get(x, y + 1) === TERRAIN_MASK_WALL
                                  || terrain.get(x + 1, y + 1) === TERRAIN_MASK_WALL
                              )) {
                  Severity: Major
                  Found in src/utils/cost-matrix.ts and 1 other location - About 1 hr to fix
                  src/utils/cost-matrix.ts on lines 158..164

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

                  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

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                              if (terrain.get(x, y) === TERRAIN_MASK_WALL && !Game.rooms[roomName].roomPlanner.isPlannedLocation(newPos, 'road')) return;
                  Severity: Minor
                  Found in src/utils/cost-matrix.ts and 1 other location - About 30 mins to fix
                  src/utils/cost-matrix.ts on lines 233..233

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

                  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

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                              if (terrain.get(x, y) === TERRAIN_MASK_WALL && !Game.rooms[roomName].roomPlanner.isPlannedLocation(newPos, 'road')) return;
                  Severity: Minor
                  Found in src/utils/cost-matrix.ts and 1 other location - About 30 mins to fix
                  src/utils/cost-matrix.ts on lines 253..253

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

                  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