lyfeyaj/poplar

View on GitHub
lib/api_method.js

Summary

Maintainability
F
3 days
Test Coverage

File api_method.js has 386 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * Expose `ApiMethod`.
 */
module.exports = ApiMethod;

Severity: Minor
Found in lib/api_method.js - About 5 hrs to fix

    Function invoke has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    ApiMethod.prototype.invoke = function(ctx, cb) {
      var args = ctx.args;
      var options = util._extend({}, ctx.options);
    
      var returns = this.returns;
    Severity: Minor
    Found in lib/api_method.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 invoke has 90 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    ApiMethod.prototype.invoke = function(ctx, cb) {
      var args = ctx.args;
      var options = util._extend({}, ctx.options);
    
      var returns = this.returns;
    Severity: Major
    Found in lib/api_method.js - About 3 hrs to fix

      Function toResult has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

      ApiMethod.toResult = function(raw, presenter, presenterSource, options) {
        if (Entity.isEntity(presenter)) {
          var result = presenter.parse(_eval(raw, presenterSource), options, _convert);
          return _eval(raw, presenterSource, result);
        } else {
      Severity: Minor
      Found in lib/api_method.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 toResult has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      ApiMethod.toResult = function(raw, presenter, presenterSource, options) {
        if (Entity.isEntity(presenter)) {
          var result = presenter.parse(_eval(raw, presenterSource), options, _convert);
          return _eval(raw, presenterSource, result);
        } else {
      Severity: Major
      Found in lib/api_method.js - About 2 hrs to fix

        Function coerceAccepts has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function coerceAccepts(uarg, desc) {
          var name = desc.name || desc.arg;
          var targetType = convertToBasicType(desc.type);
          var targetTypeIsArray = _.isArray(targetType) && targetType.length === 1;
        
        
        Severity: Minor
        Found in lib/api_method.js - About 1 hr to fix

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

            function _eval(source, path, value) {
              if (path && _.isString(path)) {
          
                // split path by '[', '.', ']' and then remove empty string
                var list = _.compact(path.trim().split(/\[|\.|\]/));
          Severity: Minor
          Found in lib/api_method.js - About 1 hr to fix

            Function ApiMethod has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function ApiMethod(name, options, fn) {
            
              this.__original = [name, options, fn];
            
              this.fn = fn;
            Severity: Minor
            Found in lib/api_method.js - About 1 hr to fix

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

              ApiMethod.getType = function(val) {
                var type = typeof val;
              
                switch (type) {
                  case 'undefined':
              Severity: Minor
              Found in lib/api_method.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 coerceAccepts has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function coerceAccepts(uarg, desc) {
                var name = desc.name || desc.arg;
                var targetType = convertToBasicType(desc.type);
                var targetTypeIsArray = _.isArray(targetType) && targetType.length === 1;
              
              
              Severity: Minor
              Found in lib/api_method.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

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

              function ApiMethod(name, options, fn) {
              
                this.__original = [name, options, fn];
              
                this.fn = fn;
              Severity: Minor
              Found in lib/api_method.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

              Avoid too many return statements within this function.
              Open

                    return callback(err);
              Severity: Major
              Found in lib/api_method.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return cb(e);
                Severity: Major
                Found in lib/api_method.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return 'object';
                  Severity: Major
                  Found in lib/api_method.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return uarg;
                    Severity: Major
                    Found in lib/api_method.js - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status