mikro-orm/mikro-orm

View on GitHub
packages/core/src/entity/EntityAssigner.ts

Summary

Maintainability
C
1 day
Test Coverage
A
100%

Function assignProperty has a Cognitive Complexity of 38 (exceeds 7 allowed). Consider refactoring.
Open

  private static assignProperty<T extends object, C extends boolean>(entity: T, propName: string, props: Dictionary<EntityProperty<T>>, data: Dictionary, options: InternalAssignOptions<C>) {
    if (options.onlyProperties && !(propName in props)) {
      return;
    }

Severity: Minor
Found in packages/core/src/entity/EntityAssigner.ts - About 5 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 assignCollection has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
Open

  private static assignCollection<T extends object, U extends object = AnyEntity, C extends boolean = false>(entity: T, collection: Collection<U>, value: unknown, prop: EntityProperty, em: EntityManager | undefined, options: AssignOptions<C>): void {
    const invalid: any[] = [];
    const items = Utils.asArray(value).map((item: any, idx) => {
      // try to propagate missing owning side reference to the payload first
      const prop2 = prop.targetMeta?.properties[prop.mappedBy];
Severity: Minor
Found in packages/core/src/entity/EntityAssigner.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

Avoid deeply nested control flow statements.
Open

            if (wrappedChild.__managed && wrappedChild.isInitialized() && sameTarget) {
              return EntityAssigner.assign(ref, value as any, options);
            }
Severity: Major
Found in packages/core/src/entity/EntityAssigner.ts - About 45 mins to fix

    Function assignEmbeddable has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
    Open

      private static assignEmbeddable<T extends object, C extends boolean>(entity: T, value: any, prop: EntityProperty<T>, em: EntityManager | undefined, options: InternalAssignOptions<C>): void {
        const propName = prop.embedded ? prop.embedded[1] : prop.name;
    
        if (value == null) {
          entity[propName] = value;
    Severity: Minor
    Found in packages/core/src/entity/EntityAssigner.ts - About 45 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 entity[prop.name] = validator.validateProperty(prop, value, entity);
    Severity: Major
    Found in packages/core/src/entity/EntityAssigner.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return EntityAssigner.assignEmbeddable(entity, value, prop, options.em, options);
      Severity: Major
      Found in packages/core/src/entity/EntityAssigner.ts - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status