noodlefrenzy/node-amqp10

View on GitHub
lib/types/composite_type.js

Summary

Maintainability
D
1 day
Test Coverage

Function wrapField has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

function wrapField(field, value) {
  if (value instanceof ForcedType) return value;
  if (value === undefined || value === null) {
    if (field.mandatory) throw new Error('missing mandatory field: ' + field.name);
    if (field.hasOwnProperty('default')) return wrapField(field, field.default);
Severity: Minor
Found in lib/types/composite_type.js - About 4 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 defineComposite has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

function defineComposite(Base, definition) {
  if (definition === undefined) {
    definition = Base;
    Base = Object;
  }
Severity: Minor
Found in lib/types/composite_type.js - About 3 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 defineComposite has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function defineComposite(Base, definition) {
  if (definition === undefined) {
    definition = Base;
    Base = Object;
  }
Severity: Major
Found in lib/types/composite_type.js - About 2 hrs to fix

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

    function wrapField(field, value) {
      if (value instanceof ForcedType) return value;
      if (value === undefined || value === null) {
        if (field.mandatory) throw new Error('missing mandatory field: ' + field.name);
        if (field.hasOwnProperty('default')) return wrapField(field, field.default);
    Severity: Minor
    Found in lib/types/composite_type.js - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

        return new ForcedType(field.type, value);
      Severity: Major
      Found in lib/types/composite_type.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          if (field.type === '*') return value;
        Severity: Major
        Found in lib/types/composite_type.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return new field.requires(value);
          Severity: Major
          Found in lib/types/composite_type.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              if (value.toDescribedType && typeof value.toDescribedType === 'function') return value;
            Severity: Major
            Found in lib/types/composite_type.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  if (value.length === 0) return new ForcedType(field.type, null);
              Severity: Major
              Found in lib/types/composite_type.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return new ForcedType(field.type, field.requires(value));
                Severity: Major
                Found in lib/types/composite_type.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      else if (value.length === 1) return new ForcedType(field.type, value[0]);
                  Severity: Major
                  Found in lib/types/composite_type.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return new ForcedType('list', values);
                    Severity: Major
                    Found in lib/types/composite_type.js - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status