opensheetmusicdisplay/opensheetmusicdisplay

View on GitHub
src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts

Summary

Maintainability
F
3 days
Test Coverage

Function addLyricEntry has a Cognitive Complexity of 140 (exceeds 5 allowed). Consider refactoring.
Open

    public addLyricEntry(lyricNodeList: IXmlElement[], currentVoiceEntry: VoiceEntry): void {
        if (lyricNodeList) {
            const lyricNodeListArr: IXmlElement[] = lyricNodeList;
            for (let idx: number = 0, len: number = lyricNodeListArr.length; idx < len; ++idx) {
                const lyricNode: IXmlElement = lyricNodeListArr[idx];
Severity: Minor
Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 2 days 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 addLyricEntry has 104 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public addLyricEntry(lyricNodeList: IXmlElement[], currentVoiceEntry: VoiceEntry): void {
        if (lyricNodeList) {
            const lyricNodeListArr: IXmlElement[] = lyricNodeList;
            for (let idx: number = 0, len: number = lyricNodeListArr.length; idx < len; ++idx) {
                const lyricNode: IXmlElement = lyricNodeListArr[idx];
Severity: Major
Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 4 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                                if (lyricNode.attributes() !== undefined && lyricNode.attribute("number")) {
                                    currentLyricVerseNumber = lyricNode.attribute("number").value;
                                }
    Severity: Major
    Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                  if (syllabic === "single" || syllabic === "end") {
                                      if (this.openLyricWords[currentLyricVerseNumber]) { // word end given or some word still open
                                          this.currentLyricWord = this.openLyricWords[currentLyricVerseNumber];
                                          const syllableNumber: number = this.currentLyricWord.Syllables.length;
                                          lyricsEntry = new LyricsEntry(text, currentLyricVerseNumber, this.currentLyricWord, currentVoiceEntry, syllableNumber);
      Severity: Major
      Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                    if (lyricsEntry) {
                                        // only add the lyric entry if not another entry has already been given:
                                        if (!currentVoiceEntry.LyricsEntries[currentLyricVerseNumber]) {
                                            currentVoiceEntry.LyricsEntries.setValue(currentLyricVerseNumber, lyricsEntry);
                                            if (currentVoiceEntry.ParentSourceStaffEntry?.VerticalContainerParent?.ParentMeasure) {
        Severity: Major
        Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if (lyricNode.element("elision") !== undefined && text === "-") {
                                          const lyricNodeChildren: IXmlElement[] = lyricNode.elements();
                                          let elisionIndex: number = 0;
                                          for (let i: number = 0; i < lyricNodeChildren.length; i++) {
                                              const child: IXmlElement = lyricNodeChildren[i];
          Severity: Major
          Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        for (const node of textAndElisionNodes) {
                                            if (node.name === "text" || node.name === "elision") {
                                                text += node.value;
                                            }
                                        }
            Severity: Major
            Found in src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts - About 45 mins to fix

              There are no issues that match your filters.

              Category
              Status