prey/prey-node-client

View on GitHub
lib/agent/control-panel/api/request.js

Summary

Maintainability
B
5 hrs
Test Coverage

Function send has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const send = function (attempt, method, path, data, options, cb) {
  if (!defaults.client) {
    const err = new Error('No HTTP client set!');
    if (cb) return cb(err);
    return err;
Severity: Major
Found in lib/agent/control-panel/api/request.js - About 2 hrs to fix

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

    const send = function (attempt, method, path, data, options, cb) {
      if (!defaults.client) {
        const err = new Error('No HTTP client set!');
        if (cb) return cb(err);
        return err;
    Severity: Minor
    Found in lib/agent/control-panel/api/request.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 use has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.use = function (obj) {
      for (const key in obj) {
        if (defaults.hasOwnProperty(key)) {
          if (key == 'protocol' && ['http', 'https'].indexOf(obj[key]) === -1) {
            logger.error(`Invalid protocol: ${obj[key]}`);
    Severity: Minor
    Found in lib/agent/control-panel/api/request.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 send has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    const send = function (attempt, method, path, data, options, cb) {
    Severity: Minor
    Found in lib/agent/control-panel/api/request.js - About 45 mins to fix

      Function set_proxy_and_send has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      const set_proxy_and_send = function (method, path, data, opts, cb) {
      Severity: Minor
      Found in lib/agent/control-panel/api/request.js - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status