Sources/Kitura/Router.swift
Function handle
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
Open
public func handle(request: ServerRequest, response: ServerResponse) {
var decoder: (() -> BodyDecoder)?
if let contentType = request.headers["Content-Type"]?[0], let mediaType = MediaType(contentTypeHeader: contentType) {
decoder = decoders[mediaType]
}
- Read upRead up
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
File Router.swift
has 260 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import KituraNet
import LoggerAPI
import Foundation
import KituraTemplateEngine
import KituraContracts
Function handle
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public func handle(request: ServerRequest, response: ServerResponse) {
var decoder: (() -> BodyDecoder)?
if let contentType = request.headers["Content-Type"]?[0], let mediaType = MediaType(contentTypeHeader: contentType) {
decoder = decoders[mediaType]
}
TODO found Open
Open
//TODO fix the stack
- Exclude checks
TODO comments should be formatted either as <todo: description> or <todo description></todo></todo:> Open
Open
//TODO fix the stack
- Read upRead up
- Exclude checks
todo-syntax
TODO comments should be defined separately using non-nested single line comments. They should adhere to the <TODO: description>
or <TODO(developer-name): description>
syntax. Empty TODO comments will be flagged.
Preferred
// TODO: <insert mandatory todo comment>
// TODO(dev-name): <insert mandatory todo comment></insert></insert>
Not Preferred
// TODO:
/// TODO: Documentation comments should not have TODOs
//// TODO: Nested comments should not have TODOs
// //TODO: Nested comments should not have TODOs
// TODO: Nested comments should not have TODOs // some comment
//// TODO: Nested comments should not have TODOs