mimiz/rabbitmq-event-manager

View on GitHub

Showing 28 of 28 total issues

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

export async function deleteExchange(channel: amqp.ConfirmChannel, exchangeName: string): Promise<void> {
  LOGGER.debug(`Delete Exchange ${exchangeName}`);
  try {
    await channel.deleteExchange(exchangeName);
    LOGGER.debug(`Exchange ${exchangeName} deleted`);
Severity: Major
Found in src/adapter/helper/deleteExchange.ts and 1 other location - About 5 hrs to fix
src/adapter/helper/deleteQueue.ts on lines 4..13

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

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

export async function deleteQueue(channel: amqp.ConfirmChannel, queueName: string): Promise<void> {
  LOGGER.debug(`Delete Queue ${queueName}`);
  try {
    await channel.deleteQueue(queueName);
    LOGGER.debug(`Queue ${queueName} deleted`);
Severity: Major
Found in src/adapter/helper/deleteQueue.ts and 1 other location - About 5 hrs to fix
src/adapter/helper/deleteExchange.ts on lines 4..13

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

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

function emitter() {
  const payload = {
    user: {
      id: 1,
      first: 'Remi',
Severity: Major
Found in demo/docker/run.ts and 1 other location - About 3 hrs to fix
demo/cloudamqp/run.ts on lines 50..64

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

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

function emitter() {
  const payload = {
    user: {
      id: 1,
      first: 'Remi',
Severity: Major
Found in demo/cloudamqp/run.ts and 1 other location - About 3 hrs to fix
demo/docker/run.ts on lines 47..61

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

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

eventManagerProducer
  .initialize()
  .then(async () => {
    // Initialize consumer
    consumer();
Severity: Major
Found in demo/docker/run.ts and 1 other location - About 3 hrs to fix
demo/cloudamqp/run.ts on lines 18..40

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

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

eventManagerProducer
  .initialize()
  .then(async () => {
    // Initialize consumer
    consumer();
Severity: Major
Found in demo/cloudamqp/run.ts and 1 other location - About 3 hrs to fix
demo/docker/run.ts on lines 16..37

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

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

function consumer() {
  eventManagerConsumer.on('PRODUCER.EVENT', async (payload: any) => {
    console.log('message received', payload);
    switch (payload.action) {
      case 'FLUSH':
Severity: Major
Found in demo/cloudamqp/run.ts and 1 other location - About 2 hrs to fix
demo/docker/run.ts on lines 63..76

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

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

function consumer() {
  eventManagerConsumer.on('PRODUCER.EVENT', async (payload: any) => {
    console.log('message received', payload);
    switch (payload.action) {
      case 'FLUSH':
Severity: Major
Found in demo/docker/run.ts and 1 other location - About 2 hrs to fix
demo/cloudamqp/run.ts on lines 66..79

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

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

Function emitAndWait has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public async emitAndWait(eventName: string, payload: IEventPayload, replyToName?: string, options?: IEmitAndWaitOptions): Promise<IEventPayload> {
    return new Promise(async (resolve, reject) => {
      LOGGER.info(`Emitting ${eventName} Message and waiting ...`);
      LOGGER.debug(`Event ${eventName}, payload received`, { payload, replyToName });
      let replyTo = replyToName ? replyToName : `${eventName}${this.options.defaultResponseSuffix}`;
Severity: Major
Found in src/EventManager.class.ts - About 2 hrs to fix

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

    async function closeAll() {
      await eventManagerConsumer.close();
      await eventManagerProducer.close();
      console.log('You should have 2 messages in the DEAD_LETTER_QUEUE');
      console.log('You should have 1 messages in the QUEUE_NO_QUEUE');
    Severity: Major
    Found in demo/docker/run.ts and 1 other location - About 1 hr to fix
    demo/cloudamqp/run.ts on lines 81..87

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

    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

    async function closeAll() {
      await eventManagerConsumer.close();
      await eventManagerProducer.close();
      console.log('You should have 2 messages in the DEAD_LETTER_QUEUE');
      console.log('You should have 1 messages in the QUEUE_NO_QUEUE');
    Severity: Major
    Found in demo/cloudamqp/run.ts and 1 other location - About 1 hr to fix
    demo/docker/run.ts on lines 78..84

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

    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

    Function consume has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function consume(channel: amqp.Channel, queueName: string, listener: ConsumeHandlerFunction, options: IEventManagerOptions): Promise<IEventPayload | void | null> {
      LOGGER.info(`Consume messages of queue  ${queueName}`);
      return new Promise((resolve, reject) => {
        try {
          channel.consume(queueName, message => {
    Severity: Minor
    Found in src/adapter/helper/consume.ts - About 1 hr to fix

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

        public async on(eventName: string, listener: EventHandlerFunction, options?: IListenerOption) {
          try {
            LOGGER.debug(`Listening ${eventName} Event ...`);
            const channel = await adapter.createChannel(this.options.url);
            const queueName = `${this.options.application}::${eventName}`;
      Severity: Minor
      Found in src/EventManager.class.ts - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            if (
              sourcePayload &&
              sourcePayload._metas &&
              sourcePayload._metas.correlationId &&
              sourcePayload._metas.replyTo &&
        Severity: Major
        Found in src/EventManager.class.ts - About 40 mins to fix

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

          async function pause(n: number) {
            return new Promise(resolve => {
              setTimeout(() => {
                resolve();
              }, n);
          Severity: Minor
          Found in demo/cloudamqp/run.ts and 1 other location - About 35 mins to fix
          demo/docker/run.ts on lines 39..45

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

          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

          async function pause(n: number) {
            return new Promise(resolve => {
              setTimeout(() => {
                resolve();
              }, n);
          Severity: Minor
          Found in demo/docker/run.ts and 1 other location - About 35 mins to fix
          demo/cloudamqp/run.ts on lines 42..48

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

          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

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

            private addMetasToPayload(payload: IEventPayload, eventName: string): IEventPayload {
              if (!this.options.metas) {
                return payload;
              } else {
                const metasOverride = payload._metas ? payload._metas : {};
          Severity: Minor
          Found in src/EventManager.class.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

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

            public async on(eventName: string, listener: EventHandlerFunction, options?: IListenerOption) {
              try {
                LOGGER.debug(`Listening ${eventName} Event ...`);
                const channel = await adapter.createChannel(this.options.url);
                const queueName = `${this.options.application}::${eventName}`;
          Severity: Minor
          Found in src/EventManager.class.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

          Calls to 'console.log' are not allowed.
          Open

            console.log('You should have 2 messages in the DEAD_LETTER_QUEUE');
          Severity: Minor
          Found in demo/docker/run.ts by tslint

          Rule: no-console

          Bans the use of specified console methods.

          Rationale

          In general, console methods aren't appropriate for production code.

          Config

          A list of method names to ban. If no method names are provided, all console methods are banned.

          Examples
          "no-console": true,log,error
          Schema
          {
            "type": "array",
            "items": {
              "type": "string"
            }
          }

          For more information see this page.

          Calls to 'console.log' are not allowed.
          Open

            console.log('You should have 1 messages in the QUEUE_NO_QUEUE');
          Severity: Minor
          Found in demo/docker/run.ts by tslint

          Rule: no-console

          Bans the use of specified console methods.

          Rationale

          In general, console methods aren't appropriate for production code.

          Config

          A list of method names to ban. If no method names are provided, all console methods are banned.

          Examples
          "no-console": true,log,error
          Schema
          {
            "type": "array",
            "items": {
              "type": "string"
            }
          }

          For more information see this page.

          Severity
          Category
          Status
          Source
          Language