mikro-orm/mikro-orm

View on GitHub

Showing 33 of 33 total issues

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

Function foreign has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
Open

  foreign(this: any, foreignInfo: Dictionary) {
    foreignInfo.column = Array.isArray(foreignInfo.column)
      ? foreignInfo.column
      : [foreignInfo.column];
    foreignInfo.column = foreignInfo.column.map((column: unknown) =>
Severity: Minor
Found in packages/knex/src/dialects/sqlite/SqliteTableCompiler.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 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 wrapped ? wrapped.toJSON() as EntityValue<Entity> : value;
    Severity: Major
    Found in packages/core/src/serialization/EntityTransformer.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return customType.toJSON(value, wrapped.__platform);
      Severity: Major
      Found in packages/core/src/serialization/EntityTransformer.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return meta.properties[k].customType!.convertToJSValue(data[k], this.platform);
        Severity: Major
        Found in packages/core/src/entity/EntityFactory.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return data[k];
          Severity: Major
          Found in packages/core/src/entity/EntityFactory.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

              Avoid too many return statements within this function.
              Open

                  return value;
              Severity: Major
              Found in packages/core/src/serialization/EntityTransformer.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return wrapped.__platform.normalizePrimaryKey(value as unknown as IPrimaryKey) as unknown as EntityValue<Entity>;
                Severity: Major
                Found in packages/core/src/serialization/EntityTransformer.ts - About 30 mins to fix

                  Function initPropertyType has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                  Open

                    protected initPropertyType(meta: EntityMetadata, prop: EntityProperty) {
                      const type = Reflect.getMetadata('design:type', meta.prototype, prop.name);
                  
                      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: Minor
                  Found in packages/core/src/metadata/ReflectMetadataProvider.ts - About 25 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 isMarkedAsPopulated has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                  Open

                    isMarkedAsPopulated(entityName: string, prop: string): boolean {
                      let populate: PopulateOptions<T>[] | undefined = this.populate;
                  
                      for (const segment of this.path) {
                        if (!populate) {
                  Severity: Minor
                  Found in packages/core/src/serialization/SerializationContext.ts - About 25 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 initProperties has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                  Open

                    protected initProperties(meta: EntityMetadata): void {
                      // load types and column names
                      for (const prop of meta.props) {
                        if (typeof prop.entity === 'string') {
                          prop.type = prop.entity;
                  Severity: Minor
                  Found in packages/core/src/metadata/ReflectMetadataProvider.ts - About 25 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

                  Severity
                  Category
                  Status
                  Source
                  Language