grommet/grommet-ferret

View on GitHub
server/rest.js

Summary

Maintainability
F
5 days
Test Coverage

File rest.js has 940 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

import express from 'express';
let router = express.Router();
import ws from "ws";
Severity: Major
Found in server/rest.js - About 2 days to fix

    Function timer has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        let timer = setInterval(() => {
          index += 1;
          if (index < 10) {
            setStatus({state: 'updating',
              percent: Math.floor((index / 10) * 100)});
    Severity: Major
    Found in server/rest.js - About 2 hrs to fix

      Function getAggregate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getAggregate (url, queryParams) {
        let items = getItems(queryParams.category) || [];
        items = filteredItems(items, queryParams);
      
        let attributes;
      Severity: Minor
      Found in server/rest.js - About 1 hr to fix

        Function respondToRequest has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function respondToRequest (connection, request) {
          let response = {op: 'update', id: request.id};
        
          try {
            if ('/rest/index/resources' === request.uri) {
        Severity: Minor
        Found in server/rest.js - About 1 hr to fix

          Function getIndex has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function getIndex (url, queryParams) {
            let items = getItems(queryParams.category) || [];
            const unfilteredTotal = items.length;
            items = filteredItems(items, queryParams);
          
          
          Severity: Minor
          Found in server/rest.js - About 1 hr to fix

            Function updateAggregateCounts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function updateAggregateCounts (counts, resource, value, intervals) {
              let count = null;
              for (let i = 0; i < counts.length; i++) {
                if (value === counts[i].value) {
                  count = counts[i];
            Severity: Minor
            Found in server/rest.js - About 1 hr to fix

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

              function runTask (task, resource, handler) {
                // allow caller to preset the percent complete
                if (! task.percentComplete) {
                  task.percentComplete = 0;
                }
              Severity: Minor
              Found in server/rest.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

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

              function respondToRequest (connection, request) {
                let response = {op: 'update', id: request.id};
              
                try {
                  if ('/rest/index/resources' === request.uri) {
              Severity: Minor
              Found in server/rest.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

              Consider simplifying this complex logical expression.
              Open

                if (! req.body.userName || ! req.body.password ||
                  'error' === req.body.userName ||
                  ('Gru' === req.body.userName && 'freeze ray' !== req.body.password)) {
                  res.status(401, "Invalid username or password.").send();
                } else {
              Severity: Major
              Found in server/rest.js - About 40 mins to fix

                Function updateAggregateCounts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                function updateAggregateCounts (counts, resource, value, intervals) {
                  let count = null;
                  for (let i = 0; i < counts.length; i++) {
                    if (value === counts[i].value) {
                      count = counts[i];
                Severity: Minor
                Found in server/rest.js - About 35 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 getAggregate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                function getAggregate (url, queryParams) {
                  let items = getItems(queryParams.category) || [];
                  items = filteredItems(items, queryParams);
                
                  let attributes;
                Severity: Minor
                Found in server/rest.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 onMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                function onMessage (connection, request) {
                  if ('start' === request.op) {
                    // Split out query parameters
                    const parts = request.uri.split('?');
                    request.uri = parts[0];
                Severity: Minor
                Found in server/rest.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

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

                router.post('/backup', (req, res) => {
                  const resource = getResource('/rest/appliances/1');
                  setBackup({}); // clear prior one
                  let task = createTask('appliances', 'Backup', resource, req);
                
                
                Severity: Major
                Found in server/rest.js and 1 other location - About 4 hrs to fix
                server/rest.js on lines 774..788

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

                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

                router.post('/support', (req, res) => {
                  const resource = getResource('/rest/appliances/1');
                  setSupport({}); // clear prior one
                  let task = createTask('appliances', 'Create support dump', resource, req);
                
                
                Severity: Major
                Found in server/rest.js and 1 other location - About 4 hrs to fix
                server/rest.js on lines 752..766

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

                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

                router.get('/settings', (req, res) => {
                  const settings = getSettings();
                  if (settings) {
                    res.json(settings);
                  } else {
                Severity: Major
                Found in server/rest.js and 1 other location - About 1 hr to fix
                server/rest.js on lines 566..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 58.

                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

                  router.get(path, (req, res) => {
                    var object = func();
                    if (object) {
                      res.json(object);
                    } else {
                Severity: Major
                Found in server/rest.js and 1 other location - About 1 hr to fix
                server/rest.js on lines 403..410

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

                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

                router.get('/index/resources', (req, res) => {
                  const result = getIndex(`/rest${req.url}`, req.query);
                  res.json(result);
                });
                Severity: Major
                Found in server/rest.js and 1 other location - About 1 hr to fix
                server/rest.js on lines 957..960

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

                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

                router.get('/index/resources/aggregated', (req, res) => {
                  const result = getAggregate(`/rest${req.url}`, req.query);
                  res.json(result);
                });
                Severity: Major
                Found in server/rest.js and 1 other location - About 1 hr to fix
                server/rest.js on lines 952..955

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

                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

                      if (file.name.match(/invalid/)) {
                        task.status = 'Critical';
                        task.state = 'Error';
                        task.taskErrors = [{
                          message: 'Simulated checksum or invalid file error.',
                Severity: Minor
                Found in server/rest.js and 1 other location - About 45 mins to fix
                server/rest.js on lines 1143..1152

                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

                      if (updatedResource.name.match(/error/i)) {
                        task.status = "Critical";
                        task.state = "Error";
                        task.taskErrors = [{
                          message: 'There was an error with this task.',
                Severity: Minor
                Found in server/rest.js and 1 other location - About 45 mins to fix
                server/rest.js on lines 838..845

                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

                  if (settings.directory && settings.directory.certifcate) {
                    setCertificate(settings.directory.address,
                      settings.directory.certificate);
                  }
                Severity: Minor
                Found in server/rest.js and 1 other location - About 35 mins to fix
                server/rest.js on lines 435..438

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

                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

                  if (settings.hypervisor && settings.hypervisor.certifcate) {
                    setCertificate(settings.hypervisor.address,
                      settings.hypervisor.certificate);
                  }
                Severity: Minor
                Found in server/rest.js and 1 other location - About 35 mins to fix
                server/rest.js on lines 439..442

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

                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