danielwippermann/resol-vbus

View on GitHub
src/vbus-recording-converter.js

Summary

Maintainability
F
6 days
Test Coverage

File vbus-recording-converter.js has 458 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*! resol-vbus | Copyright (c) 2013-present, Daniel Wippermann | MIT license */

const moreints = require('buffer-more-ints');


Severity: Minor
Found in src/vbus-recording-converter.js - About 7 hrs to fix

    Function _processBuffer has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        _processBuffer(chunk, endOfStream, processRecord) {
            let buffer;
            if (this.rxBuffer) {
                buffer = Buffer.concat([ this.rxBuffer, chunk ]);
            } else {
    Severity: Minor
    Found in src/vbus-recording-converter.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 _processRecord has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _processRecord(buffer) {
            const type = buffer [1] & 0x0F;
            const timestamp = moreints.readUInt64LE(buffer, 6);
    
            if (type === 3) {
    Severity: Major
    Found in src/vbus-recording-converter.js - About 3 hrs to fix

      Function _processRecord has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          _processRecord(buffer) {
              const type = buffer [1] & 0x0F;
              const timestamp = moreints.readUInt64LE(buffer, 6);
      
              if (type === 3) {
      Severity: Minor
      Found in src/vbus-recording-converter.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 _processBuffer has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _processBuffer(chunk, endOfStream, processRecord) {
              let buffer;
              if (this.rxBuffer) {
                  buffer = Buffer.concat([ this.rxBuffer, chunk ]);
              } else {
      Severity: Major
      Found in src/vbus-recording-converter.js - About 2 hrs to fix

        Function _convertHeaders has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _convertHeaders(timestamp, headers) {
                const buffers = [];
        
                const createBuffer = function(type, length, timestamp) {
                    const buffer = Buffer.alloc(length);
        Severity: Major
        Found in src/vbus-recording-converter.js - About 2 hrs to fix

          Function _convertHeaders has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              _convertHeaders(timestamp, headers) {
                  const buffers = [];
          
                  const createBuffer = function(type, length, timestamp) {
                      const buffer = Buffer.alloc(length);
          Severity: Minor
          Found in src/vbus-recording-converter.js - About 2 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 _processRecordForTopologyScan has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _processRecordForTopologyScan(buffer) {
                  const type = buffer [1] & 0x0F;
          
                  let destinationAddress = 0, sourceAddress = 0, protocolVersion = 0, command = 0, hasHeader = false;
                  if (((type === 3) || (type === 6)) && (buffer.length >= 20)) {
          Severity: Minor
          Found in src/vbus-recording-converter.js - About 1 hr to fix

            Function _processType3Record has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _processType3Record(buffer, timestamp) {
                    const destinationAddress = buffer.readUInt16LE(14);
                    const sourceAddress = buffer.readUInt16LE(16);
                    const protocolVersion = buffer.readUInt16LE(18);
            
            
            Severity: Minor
            Found in src/vbus-recording-converter.js - About 1 hr to fix

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

                  convertRawData(rawData) {
                      if (this.objectMode) {
                          return Converter.prototype.convertRawData.apply(this, arguments);
                      } else {
                          const buffers = [];
              Severity: Minor
              Found in src/vbus-recording-converter.js - About 1 hr to fix

                Function _processType3Record has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    _processType3Record(buffer, timestamp) {
                        const destinationAddress = buffer.readUInt16LE(14);
                        const sourceAddress = buffer.readUInt16LE(16);
                        const protocolVersion = buffer.readUInt16LE(18);
                
                
                Severity: Minor
                Found in src/vbus-recording-converter.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 _constructTopologyHeaderSet has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _constructTopologyHeaderSet() {
                        const headerSet = new HeaderSet();
                
                        const timestamp = new Date(0);
                
                
                Severity: Minor
                Found in src/vbus-recording-converter.js - About 1 hr to fix

                  Function _processRecordForTopologyScan has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      _processRecordForTopologyScan(buffer) {
                          const type = buffer [1] & 0x0F;
                  
                          let destinationAddress = 0, sourceAddress = 0, protocolVersion = 0, command = 0, hasHeader = false;
                          if (((type === 3) || (type === 6)) && (buffer.length >= 20)) {
                  Severity: Minor
                  Found in src/vbus-recording-converter.js - About 55 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

                  Avoid deeply nested control flow statements.
                  Open

                                  if (buffer.length >= 26 + dataLength) {
                                      const frameCount = Math.floor(dataLength / 7);
                  
                                      const frameData = Buffer.alloc(3 * 7);
                                      buffer.copy(frameData, 0, 26, 26 + dataLength);
                  Severity: Major
                  Found in src/vbus-recording-converter.js - About 45 mins to fix

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                                const createBuffer = function(type, length, timestamp) {
                                    const buffer = Buffer.alloc(length);
                                    buffer.fill(0);
                    
                                    buffer [0] = 0xA5;
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 4 hrs to fix
                    src/vbus-recording-converter.js on lines 111..122
                    src/vbus-recording-converter.js on lines 155..166

                    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 126.

                    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

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            const createBuffer = function(type, length, timestamp) {
                                const buffer = Buffer.alloc(length);
                                buffer.fill(0);
                    
                                buffer [0] = 0xA5;
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 4 hrs to fix
                    src/vbus-recording-converter.js on lines 73..84
                    src/vbus-recording-converter.js on lines 111..122

                    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 126.

                    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

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                                const createBuffer = function(type, length, timestamp) {
                                    const buffer = Buffer.alloc(length);
                                    buffer.fill(0);
                    
                                    buffer [0] = 0xA5;
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 4 hrs to fix
                    src/vbus-recording-converter.js on lines 73..84
                    src/vbus-recording-converter.js on lines 155..166

                    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 126.

                    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

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                                    } else if (majorVersion === 3) {
                                        buffer.writeUInt16LE(header.command, 20);
                                        buffer.writeUInt16LE(dataLength, 22);
                                        buffer.writeUInt16LE(0, 24);
                    
                    
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 1 other location - About 1 hr to fix
                    src/vbus-recording-converter.js on lines 205..223

                    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 62.

                    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

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                                    if (majorVersion === 1) {
                                        buffer.writeUInt16LE(header.command, 20);
                                        buffer.writeUInt16LE(dataLength, 22);
                                        buffer.writeUInt16LE(0, 24);
                    
                    
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 1 other location - About 1 hr to fix
                    src/vbus-recording-converter.js on lines 217..223

                    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 62.

                    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

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                                        const header = new Telegram({
                                            timestamp: new Date(timestamp),
                                            channel: this.currentChannel,
                                            destinationAddress,
                                            sourceAddress,
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 1 hr to fix
                    src/vbus-recording-converter.js on lines 360..369
                    src/vbus-recording-converter.js on lines 460..469

                    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 60.

                    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

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                                        const header = new Packet({
                                            timestamp: new Date(timestamp),
                                            channel: this.currentChannel,
                                            destinationAddress,
                                            sourceAddress,
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 1 hr to fix
                    src/vbus-recording-converter.js on lines 407..416
                    src/vbus-recording-converter.js on lines 460..469

                    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 60.

                    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

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                                    const header = new Packet({
                                        timestamp: new Date(timestamp),
                                        channel: this.currentChannel,
                                        destinationAddress,
                                        sourceAddress,
                    Severity: Major
                    Found in src/vbus-recording-converter.js and 2 other locations - About 1 hr to fix
                    src/vbus-recording-converter.js on lines 360..369
                    src/vbus-recording-converter.js on lines 407..416

                    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 60.

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                this.emit('rawData', {
                                    startTimestamp: new Date(timestamp),
                                    endTimestamp: new Date(endTimestamp),
                                    channel: this.currentChannel,
                                    buffer: rawBuffer,
                    Severity: Minor
                    Found in src/vbus-recording-converter.js and 1 other location - About 30 mins to fix
                    src/vbus-recording-converter.js on lines 526..531

                    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 45.

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                this.emit('rawData', {
                                    startTimestamp: new Date(startTimestamp),
                                    endTimestamp: new Date(endTimestamp),
                                    channel: this.currentChannel,
                                    buffer: rawBuffer,
                    Severity: Minor
                    Found in src/vbus-recording-converter.js and 1 other location - About 30 mins to fix
                    src/vbus-recording-converter.js on lines 428..433

                    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 45.

                    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

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status