opensheetmusicdisplay/opensheetmusicdisplay

View on GitHub
src/Common/DataObjects/Pitch.ts

Summary

Maintainability
F
4 days
Test Coverage

File Pitch.ts has 432 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// The value of the enum indicates the number of halftoneSteps from one note to the next
export enum NoteEnum {
    C = 0,
    D = 2,
    E = 4,
Severity: Minor
Found in src/Common/DataObjects/Pitch.ts - About 6 hrs to fix

    Pitch has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Pitch {
        public static pitchEnumValues: NoteEnum[] = [
            NoteEnum.C, NoteEnum.D, NoteEnum.E, NoteEnum.F, NoteEnum.G, NoteEnum.A, NoteEnum.B,
        ];
    
    
    Severity: Minor
    Found in src/Common/DataObjects/Pitch.ts - About 4 hrs to fix

      Function accidentalVexflow has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static accidentalVexflow(accidental: AccidentalEnum): string {
              let acc: string;
              switch (accidental) {
                  case AccidentalEnum.NATURAL:
                      acc = "n";
      Severity: Major
      Found in src/Common/DataObjects/Pitch.ts - About 2 hrs to fix

        Function HalfTonesFromAccidental has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static HalfTonesFromAccidental(accidental: AccidentalEnum): number {
                // about equal performance to hashmap/dictionary. could be turned into hashmap for convenience
                // switch is very slightly faster, but both are negligibly short anyways.
                switch (accidental) {
                    // ordered from most to least common to improve average runtime
        Severity: Minor
        Found in src/Common/DataObjects/Pitch.ts - About 1 hr to fix

          Function AccidentalFromHalfTones has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static AccidentalFromHalfTones(halfTones: number): AccidentalEnum {
                  switch (halfTones) {
                      case 0:
                          // for enharmonic change, we won't get a Natural accidental. Maybe there are edge cases though?
                          return AccidentalEnum.NONE;
          Severity: Minor
          Found in src/Common/DataObjects/Pitch.ts - About 1 hr to fix

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

                public static AccidentalFromHalfTones(halfTones: number): AccidentalEnum {
                    switch (halfTones) {
                        case 0:
                            // for enharmonic change, we won't get a Natural accidental. Maybe there are edge cases though?
                            return AccidentalEnum.NONE;
            Severity: Minor
            Found in src/Common/DataObjects/Pitch.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

                public static ceiling(halftone: number): NoteEnum {
                    halftone = (halftone) % 12;
                    let fundamentalNote: NoteEnum = <NoteEnum>halftone;
                    if (this.pitchEnumValues.indexOf(fundamentalNote) === -1) {
                        fundamentalNote = <NoteEnum>(halftone + 1);
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 2 hrs to fix
            src/Common/DataObjects/Pitch.ts on lines 193..200

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

            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

                public static floor(halftone: number): NoteEnum {
                    halftone = halftone % 12;
                    let fundamentalNote: NoteEnum = <NoteEnum>halftone;
                    if (this.pitchEnumValues.indexOf(fundamentalNote) === -1) {
                        fundamentalNote = <NoteEnum>(halftone - 1);
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 2 hrs to fix
            src/Common/DataObjects/Pitch.ts on lines 184..191

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

            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

                        case AccidentalEnum.DOUBLESHARP:
                            this.fundamentalNote = this.getNextFundamentalNote(this.fundamentalNote);
                            this.accidental = Pitch.AccidentalFromHalfTones(this.halfTone - (<number>(this.fundamentalNote) +
                            (this.octave + Pitch.octXmlDiff) * 12));
                            break;
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 2 hrs to fix
            src/Common/DataObjects/Pitch.ts on lines 415..419

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

            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

                        case AccidentalEnum.DOUBLEFLAT:
                            this.fundamentalNote = this.getPreviousFundamentalNote(this.fundamentalNote);
                            this.accidental = Pitch.AccidentalFromHalfTones(this.halfTone - (<number>(this.fundamentalNote) +
                            (this.octave + Pitch.octXmlDiff) * 12));
                            break;
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 2 hrs to fix
            src/Common/DataObjects/Pitch.ts on lines 421..425

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

            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

                public OperatorFundamentalLessThan(p2: Pitch): boolean {
                    const p1: Pitch = this;
                    if (p1.Octave === p2.Octave) {
                        return p1.FundamentalNote < p2.FundamentalNote;
                    } else {
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 1 hr to fix
            src/Common/DataObjects/Pitch.ts on lines 472..479

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

            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

                public OperatorFundamentalGreaterThan(p2: Pitch): boolean {
                    const p1: Pitch = this;
                    if (p1.Octave === p2.Octave) {
                        return p1.FundamentalNote > p2.FundamentalNote;
                    } else {
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 1 hr to fix
            src/Common/DataObjects/Pitch.ts on lines 481..488

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

            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 (this.pitchEnumValues.indexOf(fundamentalNote) === -1) {
                        fundamentalNote = <NoteEnum>(halftoneInOctave - 1);
                        accidental = AccidentalEnum.SHARP;
                    }
            Severity: Minor
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 55 mins to fix
            src/Common/DataObjects/Pitch.ts on lines 165..168

            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 (this.pitchEnumValues.indexOf(fundamentalNote) === -1) {
                        fundamentalNote = <NoteEnum>(halftone - 1);
                        accidental = AccidentalEnum.SHARP;
                    }
            Severity: Minor
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 55 mins to fix
            src/Common/DataObjects/Pitch.ts on lines 177..180

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

                public static pitchEnumValues: NoteEnum[] = [
                    NoteEnum.C, NoteEnum.D, NoteEnum.E, NoteEnum.F, NoteEnum.G, NoteEnum.A, NoteEnum.B,
                ];
            Severity: Major
            Found in src/Common/DataObjects/Pitch.ts and 3 other locations - About 40 mins to fix
            src/MusicalScore/VoiceData/Instructions/KeyInstruction.ts on lines 19..19
            src/MusicalScore/VoiceData/Instructions/KeyInstruction.ts on lines 20..20
            src/Plugins/Transpose/TransposeCalculator.ts on lines 11..11

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

            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

                    return (p1.FundamentalNote === p2.FundamentalNote && p1.Octave === p2.Octave && p1.Accidental === p2.Accidental);
            Severity: Minor
            Found in src/Common/DataObjects/Pitch.ts and 1 other location - About 35 mins to fix
            src/Common/DataObjects/Fraction.ts on lines 29..29

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

            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