Mirroar/hivemind

View on GitHub
src/empire/trade-route-manager.ts

Summary

Maintainability
D
1 day
Test Coverage

Function addResourceRequestOptions has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    private addResourceRequestOptions(options: TransportRouteOption[], room: Room, resourceType: ResourceConstant, roomState: RoomResourceState) {
        // Fullfill allies trade requests.
        for (const roomName2 in Memory?.requests?.trade?.[resourceType] || {}) {
            const info = Memory.requests.trade[resourceType][roomName2];
            if (Game.time - info.lastSeen > 10) {
Severity: Minor
Found in src/empire/trade-route-manager.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 getAvailableTransportRoutes has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public getAvailableTransportRoutes(): TransportRouteOption[] {
        const options = [];
        const rooms = this.getResourceStates();

        _.each(rooms, (roomState: RoomResourceState, roomName: string) => {
Severity: Major
Found in src/empire/trade-route-manager.ts - About 2 hrs to fix

    Function addResourceRequestOptions has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private addResourceRequestOptions(options: TransportRouteOption[], room: Room, resourceType: ResourceConstant, roomState: RoomResourceState) {
            // Fullfill allies trade requests.
            for (const roomName2 in Memory?.requests?.trade?.[resourceType] || {}) {
                const info = Memory.requests.trade[resourceType][roomName2];
                if (Game.time - info.lastSeen > 10) {
    Severity: Minor
    Found in src/empire/trade-route-manager.ts - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

                          if (room.terminal.store.energy < Game.market.calcTransactionCost(5000, roomName, roomName2)) return;
      Severity: Major
      Found in src/empire/trade-route-manager.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            if (room2.terminal.store.getFreeCapacity() < 5000) return;
        Severity: Major
        Found in src/empire/trade-route-manager.ts - About 30 mins to fix

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

              private getResourceTier(resourceType: ResourceConstant): number {
                  if (resourceType === RESOURCE_ENERGY) return 0;
                  if (resourceType === RESOURCE_POWER) return 10;
          
                  const tier = resourceType.length;
          Severity: Major
          Found in src/empire/trade-route-manager.ts and 1 other location - About 1 hr to fix
          src/process/trade.ts on lines 577..587

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

          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 (this.roomNeedsTerminalSpace(room) && resourceType !== RESOURCE_ENERGY) {
                          option.priority++;
                          if (room.terminal.store[resourceType] && room.terminal.store[resourceType] >= 5000) {
                              option.priority++;
                          }
          Severity: Major
          Found in src/empire/trade-route-manager.ts and 1 other location - About 1 hr to fix
          src/empire/trade-route-manager.ts on lines 84..92

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

          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 (this.roomNeedsTerminalSpace(room) && resourceType !== RESOURCE_ENERGY) {
                                  option.priority++;
                                  if (room.terminal.store[resourceType] && room.terminal.store[resourceType] >= 5000) {
                                      option.priority++;
                                  }
          Severity: Major
          Found in src/empire/trade-route-manager.ts and 1 other location - About 1 hr to fix
          src/empire/trade-route-manager.ts on lines 134..142

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

          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

                  return room.isEvacuating()
                      || (room.isClearingTerminal() && room.storage && room.storage.store.getFreeCapacity() < room.storage.store.getCapacity() * 0.3)
          Severity: Major
          Found in src/empire/trade-route-manager.ts and 1 other location - About 1 hr to fix
          src/empire/trade-route-manager.ts on lines 181..183

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

          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