opensheetmusicdisplay/opensheetmusicdisplay

View on GitHub
src/VexFlowPatch/src/beam.js

Summary

Maintainability
F
6 days
Test Coverage

File beam.js has 634 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
//
// ## Description
//
// This file implements `Beams` that span over a set of `StemmableNotes`.
Severity: Major
Found in src/VexFlowPatch/src/beam.js - About 1 day to fix

    Function generateBeams has 185 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static generateBeams(notes, config) {
        if (!config) config = {};
    
        if (!config.groups || !config.groups.length) {
          config.groups = [new Fraction(2, 8)];
    Severity: Major
    Found in src/VexFlowPatch/src/beam.js - About 7 hrs to fix

      Function getBeamLines has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

        getBeamLines(duration) {
          const tick_of_duration = Flow.durationToTicks(duration);
          const beam_lines = [];
          let beam_started = false;
          let current_beam = null;
      Severity: Minor
      Found in src/VexFlowPatch/src/beam.js - About 6 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 getBeamLines has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        getBeamLines(duration) {
          const tick_of_duration = Flow.durationToTicks(duration);
          const beam_lines = [];
          let beam_started = false;
          let current_beam = null;
      Severity: Major
      Found in src/VexFlowPatch/src/beam.js - About 2 hrs to fix

        Function constructor has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          constructor(notes, auto_stem) {
            super();
            this.setAttribute('type', 'Beam');
        
            if (!notes || notes == []) {
        Severity: Major
        Found in src/VexFlowPatch/src/beam.js - About 2 hrs to fix

          Function generateBeams has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            static generateBeams(notes, config) {
              if (!config) config = {};
          
              if (!config.groups || !config.groups.length) {
                config.groups = [new Fraction(2, 8)];
          Severity: Minor
          Found in src/VexFlowPatch/src/beam.js - 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 a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            constructor(notes, auto_stem) {
              super();
              this.setAttribute('type', 'Beam');
          
              if (!notes || notes == []) {
          Severity: Minor
          Found in src/VexFlowPatch/src/beam.js - 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 calculateFlatSlope has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            calculateFlatSlope() {
              const {
                notes, stem_direction,
                render_options: { beam_width, min_flat_beam_offset, flat_beam_offset },
              } = this;
          Severity: Minor
          Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

            Function calculateSlope has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              calculateSlope() {
                const {
                  notes,
                  stem_direction: stemDirection,
                  render_options: { max_slope, min_slope, slope_iterations, slope_cost },
            Severity: Minor
            Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

              Function getDefaultBeamGroups has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                static getDefaultBeamGroups(time_sig) {
                  if (!time_sig || time_sig === 'c') {
                    time_sig = '4/4';
                  }
              
              
              Severity: Minor
              Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

                Function drawBeamLines has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  drawBeamLines() {
                    this.checkContext();
                
                    const valid_beam_durations = ['4', '8', '16', '32', '64'];
                
                
                Severity: Minor
                Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

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

                      function sanitizeGroups() {
                        const sanitizedGroups = [];
                        noteGroups.forEach(group => {
                          let tempGroup = [];
                          group.forEach((note, index, group) => {
                  Severity: Minor
                  Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

                    Function calculateFlatSlope has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                      calculateFlatSlope() {
                        const {
                          notes, stem_direction,
                          render_options: { beam_width, min_flat_beam_offset, flat_beam_offset },
                        } = this;
                    Severity: Minor
                    Found in src/VexFlowPatch/src/beam.js - 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 createGroups has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        function createGroups() {
                          let nextGroup = [];
                    
                          unprocessedNotes.forEach(unprocessedNote => {
                            nextGroup = [];
                    Severity: Minor
                    Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

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

                        applyStemExtensions() {
                          const {
                            notes, slope, y_shift, stem_direction, beam_count,
                            render_options: {
                              show_stemlets,
                      Severity: Minor
                      Found in src/VexFlowPatch/src/beam.js - About 1 hr to fix

                        Function getBeamYToDraw has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          getBeamYToDraw() {
                            const firstNote = this.notes[0];
                            const firstStemTipY = firstNote.getStemExtents().topY;
                            let beamY = firstStemTipY;
                        
                        
                        Severity: Minor
                        Found in src/VexFlowPatch/src/beam.js - 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 calculateSlope has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                          calculateSlope() {
                            const {
                              notes,
                              stem_direction: stemDirection,
                              render_options: { max_slope, min_slope, slope_iterations, slope_cost },
                        Severity: Minor
                        Found in src/VexFlowPatch/src/beam.js - 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 getDefaultBeamGroups has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          static getDefaultBeamGroups(time_sig) {
                            if (!time_sig || time_sig === 'c') {
                              time_sig = '4/4';
                            }
                        
                        
                        Severity: Minor
                        Found in src/VexFlowPatch/src/beam.js - 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 deeply nested control flow statements.
                        Open

                                    if ([BEAM_LEFT, BEAM_BOTH].includes(beam_direction)) {
                                      current_beam.end = current_beam.start - partial_beam_length;
                                    } else {
                                      current_beam.end = current_beam.start + partial_beam_length;
                                    }
                        Severity: Major
                        Found in src/VexFlowPatch/src/beam.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                    } else if (!next_note_gets_beam) {
                                      // The next note doesn't get a beam. Draw a partial.
                                      if ((previous_should_break || i === 0) && next_note) {
                                        // This is the first note (but not the last one), or it is
                                        //  following a secondary break. Draw a partial to the right.
                          Severity: Major
                          Found in src/VexFlowPatch/src/beam.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        if (next_note && !next_note_gets_beam && current_beam.end === null) {
                                          // This note gets a beam,.but the next one does not. This means
                                          //  we need a partial pointing right.
                                          current_beam.end = current_beam.start - partial_beam_length;
                                        }
                            Severity: Major
                            Found in src/VexFlowPatch/src/beam.js - About 45 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                  return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick);
                              Severity: Major
                              Found in src/VexFlowPatch/src/beam.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                    return [new Fraction(1, 4)];
                                Severity: Major
                                Found in src/VexFlowPatch/src/beam.js - About 30 mins to fix

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

                                        } else if (
                                          stem_direction === Stem.UP && (currentExtreme === 0 || currentExtreme > stemTipY)
                                        ) {
                                          currentExtreme = stemTipY;
                                          extremeY = Math.min(...note.getYs());
                                  Severity: Minor
                                  Found in src/VexFlowPatch/src/beam.js and 1 other location - About 40 mins to fix
                                  src/VexFlowPatch/src/beam.js on lines 563..573

                                  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

                                        if (stem_direction === Stem.DOWN && currentExtreme < stemTipY) {
                                          currentExtreme = stemTipY;
                                          extremeY = Math.max(...note.getYs());
                                          extremeBeamCount = note.getBeamCount();
                                        } else if (
                                  Severity: Minor
                                  Found in src/VexFlowPatch/src/beam.js and 1 other location - About 40 mins to fix
                                  src/VexFlowPatch/src/beam.js on lines 567..573

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status