AnasBoulmane/container

View on GitHub

Showing 11 of 11 total issues

Function getServiceValue has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

  private getServiceValue (identifier: ServiceIdentifier, service: ServiceMetadata<any, any> | undefined): any {
    // find if instance of this object already initialized in the container and return it if it is
    if (service && service.value !== undefined) {
      return service.value;
    }
Severity: Minor
Found in src/ContainerInstance.ts - About 3 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 getServiceValue has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private getServiceValue (identifier: ServiceIdentifier, service: ServiceMetadata<any, any> | undefined): any {
    // find if instance of this object already initialized in the container and return it if it is
    if (service && service.value !== undefined) {
      return service.value;
    }
Severity: Major
Found in src/ContainerInstance.ts - About 2 hrs to fix

    Function Service has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function Service<T, K extends keyof T> (
      optionsOrServiceName?: ServiceOptions<T, K> | Token<any> | string | any[] | (() => any),
      maybeFactory?: (...args: any[]) => any,
    ): any {
      if (arguments.length === 2 || optionsOrServiceName instanceof Function) {
    Severity: Minor
    Found in src/decorators/Service.ts - About 1 hr to fix

      Function set has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        set (
          identifierOrServiceMetadata: ServiceIdentifier | ServiceMetadata<any, any> | (Array<ServiceMetadata<any, any>>),
          value?: any,
        ): this {
          if (identifierOrServiceMetadata instanceof Array) {
      Severity: Minor
      Found in src/ContainerInstance.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 (
            (!service || !service.type) &&
            (!service || !service.factory) &&
            (typeof identifier === "string" || identifier instanceof Token)
          ) {
      Severity: Major
      Found in src/ContainerInstance.ts - About 40 mins to fix

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

        export function Service<T, K extends keyof T> (
          optionsOrServiceName?: ServiceOptions<T, K> | Token<any> | string | any[] | (() => any),
          maybeFactory?: (...args: any[]) => any,
        ): any {
          if (arguments.length === 2 || optionsOrServiceName instanceof Function) {
        Severity: Minor
        Found in src/decorators/Service.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 this;
        Severity: Major
        Found in src/ContainerInstance.ts - About 30 mins to fix

          Array type using 'Array<t>' is forbidden. Use 'T[]' instead.</t>
          Open

              identifierOrServiceMetadata: ServiceIdentifier | ServiceMetadata<any, any> | (Array<ServiceMetadata<any, any>>),
          Severity: Minor
          Found in src/Container.ts by tslint

          Rule: array-type

          Requires using either 'T[]' or 'Array<t>' for arrays.</t>

          Notes
          • TypeScript Only
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "array" enforces use of T[] for all types T.
          • "generic" enforces use of Array<T> for all types T.
          • "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).
          Examples
          "array-type": true,array
          "array-type": true,generic
          "array-type": true,array-simple
          Schema
          {
            "type": "string",
            "enum": [
              "array",
              "generic",
              "array-simple"
            ]
          }

          For more information see this page.

          Array type using 'Array<t>' is forbidden. Use 'T[]' instead.</t>
          Open

            private services: Array<ServiceMetadata<any, any>> = [];
          Severity: Minor
          Found in src/ContainerInstance.ts by tslint

          Rule: array-type

          Requires using either 'T[]' or 'Array<t>' for arrays.</t>

          Notes
          • TypeScript Only
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "array" enforces use of T[] for all types T.
          • "generic" enforces use of Array<T> for all types T.
          • "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).
          Examples
          "array-type": true,array
          "array-type": true,generic
          "array-type": true,array-simple
          Schema
          {
            "type": "string",
            "enum": [
              "array",
              "generic",
              "array-simple"
            ]
          }

          For more information see this page.

          Array type using 'Array<t>' is forbidden. Use 'T[]' instead.</t>
          Open

              identifierOrServiceMetadata: ServiceIdentifier | ServiceMetadata<any, any> | (Array<ServiceMetadata<any, any>>),
          Severity: Minor
          Found in src/ContainerInstance.ts by tslint

          Rule: array-type

          Requires using either 'T[]' or 'Array<t>' for arrays.</t>

          Notes
          • TypeScript Only
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "array" enforces use of T[] for all types T.
          • "generic" enforces use of Array<T> for all types T.
          • "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).
          Examples
          "array-type": true,array
          "array-type": true,generic
          "array-type": true,array-simple
          Schema
          {
            "type": "string",
            "enum": [
              "array",
              "generic",
              "array-simple"
            ]
          }

          For more information see this page.

          Array type using 'Array<t>' is forbidden. Use 'T[]' instead.</t>
          Open

            private filterServices (identifier: ServiceIdentifier): Array<ServiceMetadata<any, any>> {
          Severity: Minor
          Found in src/ContainerInstance.ts by tslint

          Rule: array-type

          Requires using either 'T[]' or 'Array<t>' for arrays.</t>

          Notes
          • TypeScript Only
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "array" enforces use of T[] for all types T.
          • "generic" enforces use of Array<T> for all types T.
          • "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).
          Examples
          "array-type": true,array
          "array-type": true,generic
          "array-type": true,array-simple
          Schema
          {
            "type": "string",
            "enum": [
              "array",
              "generic",
              "array-simple"
            ]
          }

          For more information see this page.

          Severity
          Category
          Status
          Source
          Language