pretenderjs/pretender

View on GitHub
src/pretender.ts

Summary

Maintainability
C
1 day
Test Coverage

File pretender.ts has 291 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as FakeFetch from 'whatwg-fetch';
import FakeXMLHttpRequest from 'fake-xml-http-request';
import { Params, QueryParams } from 'route-recognizer';
import { ResponseHandler, ResponseHandlerInstance } from '../index.d';
import Hosts from './hosts';
Severity: Minor
Found in src/pretender.ts - About 3 hrs to fix

    Function handleRequest has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      handleRequest(request: FakeRequest) {
        let verb = request.method.toUpperCase();
        let path = request.url;
    
        let handler = this._handlerFor(verb, path, request);
    Severity: Minor
    Found in src/pretender.ts - About 1 hr to fix

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

        handleRequest(request: FakeRequest) {
          let verb = request.method.toUpperCase();
          let path = request.url;
      
          let handler = this._handlerFor(verb, path, request);
      Severity: Minor
      Found in src/pretender.ts - 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 scheduleProgressEvent has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function scheduleProgressEvent(request, startTime, totalTime) {
        let totalSize = 0;
        const body = request.requestBody;
        if (body) {
          if (body instanceof FormData) {
      Severity: Minor
      Found in src/pretender.ts - About 1 hr to fix

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

          constructor() {
            let lastArg = arguments[arguments.length - 1];
            let options = typeof lastArg === 'object' ? lastArg : null;
            let shouldNotTrack = options && options.trackRequests === false;
        
        
        Severity: Minor
        Found in src/pretender.ts - About 1 hr to fix

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

            constructor() {
              let lastArg = arguments[arguments.length - 1];
              let options = typeof lastArg === 'object' ? lastArg : null;
              let shouldNotTrack = options && options.trackRequests === false;
          
          
          Severity: Minor
          Found in src/pretender.ts - 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 handleResponse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            handleResponse(request: FakeRequest, strategy, callback: Function) {
              let delay = typeof strategy === 'function' ? strategy() : strategy;
              delay = typeof delay === 'boolean' || typeof delay === 'number' ? delay : 0;
          
              if (delay === false) {
          Severity: Minor
          Found in src/pretender.ts - 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

          There are no issues that match your filters.

          Category
          Status