RocketChat/Rocket.Chat

View on GitHub
ee/apps/ddp-streamer/src/Client.ts

Summary

Maintainability
D
2 days
Test Coverage

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

    process(action: string, packet: IPacket): void {
        switch (action) {
            case DDP_EVENTS.PING:
                this.pong(packet.id);
                break;
Severity: Minor
Found in ee/apps/ddp-streamer/src/Client.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 constructor has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    constructor(public ws: WebSocket, public meteorClient = false, req: IncomingMessage) {
        super();

        this.connection = {
            id: this.session,
Severity: Minor
Found in ee/apps/ddp-streamer/src/Client.ts - About 1 hr to fix

    Function process has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        process(action: string, packet: IPacket): void {
            switch (action) {
                case DDP_EVENTS.PING:
                    this.pong(packet.id);
                    break;
    Severity: Minor
    Found in ee/apps/ddp-streamer/src/Client.ts - About 1 hr to fix

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

      const getClientAddress = (req: IncomingMessage): string | undefined => {
          // For the reported client address for a connection to be correct,
          // the developer must set the HTTP_FORWARDED_COUNT environment
          // variable to an integer representing the number of hops they
          // expect in the `x-forwarded-for` header. E.g., set to "1" if the
      Severity: Minor
      Found in ee/apps/ddp-streamer/src/Client.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

                          return;
      Severity: Major
      Found in ee/apps/ddp-streamer/src/Client.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            return this.ws.close(WS_ERRORS.CLOSE_PROTOCOL_ERROR);
        Severity: Major
        Found in ee/apps/ddp-streamer/src/Client.ts - About 30 mins to fix

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

                      case DDP_EVENTS.SUBSCRIBE:
                          if (!packet.name) {
                              return this.ws.close(WS_ERRORS.CLOSE_PROTOCOL_ERROR);
                          }
                          if (!packet.id) {
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 2 hrs to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 143..151

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

          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

                      case DDP_EVENTS.METHOD:
                          if (!packet.method) {
                              return this.ws.close(WS_ERRORS.CLOSE_PROTOCOL_ERROR);
                          }
                          if (!packet.id) {
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 2 hrs to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 152..160

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

          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

              async callMethod(packet: IPacket): Promise<void> {
                  this.chain = this.chain.then(() => server.call(this, packet)).catch();
              }
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 1 hr to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 134..136

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

          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

              async callSubscribe(packet: IPacket): Promise<void> {
                  this.chain = this.chain.then(() => server.subscribe(this, packet)).catch();
              }
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 1 hr to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 130..132

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

          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

              pong(id?: string): void {
                  this.send(server.serialize({ [DDP_EVENTS.MSG]: DDP_EVENTS.PONG, ...(id && { [DDP_EVENTS.ID]: id }) }));
              }
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 1 hr to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 178..180

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

          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

              ping(id?: string): void {
                  this.send(server.serialize({ [DDP_EVENTS.MSG]: DDP_EVENTS.PING, ...(id && { [DDP_EVENTS.ID]: id }) }));
              }
          Severity: Major
          Found in ee/apps/ddp-streamer/src/Client.ts and 1 other location - About 1 hr to fix
          ee/apps/ddp-streamer/src/Client.ts on lines 182..184

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

          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