Cloud-CV/EvalAI

View on GitHub
frontend_v2/src/app/services/global.service.ts

Summary

Maintainability
F
4 days
Test Coverage

File global.service.ts has 375 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Injectable, Output, EventEmitter } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable()
export class GlobalService {
Severity: Minor
Found in frontend_v2/src/app/services/global.service.ts - About 5 hrs to fix

    GlobalService has 37 functions (exceeds 20 allowed). Consider refactoring.
    Open

    @Injectable()
    export class GlobalService {
      scrolledStateDefault = false;
      toastErrorCodes = [400, 500];
      authStorageKey = 'authtoken';
    Severity: Minor
    Found in frontend_v2/src/app/services/global.service.ts - About 4 hrs to fix

      Function getDateDifferenceString has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        getDateDifferenceString(d1, d2) {
          const DIFF_DAYS = this.getDateDifference(d1, d2);
          if (DIFF_DAYS < 1) {
            const DIFF_HOURS = DIFF_DAYS * 24;
            if (DIFF_HOURS < 1) {
      Severity: Minor
      Found in frontend_v2/src/app/services/global.service.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 handleFormError has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        handleFormError(form, err, toast = true) {
          const ERR = err.error;
          if (this.toastErrorCodes.indexOf(err.status) > -1 && ERR !== null && typeof ERR === 'object') {
            console.error(err);
            for (const KEY in ERR) {
      Severity: Minor
      Found in frontend_v2/src/app/services/global.service.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 getDateDifferenceString has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        getDateDifferenceString(d1, d2) {
          const DIFF_DAYS = this.getDateDifference(d1, d2);
          if (DIFF_DAYS < 1) {
            const DIFF_HOURS = DIFF_DAYS * 24;
            if (DIFF_HOURS < 1) {
      Severity: Minor
      Found in frontend_v2/src/app/services/global.service.ts - About 1 hr to fix

        Avoid too many return statements within this function.
        Open

                  return Math.floor(DIFF_WEEKS) + ' week(s)';
        Severity: Major
        Found in frontend_v2/src/app/services/global.service.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return Math.floor(DIFF_DAYS) + ' day(s)';
          Severity: Major
          Found in frontend_v2/src/app/services/global.service.ts - About 30 mins to fix

            Function checkTokenValidity has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              checkTokenValidity(err, toast = true) {
                if (err.error !== null && typeof err.error === 'object' && err.error['detail']) {
                  if (
                    err.error['detail'].indexOf('Invalid token') !== -1 ||
                    err.error['detail'].indexOf('Token has expired') !== -1
            Severity: Minor
            Found in frontend_v2/src/app/services/global.service.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

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

                  if (DIFF_DAYS > 100) {
                    const DIFF_WEEKS = DIFF_DAYS / 7;
                    if (DIFF_WEEKS > 104) {
                      const DIFF_YEARS = DIFF_WEEKS / 52;
                      return Math.floor(DIFF_YEARS) + ' year(s)';
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 1 other location - About 3 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 504..514

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

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

                  if (DIFF_HOURS < 1) {
                    const DIFF_MINUTES = DIFF_HOURS * 60;
                    if (DIFF_MINUTES < 1) {
                      const DIFF_SECONDS = DIFF_MINUTES * 60;
                      return Math.floor(DIFF_SECONDS) + ' seconds';
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 1 other location - About 3 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 516..526

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

            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 4 locations. Consider refactoring.
            Open

              hideModal() {
                if (this.isModalVisible) {
                  this.isModalVisible = false;
                  const TEMP = { isModalVisible: false };
                  this.modalSource.next(Object.assign({}, this.modalDefault, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 184..190
            frontend_v2/src/app/services/global.service.ts on lines 242..248
            frontend_v2/src/app/services/global.service.ts on lines 253..259

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

            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 4 locations. Consider refactoring.
            Open

              hideConfirm() {
                if (this.isConfirming) {
                  this.isConfirming = false;
                  const TEMP = { isConfirming: false };
                  this.confirmSource.next(Object.assign({}, this.modalDefault, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 231..237
            frontend_v2/src/app/services/global.service.ts on lines 242..248
            frontend_v2/src/app/services/global.service.ts on lines 253..259

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

            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 4 locations. Consider refactoring.
            Open

              hideEditPhaseModal() {
                if (this.isEditPhaseModalVisible) {
                  this.isEditPhaseModalVisible = false;
                  const TEMP = { isEditPhaseModalVisible: false };
                  this.editPhasemodalSource.next(Object.assign({}, this.editPhaseModalDefault, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 184..190
            frontend_v2/src/app/services/global.service.ts on lines 231..237
            frontend_v2/src/app/services/global.service.ts on lines 253..259

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

            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 4 locations. Consider refactoring.
            Open

              hideTermsAndConditionsModal() {
                if (this.isTermsAndConditionsModalVisible) {
                  this.isTermsAndConditionsModalVisible = false;
                  const TEMP = { isTermsAndConditionsModalVisible: false };
                  this.termsAndConditionsSource.next(Object.assign({}, this.termsAndConditionsModalDefault, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 184..190
            frontend_v2/src/app/services/global.service.ts on lines 231..237
            frontend_v2/src/app/services/global.service.ts on lines 242..248

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

            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 4 locations. Consider refactoring.
            Open

              showConfirm(params) {
                if (!this.isConfirming) {
                  this.isConfirming = true;
                  const TEMP = { isConfirming: true };
                  this.confirmSource.next(Object.assign({}, params, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 196..202
            frontend_v2/src/app/services/global.service.ts on lines 208..214
            frontend_v2/src/app/services/global.service.ts on lines 220..226

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

            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 4 locations. Consider refactoring.
            Open

              showTermsAndConditionsModal(params) {
                if (!this.isTermsAndConditionsModalVisible) {
                  this.isTermsAndConditionsModalVisible = true;
                  const TEMP = { isTermsAndConditionsModalVisible: true };
                  this.termsAndConditionsSource.next(Object.assign({}, params, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 173..179
            frontend_v2/src/app/services/global.service.ts on lines 196..202
            frontend_v2/src/app/services/global.service.ts on lines 208..214

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

            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 4 locations. Consider refactoring.
            Open

              showEditPhaseModal(params) {
                if (!this.isEditPhaseModalVisible) {
                  this.isEditPhaseModalVisible = true;
                  const TEMP = { isEditPhaseModalVisible: true };
                  this.editPhasemodalSource.next(Object.assign({}, params, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 173..179
            frontend_v2/src/app/services/global.service.ts on lines 196..202
            frontend_v2/src/app/services/global.service.ts on lines 220..226

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

            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 4 locations. Consider refactoring.
            Open

              showModal(params) {
                if (!this.isModalVisible) {
                  this.isModalVisible = true;
                  const TEMP = { isModalVisible: true };
                  this.modalSource.next(Object.assign({}, params, TEMP));
            Severity: Major
            Found in frontend_v2/src/app/services/global.service.ts and 3 other locations - About 2 hrs to fix
            frontend_v2/src/app/services/global.service.ts on lines 173..179
            frontend_v2/src/app/services/global.service.ts on lines 208..214
            frontend_v2/src/app/services/global.service.ts on lines 220..226

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

            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