IBM-Swift/Kitura

View on GitHub

Showing 279 of 850 total issues

Function serveNonDirectoryFile has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

        private func serveNonDirectoryFile(_ filePath: String, response: RouterResponse) {
            if  !isValidFilePath(filePath) {
                return
            }

Severity: Minor
Found in Sources/Kitura/staticFileServer/FileServer.swift - 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

RouterResponse has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

public class RouterResponse {

    // MARK: Properties
    
    struct State {
Severity: Minor
Found in Sources/Kitura/RouterResponse.swift - About 2 hrs to fix

    Function testBuildRegexFromPattern has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func testBuildRegexFromPattern() {
            var regex: NSRegularExpression?
    
            var isSimpleString = false
            var strings: [String]?
    Severity: Major
    Found in Tests/KituraTests/TestRouteRegex.swift - About 2 hrs to fix

      Function handle has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      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]
              }
      Severity: Minor
      Found in Sources/Kitura/Router.swift - 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 performSimpleMatch has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          private func performSimpleMatch(path: String, request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) {
              guard let pattern = pattern else {
                  next()
                  return
              }
      Severity: Minor
      Found in Sources/Kitura/RouterElement.swift - 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 testCustomCoderGet has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func testCustomCoderGet() {
              struct SimpleQuery: QueryParams {
                  let string: String
              }
              let jsonEncoder: () -> BodyEncoder = {
      Severity: Major
      Found in Tests/KituraTests/TestTypeSafeMiddleware.swift - About 2 hrs to fix

        Function testMergeParams has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func testMergeParams() {
                let simpleHandler = { (req: RouterRequest, res: RouterResponse, next: () -> Void) throws in
                    next()
                }
        
        
        Severity: Major
        Found in Tests/KituraTests/TestSubrouter.swift - About 2 hrs to fix

          Function testParameters has 58 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              func testParameters() {
                  let router = Router()
          
                  router.parameter("user") { request, response, value, next in
                      XCTAssertNotNil(value)
          Severity: Major
          Found in Tests/KituraTests/TestRequests.swift - About 2 hrs to fix

            Function handleMatch has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                    private static func handleMatch(rawHeaderValue: String, type: String, matchAllPattern: String,
                                                    criteriaMatches: inout CriteriaMatches, headerOrder: Int) {
                        let parsedHeaderValue = parse(mediaType: rawHeaderValue)
                        let headerType = parsedHeaderValue.type
                        guard !headerType.isEmpty && parsedHeaderValue.qValue > 0.0 else {
            Severity: Minor
            Found in Sources/Kitura/MimeTypeAcceptor.swift - 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

            File KituraTestBuilder.swift has 260 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import XCTest
            import Kitura
            
            @testable import KituraNet
            @testable import KituraContracts
            Severity: Minor
            Found in Tests/KituraTests/KituraTestBuilder.swift - About 2 hrs to fix

              Function testJsonp has 56 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  func testJsonp() {
                      performServerTest(router) { expectation in
                          self.performRequest("get", path: "/jsonp?callback=testfn", callback: { response in
                              XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                              XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
              Severity: Major
              Found in Tests/KituraTests/TestResponse.swift - About 2 hrs to fix

                File Router.swift has 260 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import KituraNet
                import LoggerAPI
                import Foundation
                import KituraTemplateEngine
                import KituraContracts
                Severity: Minor
                Found in Sources/Kitura/Router.swift - About 2 hrs to fix

                  Function testCustomCoder has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      func testCustomCoder() {
                          struct SimpleQuery: QueryParams {
                              let string: String
                          }
                          let jsonEncoder: () -> BodyEncoder = {
                  Severity: Major
                  Found in Tests/KituraTests/TestTypeSafeMiddleware.swift - About 2 hrs to fix

                    Function parse has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        static func parse(size: UInt64, headerValue: String, shouldCombine: Bool = true) throws -> RangeHeader {
                    
                            guard let index = headerValue.range(of: "=")?.lowerBound else {
                                // malformed
                                throw RangeHeader.Error.malformed
                    Severity: Major
                    Found in Sources/Kitura/staticFileServer/RangeHeader.swift - About 2 hrs to fix

                      Function constructIdentOutResultHandler has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static func constructIdentOutResultHandler<IdType: Identifier, OutputType: Codable>(successStatus: HTTPStatusCode = .OK, response: RouterResponse, completion: @escaping () -> Void) -> IdentifierCodableResultClosure<IdType, OutputType> {
                              return { id, codableOutput, error in
                                  var status = successStatus
                                  if let error = error {
                                      status = httpStatusCode(from: error)
                      Severity: Minor
                      Found in Sources/Kitura/CodableRouter.swift - 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 initialize has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                  initialize: function initialize(o, datasets) {
                                      var www;
                                      datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
                                      o = o || {};
                                      www = WWW(o.classNames);
                      Severity: Major
                      Found in docs/js/typeahead.jquery.js - About 2 hrs to fix

                        Function initialize has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                    initialize: function initialize(o, datasets) {
                                        var www;
                                        datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
                                        o = o || {};
                                        www = WWW(o.classNames);

                          Function testPostRequestUrlEncoded has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              func testPostRequestUrlEncoded() {
                                  performServerTest(router) { expectation in
                                      self.performRequest("post", path: "/bodytest", callback: {response in
                                          XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                                          XCTAssertNotNil(response?.headers["Date"], "There was No Date header in the response")
                          Severity: Minor
                          Found in Tests/KituraTests/TestResponse.swift - About 1 hr to fix

                            Function testSimpleMatches has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                            Open

                                func testSimpleMatches() {
                                    var router = Router()
                            
                                    router.all("/test", handler: handler)
                            
                            
                            Severity: Minor
                            Found in Tests/KituraTests/TestRouteRegex.swift - 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 testSimplePaths has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                            Open

                                func testSimplePaths() {
                                    var router = Router()
                            
                                    router.all("", handler: handler)
                            
                            
                            Severity: Minor
                            Found in Tests/KituraTests/TestRouteRegex.swift - 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

                            Severity
                            Category
                            Status
                            Source
                            Language