mseemann/js-restful-express

View on GitHub

Showing 5 of 5 total issues

Function registerService has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    registerService(service:any){
        if(typeof service === 'function'){
            throw new TypeError('A type is not allowed - only an object can be registered');
        }

Severity: Major
Found in src/express/registry.ts - About 2 hrs to fix

Function collectAndConvertArgs has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    collectAndConvertArgs(req:express.Request, res: express.Response, next:express.NextFunction, service:Object, method:MethodDescription): any[]{
        const args = [];

        args.length = method.pathParams.length + method.headerParams.length + method.queryParams.length + method.contextParams.length;

Severity: Minor
Found in src/express/registry.ts - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

                                if(!allowed){
                                    res.status(403).send('permission denied');
                                    return;
                                }
Severity: Major
Found in src/express/registry.ts - About 45 mins to fix

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

    render(res: express.Response, value:any){
        if ( typeof value === 'undefined' || value === null) {
            if(this.isResponseParameterPresent()){
                // do not send any reponse values if a HttpReponse Context param is provided to the service method.
                return;
Severity: Minor
Found in src/express/renderers.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

Function convertRawParamToMethodParam has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    convertRawParamToMethodParam(service, method, pathParam, rawParam){
        // try to figure out what the method signature expects
        let paramTypes = Reflect.getMetadata('design:paramtypes', service, method.methodName);
        if(paramTypes && paramTypes.length >= pathParam.index){
            // this is a constructor function of the expected type
Severity: Minor
Found in src/express/registry.ts - About 25 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

Severity
Category
Status
Source
Language