mikro-orm/mikro-orm

View on GitHub

Showing 34 of 34 total issues

Function clone has a Cognitive Complexity of 59 (exceeds 7 allowed). Consider refactoring.
Open

export function clone<T>(parent: T, respectCustomCloneMethod = true): T {
  const allParents: unknown[] = [];
  const allChildren: unknown[] = [];

  function _clone(parent: any) {
Severity: Minor
Found in packages/core/src/utils/clone.ts - About 1 day 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 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

Consider simplifying this complex logical expression.
Open

      if (
        !prop.nullable &&
        !prop.autoincrement &&
        !prop.default &&
        !prop.defaultRaw &&
Severity: Critical
Found in packages/core/src/entity/EntityValidator.ts - About 2 hrs to fix

    Function handler has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
    Open

      async handler() {
        CLIHelper.dump(`Current ${colors.cyan('MikroORM')} CLI configuration`);
        await CLIHelper.dumpDependencies();
        const settings = ConfigurationLoader.getSettings();
    
    
    Severity: Minor
    Found in packages/cli/src/commands/DebugCommand.ts - About 2 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 create has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
    Open

      create<T extends object, P extends string = string>(entityName: EntityName<T>, data: EntityData<T>, options: FactoryOptions = {}): New<T, P> {
        data = Reference.unwrapReference(data as T);
        options.initialized ??= true;
    
        if ((data as Dictionary).__entity) {
    Severity: Minor
    Found in packages/core/src/entity/EntityFactory.ts - About 2 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 propagateToOwningSide has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
    Open

      protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void {
        const mappedBy = this.property.mappedBy as EntityKey<T>;
        const collection = item[mappedBy] as ArrayCollection<O, T>;
    
        if (this.property.kind === ReferenceKind.MANY_TO_MANY) {
    Severity: Minor
    Found in packages/core/src/entity/ArrayCollection.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 logQuery has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

      logQuery(context: { query: string } & LogContext): void {
        if (!this.isEnabled('query', context)) {
          return;
        }
    
    
    Severity: Minor
    Found in packages/core/src/logging/DefaultLogger.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 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

    Function processProperty has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

      private static processProperty<Entity extends object>(prop: EntityKey<Entity>, entity: Entity, raw: boolean, populated: boolean): EntityValue<Entity> | undefined {
        const wrapped = helper(entity);
        const property = wrapped.__meta.properties[prop];
        const serializer = property?.serializer;
        const value = entity[prop];
    Severity: Minor
    Found in packages/core/src/serialization/EntityTransformer.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 createEntity has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
    Open

      private createEntity<T extends object>(data: EntityData<T>, meta: EntityMetadata<T>, options: FactoryOptions): T {
        if (options.newEntity || meta.forceConstructor || meta.virtual) {
          if (!meta.class) {
            throw new Error(`Cannot create entity ${meta.className}, class prototype is unknown`);
          }
    Severity: Minor
    Found in packages/core/src/entity/EntityFactory.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 processProperty has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
    Open

      private static processProperty<T extends object>(prop: EntityKey<T>, entity: T, options: SerializeOptions<T, any, any>): EntityValue<T> | undefined {
        const parts = prop.split('.');
        prop = parts[0] as EntityKey<T>;
        const wrapped = helper(entity);
        const property = wrapped.__meta.properties[prop];
    Severity: Minor
    Found in packages/core/src/serialization/EntitySerializer.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 processWhere has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
    Open

      static processWhere<T extends object>(options: ProcessWhereOptions<T>): FilterQuery<T> {
        // eslint-disable-next-line prefer-const
        let { where, entityName, metadata, platform, aliased = true, convertCustomTypes = true, root = true } = options;
        const meta = metadata.find<T>(entityName);
    
    
    Severity: Minor
    Found in packages/core/src/utils/QueryHelper.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

    Consider simplifying this complex logical expression.
    Open

        if (!prop.type && (!type || (type === Object && prop.kind !== ReferenceKind.SCALAR)) && !(prop.enum && (prop.items?.length ?? 0) > 0)) {
          throw new Error(`Please provide either 'type' or 'entity' attribute in ${meta.className}.${prop.name}. If you are using decorators, ensure you have 'emitDecoratorMetadata' enabled in your tsconfig.json.`);
        }
    Severity: Major
    Found in packages/core/src/metadata/ReflectMetadataProvider.ts - About 1 hr to fix

      Function handleSchemaCommand has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
      Open

        static async handleSchemaCommand(args: ArgumentsCamelCase<Options>, method: SchemaMethod, successMessage: string) {
          if (!args.run && !args.dump) {
            return CLIHelper.showHelp();
          }
      
      
      Severity: Minor
      Found in packages/cli/src/commands/SchemaCommandFactory.ts - About 55 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 createReference has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
      Open

        createReference<T extends object>(entityName: EntityName<T>, id: Primary<T> | Primary<T>[] | Record<string, Primary<T>>, options: Pick<FactoryOptions, 'merge' | 'convertCustomTypes' | 'schema'> = {}): T {
          options.convertCustomTypes ??= true;
          entityName = Utils.className(entityName);
          const meta = this.metadata.get<T>(entityName);
          const schema = this.driver.getSchemaName(meta, options);
      Severity: Minor
      Found in packages/core/src/entity/EntityFactory.ts - About 55 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 toObject has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
      Open

        static toObject<Entity extends object, Ignored extends EntityKey<Entity> = never>(entity: Entity, ignoreFields: Ignored[] = [], raw = false): Omit<EntityDTO<Entity>, Ignored> {
          if (!Array.isArray(ignoreFields)) {
            ignoreFields = [];
          }
      
      
      Severity: Minor
      Found in packages/core/src/serialization/EntityTransformer.ts - About 55 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 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

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

        private static processEntity<Entity extends object>(prop: keyof Entity, entity: Entity, platform: Platform, raw: boolean, populated: boolean): EntityValue<Entity> | undefined {
          const child = entity[prop] as unknown as Entity | Reference<Entity>;
          const wrapped = helper(child as Entity);
          const meta = wrapped.__meta;
          const visible = meta.primaryKeys.filter(prop => isVisible(meta, prop));
      Severity: Minor
      Found in packages/core/src/serialization/EntityTransformer.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

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

        validateProperty<T extends object>(prop: EntityProperty, givenValue: any, entity: T) {
          if (givenValue === null || givenValue === undefined) {
            return givenValue;
          }
      
      
      Severity: Minor
      Found in packages/core/src/entity/EntityValidator.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 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
        Severity
        Category
        Status
        Source
        Language