NaturalIntelligence/Stubmatic

View on GitHub

Showing 106 of 106 total issues

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

    it('should respond with  500 when invalid strategy given', function (done) {
        chai.request("http://localhost:9999")
            .get('/stubs/invalid-strategy')
            .then(res => {
                expect(res.status).toBe(500);
Severity: Major
Found in functional-tests/fileresponse_spec.js and 2 other locations - About 3 hrs to fix
functional-tests/fileresponse_spec.js on lines 171..180
functional-tests/skipProcessing_spec.js on lines 69..78

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

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 3 locations. Consider refactoring.
Open

    it('should response with 500 when file is not found', function (done) {
        chai.request("http://localhost:9999")
            .get('/stubs/skipProcessing/invalid')
            .then(res => {
                expect(res.status).toBe(500);
Severity: Major
Found in functional-tests/skipProcessing_spec.js and 2 other locations - About 3 hrs to fix
functional-tests/fileresponse_spec.js on lines 171..180
functional-tests/fileresponse_spec.js on lines 182..191

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

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 getFileName has a Cognitive Complexity of 22 (exceeds 5 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 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

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

        chai.request("http://localhost:9999")
            .get('/stubs/round-robin-first-found')
            .then(res => {
                expect(res.status).toBe(200);
                expect(res.text).toBe("file 3");
Severity: Major
Found in functional-tests/fileresponse_spec.js and 4 other locations - About 2 hrs to fix
functional-tests/fileresponse_spec.js on lines 70..77
functional-tests/fileresponse_spec.js on lines 99..106
functional-tests/fileresponse_spec.js on lines 141..148
functional-tests/fileresponse_spec.js on lines 160..167

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

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 5 locations. Consider refactoring.
Open

        chai.request("http://localhost:9999")
            .get('/stubs/round-robin')
            .then(res => {
                expect(res.status).toBe(200);
                expect(res.text).toBe("id: 1; name: {{ url[2] }}");
Severity: Major
Found in functional-tests/fileresponse_spec.js and 4 other locations - About 2 hrs to fix
functional-tests/fileresponse_spec.js on lines 99..106
functional-tests/fileresponse_spec.js on lines 108..115
functional-tests/fileresponse_spec.js on lines 141..148
functional-tests/fileresponse_spec.js on lines 160..167

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

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 5 locations. Consider refactoring.
Open

        chai.request("http://localhost:9999")
            .get('/stubs/round-robin-first-found/multi')
            .then(res => {
                expect(res.status).toBe(202);
                expect(res.text).toBe("id: 1; name: {{ url[2] }}");
Severity: Major
Found in functional-tests/fileresponse_spec.js and 4 other locations - About 2 hrs to fix
functional-tests/fileresponse_spec.js on lines 70..77
functional-tests/fileresponse_spec.js on lines 99..106
functional-tests/fileresponse_spec.js on lines 108..115
functional-tests/fileresponse_spec.js on lines 141..148

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

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 5 locations. Consider refactoring.
Open

        chai.request("http://localhost:9999")
            .get('/stubs/round-robin-first-found/multi')
            .then(res => {
                expect(res.status).toBe(202);
                expect(res.text).toBe("id: 1; name: {{ url[2] }}");
Severity: Major
Found in functional-tests/fileresponse_spec.js and 4 other locations - About 2 hrs to fix
functional-tests/fileresponse_spec.js on lines 70..77
functional-tests/fileresponse_spec.js on lines 99..106
functional-tests/fileresponse_spec.js on lines 108..115
functional-tests/fileresponse_spec.js on lines 160..167

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

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 5 locations. Consider refactoring.
Open

        chai.request("http://localhost:9999")
            .get('/stubs/round-robin-first-found')
            .then(res => {
                expect(res.status).toBe(200);
                expect(res.text).toBe("id: 1; name: {{ url[2] }}");
Severity: Major
Found in functional-tests/fileresponse_spec.js and 4 other locations - About 2 hrs to fix
functional-tests/fileresponse_spec.js on lines 70..77
functional-tests/fileresponse_spec.js on lines 108..115
functional-tests/fileresponse_spec.js on lines 141..148
functional-tests/fileresponse_spec.js on lines 160..167

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

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 exports has a Cognitive Complexity of 21 (exceeds 5 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 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 matchAndCapture has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function matchAndCapture(mapped_request, http_request){
    var matched = {}, i=0;

    if(Array.isArray(mapped_request.method)){
        if(mapped_request.method.indexOf(http_request.method) === -1) return;
Severity: Minor
Found in lib/RequestResolver.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 process has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    process(request, response, onSuccess, onError){
        
        var rc = new RequestContext(request);
        logger.info(rc.getTransactionId() + " " + request.method+": "+request.url,'green');

Severity: Major
Found in lib/RequestProcessor.js - About 2 hrs to fix

    Function exports has a Cognitive Complexity of 15 (exceeds 5 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

    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 parse has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        parse(http_request, mappings, dataTables){
            for(var i=0;i<mappings.length;i++){
                var entry = util.clone(mappings[i]);
                var matched = matchAndCapture(entry.request, http_request);
                if(matched){//if nothing matches in current mapping, check for other matching
    Severity: Minor
    Found in lib/RequestResolver.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 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        build(options){
            this.config = {
                mappings: {},
                server:{},
                recordAndPlay : {
    Severity: Minor
    Found in lib/ConfigBuilder.js - About 1 hr to fix

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

      function buildServerOptions(args) {
          var options = {};
          for (var i = 2; i < args.length; i++) {
              if (args[i].indexOf("-") === 0) {
                  var key = args[i];
      Severity: Minor
      Found in index.js - About 1 hr to fix

        Function buildFunctionExp has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        var buildFunctionExp = function(exp){
            var paramStart = 0, startIndex = 0;
            var inFunction = false, nestedFunction = false;
            var args = [];
            for(var i=0;i<exp.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

        Function buildMappings has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            buildMappings(mappingFiles, allMappings){
                var fileLevelMappings;
                allMappings = allMappings || [];
                //defaultConfig = config.mappings.default || defaultConfig;
                defaultConfig = deepAssign({},defaultConfig, this.options.mappings.default);
        Severity: Minor
        Found in lib/loaders/MappingsBuilder.js - About 1 hr to fix

          Function redirect has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function redirect(request, response, requestProcessor, baseUrl, options){
              const targetUrl = url.resolve(baseUrl, request.originalUrl);
              const reqOptions = {
                  url: targetUrl,
                  method: request.method,
          Severity: Minor
          Found in lib/server.js - About 1 hr to fix

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

                reload(){
                    this.tables = [];
                    if(this.source){
                        try{
                            var files = fs.readdirSync(this.source);
            Severity: Minor
            Found in lib/loaders/DataTablesLoader.js - About 1 hr to fix

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

              function requestResponseHandler(request, response, requestProcessor) {
                      
                  request.originalUrl = request.url;
                  var parsedURL = url.parse(request.url, true);
                  request.url = parsedURL.pathname;
              Severity: Minor
              Found in lib/server.js - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language