NatLibFi/marc-record-validators-melinda

View on GitHub
src/merge-fields/controlSubfields.js

Summary

Maintainability
D
1 day
Test Coverage

Function controlSubfield9PermitsMerge has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

function controlSubfield9PermitsMerge(baseField, sourceField) {
  const baseFieldSubfields9 = baseField.subfields.filter(sf => sf.code === '9');
  const sourceFieldSubfields9 = sourceField.subfields.filter(sf => sf.code === '9');

  //nvdebug('CHECK $9', debugDev);
Severity: Minor
Found in src/merge-fields/controlSubfields.js - About 5 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 controlSubfield9PermitsMerge has 83 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function controlSubfield9PermitsMerge(baseField, sourceField) {
  const baseFieldSubfields9 = baseField.subfields.filter(sf => sf.code === '9');
  const sourceFieldSubfields9 = sourceField.subfields.filter(sf => sf.code === '9');

  //nvdebug('CHECK $9', debugDev);
Severity: Major
Found in src/merge-fields/controlSubfields.js - About 3 hrs to fix

    Function keepOrDropPreventsMerge has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function keepOrDropPreventsMerge() {
        const keepOrDrop1 = baseFieldSubfields9.filter(sf => subfieldHasKeepOrDrop(sf));
        const keepOrDrop2 = sourceFieldSubfields9.filter(sf => subfieldHasKeepOrDrop(sf));
    
        if (keepOrDrop1.length === 0 && keepOrDrop2.length === 0) {
    Severity: Minor
    Found in src/merge-fields/controlSubfields.js - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

        return true;
      Severity: Major
      Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return false;
        Severity: Major
        Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return true;
          Severity: Major
          Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return false;
            Severity: Major
            Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return false;
              Severity: Major
              Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  return true;
                Severity: Major
                Found in src/merge-fields/controlSubfields.js - About 30 mins to fix

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

                  export function controlSubfieldsPermitMerge(baseField, sourceField) {
                    // Check $w, $0, $1, $2 (which isn't an identifier per se, but the sama logic can be applied)
                    if (!controlSubfieldsContainingIdentifier.every(subfieldCode => controlSubfieldContainingIdentifierPermitsMerge(baseField, sourceField, subfieldCode))) {
                      //debug(' control subfields with identifiers failed');
                      return false;
                  Severity: Minor
                  Found in src/merge-fields/controlSubfields.js - 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

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

                  function controlSubfieldContainingIdentifierPermitsMerge(field1, field2, subfieldCode) {
                    if (!fieldHasSubfield(field1, subfieldCode, null) || !fieldHasSubfield(field2, subfieldCode, null)) {
                      return true;
                    }
                  
                  
                  Severity: Minor
                  Found in src/merge-fields/controlSubfields.js - 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

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

                  function controlSubfield5PermitsMerge(field1, field2) {
                    // field1.$5 XOR field2.$5 means false, NEITHER and BOTH mean true, regardless of value
                    if (!fieldHasSubfield(field1, '5')) {
                      if (!fieldHasSubfield(field2, '5')) {
                        return true; // If neither one has $5, it's ok to merge
                  Severity: Minor
                  Found in src/merge-fields/controlSubfields.js - 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

                  There are no issues that match your filters.

                  Category
                  Status