opensheetmusicdisplay/opensheetmusicdisplay

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

Summary

Maintainability
F
6 days
Test Coverage

Function handleLineRepetitionInstructions has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
Open

  public handleLineRepetitionInstructions(barlineNode: IXmlElement): boolean {
    let pieceEndingDetected: boolean = false;
    if (barlineNode.elements().length > 0) {
      let location: string = "";
      let hasRepeat: boolean = false;

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 removeRedundantInstructions has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

  public removeRedundantInstructions(): void {
    let segnoCount: number = 0;
    let codaCount: number = 0;
    //const fineCount: number = 0;
    let toCodaCount: number = 0;

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 handleRepetitionInstructionsFromWordsOrSymbols has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  public handleRepetitionInstructionsFromWordsOrSymbols(directionTypeNode: IXmlElement, relativeMeasurePosition: number): boolean {
    const wordsNode: IXmlElement = directionTypeNode.element("words");
    const measureIndex: number = this.currentMeasureIndex;
    if (wordsNode) {
      const dsRegEx: string = "d\\s?\\.s\\."; // Input for new RegExp(). TS eliminates the first \

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 removeRedundantInstructions has 85 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public removeRedundantInstructions(): void {
    let segnoCount: number = 0;
    let codaCount: number = 0;
    //const fineCount: number = 0;
    let toCodaCount: number = 0;

    Function handleLineRepetitionInstructions has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public handleLineRepetitionInstructions(barlineNode: IXmlElement): boolean {
        let pieceEndingDetected: boolean = false;
        if (barlineNode.elements().length > 0) {
          let location: string = "";
          let hasRepeat: boolean = false;

      File RepetitionInstructionReader.ts has 296 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import {MusicSheet} from "../../MusicSheet";
      import {IXmlElement} from "../../../Common/FileIO/Xml";
      import {SourceMeasure} from "../../VoiceData/SourceMeasure";
      import {RepetitionInstruction, RepetitionInstructionEnum, AlignmentType} from "../../VoiceData/Instructions/RepetitionInstruction";
      import {RepetitionInstructionComparer} from "../../VoiceData/Instructions/RepetitionInstruction";

        Function handleRepetitionInstructionsFromWordsOrSymbols has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public handleRepetitionInstructionsFromWordsOrSymbols(directionTypeNode: IXmlElement, relativeMeasurePosition: number): boolean {
            const wordsNode: IXmlElement = directionTypeNode.element("words");
            const measureIndex: number = this.currentMeasureIndex;
            if (wordsNode) {
              const dsRegEx: string = "d\\s?\\.s\\."; // Input for new RegExp(). TS eliminates the first \

          Avoid deeply nested control flow statements.
          Open

                      if (separatedEndingIndex.search("-") !== -1 && indices.length === 2) {
                        const startIndex: number = parseInt(indices[0], 10);
                        const endIndex: number = parseInt(indices[1], 10);
                        for (let index: number = startIndex; index <= endIndex; index++) {
                          endingIndices.push(index);

            Avoid deeply nested control flow statements.
            Open

                          if (instruction.measureIndex - instr.measureIndex === 1) {
                            switch (instr.type) {
                              case RepetitionInstructionEnum.BackJumpLine:
                                if (toCodaCount - codaCount > 0) { // open toCoda existing
                                  instr.type = RepetitionInstructionEnum.DalSegnoAlCoda;

              Avoid deeply nested control flow statements.
              Open

                            if (foundInstruction) {
                              break;
                            }

                Avoid too many return statements within this function.
                Open

                    return false;

                  Avoid too many return statements within this function.
                  Open

                          return true;

                    Avoid too many return statements within this function.
                    Open

                          return true;

                      Avoid too many return statements within this function.
                      Open

                              return true;

                        Avoid too many return statements within this function.
                        Open

                                return true;

                          Avoid too many return statements within this function.
                          Open

                                  return true;

                            Avoid too many return statements within this function.
                            Open

                                    return true;

                              Avoid too many return statements within this function.
                              Open

                                    return true;

                                Avoid too many return statements within this function.
                                Open

                                        return true;

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, dcRegEx + " al coda", true)) {
                                          // if (relativeMeasurePosition < 0.5) {
                                          //   measureIndex--;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.DaCapoAlCoda);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 160..167
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 168..175

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

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, dcRegEx + " al fine", true)) {
                                          // if (relativeMeasurePosition < 0.5 && this.currentMeasureIndex < this.xmlMeasureList[0].length - 1) { // not in last measure
                                          //   measureIndex--;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.DaCapoAlFine);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 152..159
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 168..175

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

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, dcRegEx + " al coda", true)) {
                                          // if (relativeMeasurePosition < 0.5) {
                                          //   measureIndex--;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.DaCapoAlCoda);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 152..159
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 160..167

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

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, "segno", true)) {
                                          // if (relativeMeasurePosition > 0.5) {
                                          //   measureIndex++;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.Segno);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 208..215
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 216..223

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

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, "fine", true)) {
                                          // if (relativeMeasurePosition < 0.5) {
                                          //   measureIndex--;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.Fine);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 216..223
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 224..231

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

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

                                        if (StringUtil.StringContainsSeparatedWord(innerText, "coda", true)) {
                                          // if (relativeMeasurePosition > 0.5) {
                                          //   measureIndex++;
                                          // }
                                          const newInstruction: RepetitionInstruction = new RepetitionInstruction(measureIndex, RepetitionInstructionEnum.Coda);
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 208..215
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 224..231

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

                                  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 (type === "stop") {
                                              const newInstruction: RepetitionInstruction = new RepetitionInstruction(this.currentMeasureIndex, RepetitionInstructionEnum.Ending,
                                                                                                                      AlignmentType.End, undefined, endingIndices);
                                              this.addInstruction(this.repetitionInstructions, newInstruction);
                                            }
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 106..110

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

                                  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 (type === "start") {
                                              const newInstruction: RepetitionInstruction = new RepetitionInstruction(this.currentMeasureIndex, RepetitionInstructionEnum.Ending,
                                                                                                                      AlignmentType.Begin, undefined, endingIndices);
                                              this.addInstruction(this.repetitionInstructions, newInstruction);
                                            }
                                  src/MusicalScore/ScoreIO/MusicSymbolModules/RepetitionInstructionReader.ts on lines 117..121

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

                                  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