danielwippermann/resol-vbus

View on GitHub
examples/vbustouch-proxy/index.js

Summary

Maintainability
F
6 days
Test Coverage

File index.js has 490 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

const fs = require('fs');
const os = require('os');
const path = require('path');
Severity: Minor
Found in examples/vbustouch-proxy/index.js - About 7 hrs to fix

    Function processDownloadDownloadRequest has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const processDownloadDownloadRequest = async (req, res) => {
        try {
            const i18n = specification.i18n;
    
            const startDate = req.query.startDate ? i18n.momentUtc(req.query.startDate, 'MM/DD/YYYY') : i18n.momentUtc();
    Severity: Major
    Found in examples/vbustouch-proxy/index.js - About 4 hrs to fix

      Function startMqttLogging has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const startMqttLogging = async () => {
          const onHeaderSet = async (headerSet, client) => {
              const headers = headerSet.getSortedHeaders();
              const packetFields = specification.getPacketFieldsForHeaders(headers);
      
      
      Severity: Major
      Found in examples/vbustouch-proxy/index.js - About 3 hrs to fix

        Function startMqttLogging has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        const startMqttLogging = async () => {
            const onHeaderSet = async (headerSet, client) => {
                const headers = headerSet.getSortedHeaders();
                const packetFields = specification.getPacketFieldsForHeaders(headers);
        
        
        Severity: Minor
        Found in examples/vbustouch-proxy/index.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 onHeaderSet has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const onHeaderSet = async (headerSet, client) => {
                const headers = headerSet.getSortedHeaders();
                const packetFields = specification.getPacketFieldsForHeaders(headers);
        
                const valuesById = packetFields.reduce((memo, pf) => {
        Severity: Major
        Found in examples/vbustouch-proxy/index.js - About 2 hrs to fix

          Function rewriteWebHeaderSet has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const rewriteWebHeaderSet = function(headerSet) {
              const timestamp = headerSet.timestamp;
          
              /*
               * Get list of packet fields in the received packets.
          Severity: Major
          Found in examples/vbustouch-proxy/index.js - About 2 hrs to fix

            Function startPvOutputOrgLogging has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const startPvOutputOrgLogging = async () => {
                const onHeaderSet = async (headerSet) => {
                    const headers = headerSet.getSortedHeaders();
                    const packetFields = specification.getPacketFieldsForHeaders(headers);
            
            
            Severity: Minor
            Found in examples/vbustouch-proxy/index.js - About 2 hrs to fix

              Function onHeaderSet has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  const onHeaderSet = async (headerSet) => {
                      const headers = headerSet.getSortedHeaders();
                      const packetFields = specification.getPacketFieldsForHeaders(headers);
              
                      const valuesById = packetFields.reduce((memo, pf) => {
              Severity: Minor
              Found in examples/vbustouch-proxy/index.js - About 1 hr to fix

                Function startTextLogging has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const startTextLogging = async () => {
                    let currentDatecode = null;
                
                    let currentConverter = null;
                
                
                Severity: Minor
                Found in examples/vbustouch-proxy/index.js - About 1 hr to fix

                  Function startPvOutputOrgLogging has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                  const startPvOutputOrgLogging = async () => {
                      const onHeaderSet = async (headerSet) => {
                          const headers = headerSet.getSortedHeaders();
                          const packetFields = specification.getPacketFieldsForHeaders(headers);
                  
                  
                  Severity: Minor
                  Found in examples/vbustouch-proxy/index.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 processDownloadDownloadRequest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                  const processDownloadDownloadRequest = async (req, res) => {
                      try {
                          const i18n = specification.i18n;
                  
                          const startDate = req.query.startDate ? i18n.momentUtc(req.query.startDate, 'MM/DD/YYYY') : i18n.momentUtc();
                  Severity: Minor
                  Found in examples/vbustouch-proxy/index.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 connectToVBus has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const connectToVBus = async () => {
                      const ConnectionClass = connectionClassByName [config.connectionClassName];
                      const connection = new ConnectionClass(config.connectionOptions);
                  
                      connection.on('connectionState', (connectionState) => {
                  Severity: Minor
                  Found in examples/vbustouch-proxy/index.js - About 1 hr to fix

                    Function startTextLogging has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const startTextLogging = async () => {
                        let currentDatecode = null;
                    
                        let currentConverter = null;
                    
                    
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js - About 45 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

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

                        const onHeaderSet = async (headerSet) => {
                            const datecode = specification.i18n.moment(headerSet.timestamp).format('YYYYMMDD');
                            if (currentDatecode !== datecode) {
                                currentDatecode = datecode;
                    
                    
                    Severity: Major
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 1 day to fix
                    examples/json-live-data-server/index.js on lines 686..713

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

                    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

                            const params = Object.keys(config.pvOutputOrgPacketFieldMap).reduce((memo, key) => {
                                const packetFieldId = config.pvOutputOrgPacketFieldMap [key];
                    
                                let value;
                                if (typeof packetFieldId === 'function') {
                    Severity: Major
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 4 hrs to fix
                    examples/vbustouch-proxy/index.js on lines 483..499

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

                    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

                                const params = Object.keys(config.mqttPacketFieldMap).reduce((memo, key) => {
                                    const packetFieldId = config.mqttPacketFieldMap [key];
                    
                                    let value;
                                    if (typeof packetFieldId === 'function') {
                    Severity: Major
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 4 hrs to fix
                    examples/vbustouch-proxy/index.js on lines 557..573

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

                    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

                            for (const iface of Object.values(os.networkInterfaces())) {
                                for (const ifaceConfig of iface) {
                                    if (ifaceConfig.family === 'IPv4') {
                                        logger.debug('  - http://' + ifaceConfig.address + ':' + config.webServerPort + '/' + (ifaceConfig.internal ? ' (internal)' : ''));
                                    }
                    Severity: Major
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 3 hrs to fix
                    examples/json-live-data-server/index.js on lines 731..737

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

                    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

                            const onOutputConverterReadable = function() {
                                let chunk;
                                while ((chunk = outputConverter.read()) != null) {
                                    chunks.push(chunk);
                                }
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 45 mins to fix
                    examples/json-live-data-server/index.js on lines 225..230

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

                    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

                        const supportedPacket1 = new Packet({
                            timestamp,
                            channel: 0,
                            destinationAddress: 0x0010,  // DFA
                            sourceAddress: 0x7321,  // Vitosolic 200 [Regler]
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 45 mins to fix
                    examples/vbustouch-proxy/index.js on lines 210..217

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

                    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

                        const supportedPacket2 = new Packet({
                            timestamp,
                            channel: 0,
                            destinationAddress: 0x0010,  // DFA
                            sourceAddress: 0x7326,  // Vitosolic 200 [WMZ1]
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 45 mins to fix
                    examples/vbustouch-proxy/index.js on lines 198..205

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

                    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

                            const endDate = req.query.endDate ? i18n.momentUtc(req.query.endDate, 'MM/DD/YYYY') : i18n.momentUtc();
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 30 mins to fix
                    examples/vbustouch-proxy/index.js on lines 268..268

                    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

                            const startDate = req.query.startDate ? i18n.momentUtc(req.query.startDate, 'MM/DD/YYYY') : i18n.momentUtc();
                    Severity: Minor
                    Found in examples/vbustouch-proxy/index.js and 1 other location - About 30 mins to fix
                    examples/vbustouch-proxy/index.js on lines 269..269

                    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