Apollon77/smartmeter-obis

View on GitHub
lib/ObisMeasurement.js

Summary

Maintainability
A
0 mins
Test Coverage
A
91%

Function ObisMeasurement has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Wontfix

function ObisMeasurement(medium, channel, measurement, measureType, tariffRate, previousMeasurement) {
    this.medium = medium;
    this.channel = channel;
    this.measurement = measurement;
    this.measureType = measureType;
Severity: Minor
Found in lib/ObisMeasurement.js - About 1 day 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 addValue has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Wontfix

ObisMeasurement.prototype.addValue = function addValue(value, unit) {
    if (typeof value === 'string') {
        var valueFloat = parseFloat(value);
        if (valueFloat.toString() === value) { // it is a float
            value = valueFloat;
Severity: Minor
Found in lib/ObisMeasurement.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 ObisMeasurement has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Wontfix

function ObisMeasurement(medium, channel, measurement, measureType, tariffRate, previousMeasurement) {
    this.medium = medium;
    this.channel = channel;
    this.measurement = measurement;
    this.measureType = measureType;
Severity: Major
Found in lib/ObisMeasurement.js - About 2 hrs to fix

    Function idToString has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Wontfix

    ObisMeasurement.prototype.idToString = function idToString(content) {
        var fullContent = (content === undefined || content === 'full');
        var extendedContent = (content === undefined || content === 'full' || content === 'extended');
    
        var obisStr = '';
    Severity: Minor
    Found in lib/ObisMeasurement.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 addValue has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Wontfix

    ObisMeasurement.prototype.addValue = function addValue(value, unit) {
        if (typeof value === 'string') {
            var valueFloat = parseFloat(value);
            if (valueFloat.toString() === value) { // it is a float
                value = valueFloat;
    Severity: Minor
    Found in lib/ObisMeasurement.js - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Wontfix

                      if (obisArr[1] !== '') this.setMeasurement(obisArr[1]);
      Severity: Major
      Found in lib/ObisMeasurement.js - About 45 mins to fix

        Function ObisMeasurement has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Wontfix

        function ObisMeasurement(medium, channel, measurement, measureType, tariffRate, previousMeasurement) {
        Severity: Minor
        Found in lib/ObisMeasurement.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Wontfix

                          if (obisArr[2] !== '') this.setMeasureType(obisArr[2]);
          Severity: Major
          Found in lib/ObisMeasurement.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Wontfix

                            if (obisArr[4] !== '') this.setPreviousMeasurement(obisArr[4]);
            Severity: Major
            Found in lib/ObisMeasurement.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Wontfix

                              if (obisArr[3] !== '') this.setTariffRate(obisArr[3]);
              Severity: Major
              Found in lib/ObisMeasurement.js - About 45 mins to fix

                There are no issues that match your filters.

                Category
                Status