NaturalIntelligence/Stubmatic

View on GitHub

Showing 106 of 106 total issues

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

exports.ls = function(dirpath, ext){
    if(exports.isExist(dirpath)){
        const fileList = fs.readdirSync(dirpath);
        if(ext){
            const filteredFileList = [];
Severity: Minor
Found in lib/util/fileutil.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 build has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    build(options){
        this.config = {
            mappings: {},
            server:{},
            recordAndPlay : {
Severity: Minor
Found in lib/ConfigBuilder.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 evaluateMarker has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

var evaluateMarker = function(exp,rc,store){
    for(var marker in markers){
        if(markers[marker].exp){
            var regx = "^" + markers[marker].exp + "$";
            var result = util.getMatches(exp.toString(),regx);
Severity: Minor
Found in lib/expressions/engine.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 evaluate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

exports.evaluate = function(exp,rc,store){

    if(isFunction(exp)){
        var fExp = buildFunctionExp(exp);
        for (var i = 0; i < fExp.args.length; i++) {
Severity: Minor
Found in lib/expressions/engine.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

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

function replaceRequestParamExp(fileName, matches){
    const regx = "([a-zA-Z]+)\\[\\s([0-9]+)\\s*\\]";
    const reqParamsPart = util.getMatches(fileName,regx);
    const paramName = reqParamsPart[1];
    const index =  reqParamsPart[2];
Severity: Major
Found in lib/FileStrategyHandler.js and 1 other location - About 1 hr to fix
lib/expressions/includeFileExpression.js on lines 57..63

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

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

function resolveRequestParamExp(fileName, matches){
    const regx = "([a-zA-Z]+)\\[\\s([0-9]+)\\s*\\]";
    const reqParamsPart = util.getMatches(fileName,regx);
    const paramName = reqParamsPart[1];
    const index =  reqParamsPart[2];
Severity: Major
Found in lib/expressions/includeFileExpression.js and 1 other location - About 1 hr to fix
lib/FileStrategyHandler.js on lines 92..98

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

            if(this.config.server.key){
                this.config.server.key = path.join(basePath , this.config.server.key);
            }
Severity: Major
Found in lib/ConfigBuilder.js and 1 other location - About 1 hr to fix
lib/ConfigBuilder.js on lines 97..99

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

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(this.config.server.cert){
                this.config.server.cert = path.join(basePath , this.config.server.cert);
            }
Severity: Major
Found in lib/ConfigBuilder.js and 1 other location - About 1 hr to fix
lib/ConfigBuilder.js on lines 93..95

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

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

Function matchParamters has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function matchParamters(http_request, mapped_request, param_name){
    var clips = [];
    clips[0] = "N/A";
    if( !http_request[param_name]){
        if( mapped_request[param_name] ){
Severity: Minor
Found in lib/RequestResolver.js - About 1 hr to fix

    Function exports has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function(data, mappedEntry, source){
        var regx = "{{\\s*(.*)\\s*}}";
        var expressions = util.getAllMatches(data,regx);
        var dataTableRegex = "#(([\\w]+)|(([\\w]+)(\\[\\s*([0-9]+)\\s*\\])?)(\\((.*?)\\))?\.([\\w]+))";
        for(var i in expressions){
    Severity: Minor
    Found in lib/expressions/dataTableExpression.js - About 1 hr to fix

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

      function convertToFullNotationIfShort(mapping){
          if(mapping.request){
              return mapping;
          }else{
              var fullNotation ={};
      Severity: Minor
      Found in lib/loaders/MappingsBuilder.js - About 1 hr to fix

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

            getFileName (matchedentry) {
                var res = matchedentry.response,
                    matches = matchedentry.request.matches;
            
                if (res.file) {
        Severity: Minor
        Found in lib/FileStrategyHandler.js - About 1 hr to fix

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

          module.exports = function (data, dumpsdir, store, requestMatches){
              //var regx = "\\[\\[([^\\]]+)\\]\\]";
              var regx = "{{\\s*include\\(([^}]*)\\)\\s*}}";
              var matches = util.getAllMatches(data,regx);
              
          Severity: Minor
          Found in lib/expressions/includeFileExpression.js - About 1 hr to fix

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

            function convertToFullNotationIfShort(mapping){
                if(mapping.request){
                    return mapping;
                }else{
                    var fullNotation ={};
            Severity: Minor
            Found in lib/loaders/MappingsBuilder.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 getEncodingStream has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            function getEncodingStream(encodingHeader, response, dataStream){
                let encodingName = encodingHeader;
                if(encodingName === "*"){
                    encodingName = "gzip";
                }
            Severity: Minor
            Found in lib/compressionHandler.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 buildMappingFileContent has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function buildMappingFileContent(req,res, options){
                const mappingFileContent = {
                    request: {
                        method: req.method,
                        url: req.url,
            Severity: Minor
            Found in lib/server.js - About 1 hr to fix

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

                  _buildFromDirectory(dirPath){
                      this.config.datatables = joinPathIfExists(dirPath, "datatables");
                      this.config.stubs = joinPathIfExists(dirPath, "stubs");
                      this.config.dumps = joinPathIfExists(dirPath, "dumps");
                      this.config.recordAndPlay.path = joinPathIfExists(dirPath, "recordings");
              Severity: Minor
              Found in lib/ConfigBuilder.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(!matches) return;
              Severity: Major
              Found in lib/RequestResolver.js - About 45 mins to fix

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

                module.exports = function(response, responseRecieved, fileName){
                    let encodingName = responseRecieved.headers["content-encoding"];
                    if(encodingName){
                        let encodingStream = supportedEncodings[ encodingName ];//when only one encoding name is given
                        if( !encodingStream ){//when multiple encoding schems are acceptable 
                Severity: Minor
                Found in lib/proxyResponseHandler.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

                Avoid deeply nested control flow statements.
                Open

                                            if(fileLevelMappings[i].response && fileLevelMappings[i].response.parser && typeof fileLevelMappings[i].response.parser === "string"){
                                                fileLevelMappings[i].response.parser = {
                                                    type : fileLevelMappings[i].response.parser
                                                };
                                            }
                Severity: Major
                Found in lib/loaders/MappingsBuilder.js - About 45 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language