noushmac/ngx-magic-table

View on GitHub
projects/ngx-magic-table/src/lib/ngx-multiselect-dropdown/ngx-multiselect-dropdown.component.ts

Summary

Maintainability
A
0 mins
Test Coverage

Function writeValue has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Invalid

  writeValue(obj: any): void {
    if (obj !== undefined && obj !== null && obj.length > 0) {
      if (this._settings.singleSelection) {
        try {
          if (obj.length >= 1) {

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

File ngx-multiselect-dropdown.component.ts has 284 lines of code (exceeds 250 allowed). Consider refactoring.
Invalid

import {
  Component, OnInit, HostListener, Input, Output, EventEmitter,
  forwardRef, ChangeDetectorRef, ChangeDetectionStrategy
} from '@angular/core';
import { ListItemDropdown, IDropdownSettings } from '../models/multiselect.model';

    NgxMultiselectDropdownComponent has 23 functions (exceeds 20 allowed). Consider refactoring.
    Invalid

    @Component({
      selector: 'lib-ngx-multiselect-dropdown',
      templateUrl: './ngx-multiselect-dropdown.component.html',
      styleUrls: ['./ngx-multiselect-dropdown.component.scss'],
      providers: [DROPDOWN_CONTROL_VALUE_ACCESSOR],

      Function writeValue has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Invalid

        writeValue(obj: any): void {
          if (obj !== undefined && obj !== null && obj.length > 0) {
            if (this._settings.singleSelection) {
              try {
                if (obj.length >= 1) {

        Function emittedValue has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Invalid

          emittedValue(val: any): any {
            const selected = [];
            if (Array.isArray(val)) {
              val.map(item => {
                if (item.id === item.text) {

        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 onItemClick has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Invalid

          onItemClick($event: any, item: ListItemDropdown) {
            if (this.disabled) {
              return false;
            }
            const found = this.isSelected(item);

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

                      if (this.selectedItems.indexOf(element) !== -1 && this.selectedItems.length > 1) {
                        this.selectedItems.splice(this.selectedItems.indexOf(element), 1);
                      }

          Function addSelected has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Invalid

            addSelected(item: ListItemDropdown) {
              if (this._settings.singleSelection) {
                this.selectedItems = [];
                this.selectedItems.push(item);
              } else {

          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

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

                  const _data = obj.map(
                    (item: any) =>
                      typeof item === 'string'
                        ? new ListItemDropdown(item)
                        : new ListItemDropdown({
          projects/ngx-magic-table/src/lib/ngx-multiselect-dropdown/ngx-multiselect-dropdown.component.ts on lines 89..98

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

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

                this._data = value.map(
                  (item: any) =>
                    typeof item === 'string'
                      ? new ListItemDropdown(item)
                      : new ListItemDropdown({
          projects/ngx-magic-table/src/lib/ngx-multiselect-dropdown/ngx-multiselect-dropdown.component.ts on lines 124..133

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

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

                if (childItem.length > 0 && childItemseleted.length <= 0) {
                  this.selectedItems.push(childItem[0]);
                }
          projects/ngx-magic-table/src/lib/ngx-multiselect-dropdown/ngx-multiselect-dropdown.component.ts on lines 289..291

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

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

                if (parentItem.length > 0 && parentItemseleted.length <= 0) {
                  this.selectedItems.push(parentItem[0]);
                }
          projects/ngx-magic-table/src/lib/ngx-multiselect-dropdown/ngx-multiselect-dropdown.component.ts on lines 295..297

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

          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