src/MusicalScore/ScoreIO/MusicSymbolModules/LyricsReader.ts
Function addLyricEntry
has a Cognitive Complexity of 140 (exceeds 5 allowed). Consider refactoring. Open
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];
- 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 addLyricEntry
has 104 lines of code (exceeds 25 allowed). Consider refactoring. Open
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];
Avoid deeply nested control flow statements. Open
Open
if (lyricNode.attributes() !== undefined && lyricNode.attribute("number")) {
currentLyricVerseNumber = lyricNode.attribute("number").value;
}
Avoid deeply nested control flow statements. Open
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);
Avoid deeply nested control flow statements. Open
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) {
Avoid deeply nested control flow statements. Open
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];
Avoid deeply nested control flow statements. Open
Open
for (const node of textAndElisionNodes) {
if (node.name === "text" || node.name === "elision") {
text += node.value;
}
}