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`.
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)];
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;
- Read upRead up
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;
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 == []) {
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)];
- Read upRead up
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 == []) {
- Read upRead up
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;
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 },
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';
}
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'];
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) => {
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;
- Read upRead up
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 = [];
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,
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;
- Read upRead up
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 },
- Read upRead up
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';
}
- Read upRead up
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;
}
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.
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;
}
Avoid too many return
statements within this function. Open
return this.lookupBeamDirection(lookup_duration, prev_tick, tick, next_tick);
Avoid too many return
statements within this function. Open
return [new Fraction(1, 4)];
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());
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 (
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76