concord-consortium/lara

View on GitHub
lara-typescript/src/interactive-api-lara-host/iframe-saver.ts

Summary

Maintainability
D
2 days
Test Coverage

File iframe-saver.ts has 533 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { ParentEndpoint } from "iframe-phone";
import * as DOMPurify from "dompurify";
import { IframePhoneManager } from "./iframe-phone-manager";
import { IFrameSaverPluginApi } from "./iframe-saver-plugin";
import { ModalApiPlugin } from "./modal-api-plugin";
Severity: Major
Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 1 day to fix

    Function phoneAnswered has 98 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private phoneAnswered() {
        // Workaround IframePhone problem - phone_answered callback can be triggered multiple times:
        // https://www.pivotaltracker.com/story/show/89602814
        if (this.alreadySetup) {
          return;
    Severity: Major
    Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 3 hrs to fix

      Function initInteractive has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private initInteractive(err: string | null = null, response: IInteractiveRunStateResponse | null = null) {
          const  globalInteractiveState = (typeof globalIframeSaver !== "undefined" && globalIframeSaver !== null)
            ? globalIframeSaver.globalState
            : null;
          const initInteractiveMsg: IInitInteractive = {
      Severity: Major
      Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 2 hrs to fix

        Function interactiveStateProps has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        const interactiveStateProps = (data: IInteractiveRunStateResponse | null): IInteractiveStateProps => ({
          interactiveState: (data != null ? safeJSONParse(data.raw_data) : undefined),
          hasLinkedInteractive: (data != null ? data.has_linked_interactive : undefined),
          linkedState: (data != null ? safeJSONParse(data.linked_state) : undefined),
          // tslint:disable-next-line:max-line-length
        Severity: Minor
        Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.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 constructor has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          constructor($iframe: JQuery, $dataDiv: JQuery, $deleteButton: JQuery) {
            this.$iframe = $iframe;
            this.$deleteButton = $deleteButton;
            this.enableLearnerState = $dataDiv.data("enable-learner-state");
            this.interactiveRunStateUrl = $dataDiv.data("interactive-run-state-url"); // get and put our data here.
        Severity: Minor
        Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 1 hr to fix

          Function saveLearnerState has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public saveLearnerState(interactiveJson: string | object | null) {
              if (!this.learnerStateSavingEnabled()) { return; }
          
              const runSuccess = () => {
                this.savedState = interactiveJson;
          Severity: Minor
          Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 1 hr to fix

            Function loadInteractive has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private loadInteractive(callback: () => void) {
                if (!this.learnerStateSavingEnabled()) {
                  this.initInteractive();
                  callback();
                  return;
            Severity: Minor
            Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.ts - About 1 hr to fix

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

                private async initializeAttachmentsManager() {
                  if (!IFrameSaver.isAttachmentsManagerInitialized) {
                    // Try to initialize manager only once.
                    IFrameSaver.isAttachmentsManagerInitialized = true;
                    try {
              Severity: Minor
              Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.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

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

                public saveLearnerState(interactiveJson: string | object | null) {
                  if (!this.learnerStateSavingEnabled()) { return; }
              
                  const runSuccess = () => {
                    this.savedState = interactiveJson;
              Severity: Minor
              Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.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

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

                private loadInteractive(callback: () => void) {
                  if (!this.learnerStateSavingEnabled()) {
                    this.initInteractive();
                    callback();
                    return;
              Severity: Minor
              Found in lara-typescript/src/interactive-api-lara-host/iframe-saver.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

              There are no issues that match your filters.

              Category
              Status