uu-cubitt/events

View on GitHub
src/EventFactory.ts

Summary

Maintainability
F
1 wk
Test Coverage

File EventFactory.ts has 371 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as Common from "cubitt-common";

import {EventType} from "./EventType";
import {Event} from "./events/Event";
import {ConnectorAddedEvent} from "./events/ConnectorAddedEvent";
Severity: Minor
Found in src/EventFactory.ts - About 4 hrs to fix

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

        public static parse(jsonObject: Object): Event {
            if (typeof(jsonObject) === "undefined" || jsonObject === null) {
                throw new Error("EVENT ERROR: Empty object cannot be parsed.");
            }
    
    
    Severity: Minor
    Found in src/EventFactory.ts - About 1 hr to fix

      Function validateObject has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          protected static validateObject(object: Object, keysWithType: Common.Dictionary<ValidationType>): void {
              for (let key in keysWithType) {
                  let type: ValidationType = keysWithType[key];
                  let val: any = object[key];
                  if (typeof(val) === "undefined") {
      Severity: Minor
      Found in src/EventFactory.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 getEventType has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected static getEventType(type: string): EventType {
              switch (type) {
                  case "ConnectorAddedEvent":
                      return EventType.ConnectorAdded;
                  case "EdgeAddedEvent":
      Severity: Minor
      Found in src/EventFactory.ts - About 1 hr to fix

        Function validateObject has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected static validateObject(object: Object, keysWithType: Common.Dictionary<ValidationType>): void {
                for (let key in keysWithType) {
                    let type: ValidationType = keysWithType[key];
                    let val: any = object[key];
                    if (typeof(val) === "undefined") {
        Severity: Minor
        Found in src/EventFactory.ts - About 1 hr to fix

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

              protected static parseConnectorAddedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ConnectorAddedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["elementType"] = ValidationType.String;
                  keys["nodeId"] = ValidationType.Guid;
                  let properties: Object = EventFactory.parseProperties(jsonObject["properties"]);
          Severity: Major
          Found in src/EventFactory.ts and 1 other location - About 1 day to fix
          src/EventFactory.ts on lines 265..280

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

          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

              protected static parseNodeAddedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): NodeAddedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["elementType"] = ValidationType.String;
                  keys["modelId"] = ValidationType.Guid;
                  let properties: Object = EventFactory.parseProperties(jsonObject["properties"]);
          Severity: Major
          Found in src/EventFactory.ts and 1 other location - About 1 day to fix
          src/EventFactory.ts on lines 190..205

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

          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 3 locations. Consider refactoring.
          Open

              protected static parseConnectorPropertySetEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ConnectorPropertySetEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  keys["propertyValue"] = ValidationType.Any;
                  EventFactory.validateObject(jsonObject, keys);
          Severity: Major
          Found in src/EventFactory.ts and 2 other locations - About 6 hrs to fix
          src/EventFactory.ts on lines 453..466
          src/EventFactory.ts on lines 474..487

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

          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 3 locations. Consider refactoring.
          Open

              protected static parseEdgePropertySetEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): EdgePropertySetEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  keys["propertyValue"] = ValidationType.Any;
                  EventFactory.validateObject(jsonObject, keys);
          Severity: Major
          Found in src/EventFactory.ts and 2 other locations - About 6 hrs to fix
          src/EventFactory.ts on lines 432..445
          src/EventFactory.ts on lines 474..487

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

          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 3 locations. Consider refactoring.
          Open

              protected static parseModelPropertySetEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ModelPropertySetEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  keys["propertyValue"] = ValidationType.Any;
                  EventFactory.validateObject(jsonObject, keys);
          Severity: Major
          Found in src/EventFactory.ts and 2 other locations - About 6 hrs to fix
          src/EventFactory.ts on lines 432..445
          src/EventFactory.ts on lines 453..466

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseConnectorPropertyDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ConnectorPropertyDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  EventFactory.validateObject(jsonObject, keys);
                  return new ConnectorPropertyDeletedEvent(
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 5 hrs to fix
          src/EventFactory.ts on lines 375..386
          src/EventFactory.ts on lines 394..405
          src/EventFactory.ts on lines 413..424

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseNodePropertyDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): NodePropertyDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  EventFactory.validateObject(jsonObject, keys);
                  return new NodePropertyDeletedEvent(
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 5 hrs to fix
          src/EventFactory.ts on lines 356..367
          src/EventFactory.ts on lines 375..386
          src/EventFactory.ts on lines 394..405

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseModelPropertyDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ModelPropertyDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  EventFactory.validateObject(jsonObject, keys);
                  return new ModelPropertyDeletedEvent(
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 5 hrs to fix
          src/EventFactory.ts on lines 356..367
          src/EventFactory.ts on lines 375..386
          src/EventFactory.ts on lines 413..424

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseEdgePropertyDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): EdgePropertyDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  keys["propertyName"] = ValidationType.String;
                  EventFactory.validateObject(jsonObject, keys);
                  return new EdgePropertyDeletedEvent(
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 5 hrs to fix
          src/EventFactory.ts on lines 356..367
          src/EventFactory.ts on lines 394..405
          src/EventFactory.ts on lines 413..424

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseEdgeDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): EdgeDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  EventFactory.validateObject(jsonObject, keys);
                  return new EdgeDeletedEvent(
                      Common.Guid.parse(jsonObject["sourceId"]),
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 4 hrs to fix
          src/EventFactory.ts on lines 288..297
          src/EventFactory.ts on lines 322..331
          src/EventFactory.ts on lines 339..348

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseModelDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ModelDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  EventFactory.validateObject(jsonObject, keys);
                  return new ModelDeletedEvent(
                      Common.Guid.parse(jsonObject["sourceId"]),
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 4 hrs to fix
          src/EventFactory.ts on lines 288..297
          src/EventFactory.ts on lines 305..314
          src/EventFactory.ts on lines 339..348

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseConnectorDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): ConnectorDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  EventFactory.validateObject(jsonObject, keys);
                  return new ConnectorDeletedEvent(
                      Common.Guid.parse(jsonObject["sourceId"]),
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 4 hrs to fix
          src/EventFactory.ts on lines 305..314
          src/EventFactory.ts on lines 322..331
          src/EventFactory.ts on lines 339..348

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

          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 4 locations. Consider refactoring.
          Open

              protected static parseNodeDeletedEvent(jsonObject: Object, keys: Common.Dictionary<ValidationType>): NodeDeletedEvent {
                  keys["elementId"] = ValidationType.Guid;
                  EventFactory.validateObject(jsonObject, keys);
                  return new NodeDeletedEvent(
                      Common.Guid.parse(jsonObject["sourceId"]),
          Severity: Major
          Found in src/EventFactory.ts and 3 other locations - About 4 hrs to fix
          src/EventFactory.ts on lines 288..297
          src/EventFactory.ts on lines 305..314
          src/EventFactory.ts on lines 322..331

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

          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