opensheetmusicdisplay/opensheetmusicdisplay

View on GitHub
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

Summary

Maintainability
F
1 wk
Test Coverage

File OpenSheetMusicDisplay.ts has 795 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { IXmlElement } from "./../Common/FileIO/Xml";
import { VexFlowMusicSheetCalculator } from "./../MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator";
import { VexFlowBackend } from "./../MusicalScore/Graphical/VexFlow/VexFlowBackend";
import { MusicSheetReader } from "./../MusicalScore/ScoreIO/MusicSheetReader";
import { GraphicalMusicSheet } from "./../MusicalScore/Graphical/GraphicalMusicSheet";
Severity: Major
Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 day to fix

    Function setOptions has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring.
    Open

        public setOptions(options: IOSMDOptions): void {
            if (!this.rules) {
                this.rules = new EngravingRules();
            }
            if (!this.drawingParameters && !options.drawingParameters) {
    Severity: Minor
    Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 day 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 setOptions has 244 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public setOptions(options: IOSMDOptions): void {
            if (!this.rules) {
                this.rules = new EngravingRules();
            }
            if (!this.drawingParameters && !options.drawingParameters) {
    Severity: Major
    Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 day to fix

      OpenSheetMusicDisplay has 43 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class OpenSheetMusicDisplay {
          protected version: string = "1.8.8-dev"; // getter: this.Version
          // at release, bump version and change to -release, afterwards to -dev again
      
          /**
      Severity: Minor
      Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 5 hrs to fix

        Function createOrRefreshRenderBackend has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            protected createOrRefreshRenderBackend(): void {
                // console.log("[OSMD] createOrRefreshRenderBackend()");
        
                // Remove old backends
                if (this.drawer && this.drawer.Backends) {
        Severity: Minor
        Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.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 enableOrDisableCursors has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            public enableOrDisableCursors(enable: boolean): void {
                this.drawingParameters.drawCursors = enable;
                if (enable) {
                    for (let i: number = 0; i < this.cursorsOptions.length; i++){
                        // save previous cursor state
        Severity: Minor
        Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.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 load has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public load(content: string | Document, tempTitle: string = "Untitled Score"): Promise<{}> {
                // Warning! This function is asynchronous! No error handling is done here.
                this.reset();
                //console.log("typeof content: " + typeof content);
                if (typeof content === "string") {
        Severity: Major
        Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 2 hrs to fix

          Function load has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              public load(content: string | Document, tempTitle: string = "Untitled Score"): Promise<{}> {
                  // Warning! This function is asynchronous! No error handling is done here.
                  this.reset();
                  //console.log("typeof content: " + typeof content);
                  if (typeof content === "string") {
          Severity: Minor
          Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.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 createOrRefreshRenderBackend has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected createOrRefreshRenderBackend(): void {
                  // console.log("[OSMD] createOrRefreshRenderBackend()");
          
                  // Remove old backends
                  if (this.drawer && this.drawer.Backends) {
          Severity: Major
          Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 2 hrs to fix

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

                public setColoringMode(options: IOSMDOptions): void {
                    if (options.coloringMode === ColoringModes.XML) {
                        this.rules.ColoringMode = ColoringModes.XML;
                        return;
                    }
            Severity: Minor
            Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.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 render has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public render(): void {
                    if (!this.graphic) {
                        throw new Error("OpenSheetMusicDisplay: Before rendering a music sheet, please load a MusicXML file");
                    }
                    this.drawer?.clear(); // clear canvas before setting width
            Severity: Minor
            Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 hr to fix

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

                  public setColoringMode(options: IOSMDOptions): void {
                      if (options.coloringMode === ColoringModes.XML) {
                          this.rules.ColoringMode = ColoringModes.XML;
                          return;
                      }
              Severity: Minor
              Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 hr to fix

                Function handleResize has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected handleResize(startCallback: () => void, endCallback: () => void): void {
                        let rtime: number;
                        let timeout: number = undefined;
                        const delta: number = 200;
                        const self: OpenSheetMusicDisplay = this;
                Severity: Minor
                Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 hr to fix

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

                      public enableOrDisableCursors(enable: boolean): void {
                          this.drawingParameters.drawCursors = enable;
                          if (enable) {
                              for (let i: number = 0; i < this.cursorsOptions.length; i++){
                                  // save previous cursor state
                  Severity: Minor
                  Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 1 hr to fix

                    Function handleResize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected handleResize(startCallback: () => void, endCallback: () => void): void {
                            let rtime: number;
                            let timeout: number = undefined;
                            const delta: number = 200;
                            const self: OpenSheetMusicDisplay = this;
                    Severity: Minor
                    Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 55 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 render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public render(): void {
                            if (!this.graphic) {
                                throw new Error("OpenSheetMusicDisplay: Before rendering a music sheet, please load a MusicXML file");
                            }
                            this.drawer?.clear(); // clear canvas before setting width
                    Severity: Minor
                    Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.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

                    Avoid too many return statements within this function.
                    Open

                                return Promise.reject(new Error("OpenSheetMusicDisplay: Document is not a valid 'partwise' MusicXML"));
                    Severity: Major
                    Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return Promise.resolve({});
                      Severity: Major
                      Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return Promise.reject(new Error("given music sheet was incomplete or could not be loaded."));
                        Severity: Major
                        Found in src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status