IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

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

    static func setupRouter() -> Router {
        let subsubRouter = Router()
        subsubRouter.get("/") { _, response, next in
            response.status(HTTPStatusCode.OK).send("hello from the sub sub")
            next()
Severity: Minor
Found in Tests/KituraTests/TestSubrouter.swift - About 1 hr to fix

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

        func testHeaders() {
            var headers = Headers(headers: HeadersContainer())
            headers.append("plover", value: "xyzzy")
            headers.append("kitura", value: "The greatest")
    
    
    Severity: Minor
    Found in Tests/KituraTests/MiscellaneousTests.swift - About 1 hr to fix

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

          func performRequest(_ method: String, path: String, port: Int? = nil, socketPath: String? = nil, useSSL: Bool? = nil, useUnixSocket: Bool? = nil, followRedirects: Bool = true,
                              callback: @escaping ClientRequest.Callback, headers: [String: String]? = nil,
                              requestModifier: ((ClientRequest) -> Void)? = nil) {
      
              let port = port ?? self.port
      Severity: Minor
      Found in Tests/KituraTests/KituraTest.swift - About 1 hr to fix

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

                buildServerTest(router, timeout: 30)
                    .request("get", path: "/userMultiMiddleware?id=2", headers: goodHeaders)
                    .hasStatus(.OK)
                    .hasContentType(withPrefix: "application/json")
                    .hasData(expectedArray)
        Severity: Major
        Found in Tests/KituraTests/TestTypeSafeMiddleware.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCodableRouter.swift on lines 831..842

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

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

                        if let cookie = cookie {
                            XCTAssertEqual(cookie.value, cookie3Value as String, "Value of Cookie \(cookie3Name) is not \(cookie3Value), was \(cookie.value)")
                            XCTAssertEqual(cookie.path, "/", "Path of Cookie \(cookie3Name) is not (/), was \(cookie.path)")
                            XCTAssertEqual(cookie.domain, cookieHost as String, "Domain of Cookie \(cookie3Name) is not \(cookieHost), was \(cookie.domain)")
                            XCTAssertTrue(cookie.isSecure, "\(cookie3Name) wasn't marked as secure. It should have been marked so.")
        Severity: Major
        Found in Tests/KituraTests/TestCookies.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCookies.swift on lines 118..124

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

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

                buildServerTest(router, timeout: 30)//
                    .request("post", path: "/ok", data: user)
                    .hasStatus(.OK)
                    .hasContentType(withPrefix: "application/json")
                    .hasData(user)
        Severity: Major
        Found in Tests/KituraTests/TestCodableRouter.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestTypeSafeMiddleware.swift on lines 516..527

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

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

                        if let cookie1 = cookie1 {
                            XCTAssertEqual(cookie1.value, cookie1Value as String, "Value of Cookie \(cookie1Name) is not \(cookie1Value), was \(cookie1.value)")
                            XCTAssertEqual(cookie1.path, "/", "Path of Cookie \(cookie1Name) is not (/), was \(cookie1.path)")
                            XCTAssertEqual(cookie1.domain, cookieHost as String, "Domain of Cookie \(cookie1Name) is not \(cookieHost), was \(cookie1.domain)")
                            XCTAssertFalse(cookie1.isSecure, "\(cookie1Name) was marked as secure. Should have not been marked so.")
        Severity: Major
        Found in Tests/KituraTests/TestCookies.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCookies.swift on lines 144..150

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

        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 testPostJSONRequest has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func testPostJSONRequest() {
                let jsonToTest = SomeJSON()
        
                performServerTest(router) { expectation in
                    self.performRequest("post", path: "/bodytest", callback: { response in
        Severity: Minor
        Found in Tests/KituraTests/TestResponse.swift - About 1 hr to fix

          Function handleMatch has 32 lines of code (exceeds 25 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 1 hr to fix

            Function startUnixSocketServer has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private func startUnixSocketServer(router: ServerDelegate, options: ServerOptions?) -> String? {
                    // Servers with options (live for duration of one test)
                    if (options != nil) {
                        let server = doStartUnixSocketServer(router: router, options: options)
                        return server?.unixDomainSocketPath
            Severity: Minor
            Found in Tests/KituraTests/KituraTest.swift - About 1 hr to fix

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

              class URLEncodedMultiValueBodyParser: BodyParserProtocol {
                  func parse(_ data: Data) -> ParsedBody? {
                      guard let bodyAsString = String(data: data, encoding: .utf8) else {
                          return nil
                      }
              Severity: Major
              Found in Sources/Kitura/bodyParser/URLEncodedBodyParser.swift and 1 other location - About 1 hr to fix
              Sources/Kitura/bodyParser/URLEncodedBodyParser.swift on lines 19..28

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

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

              class URLEncodedBodyParser: BodyParserProtocol {
                  func parse(_ data: Data) -> ParsedBody? {
                      guard let bodyAsString = String(data: data, encoding: .utf8) else {
                          return nil
                      }
              Severity: Major
              Found in Sources/Kitura/bodyParser/URLEncodedBodyParser.swift and 1 other location - About 1 hr to fix
              Sources/Kitura/bodyParser/URLEncodedBodyParser.swift on lines 30..39

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

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

                  func testDataIsNotCorrupted() {
                      // Corrupted files will have more bytes or less bytes than required
                      // So we check the file is intact after reconstructing it (after various range requests)
                      performServerTest(router) { expectation in
                          self.performRequest("get", path: "/qwer/index.html", callback: { response in
              Severity: Minor
              Found in Tests/KituraTests/TestStaticFileServer.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 run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public func run() {
                      // Construct a list of async tasks that will perform each
                      // request in turn and test their associated assertions
                      let tasks = requests.map { request in
                          return { (expectation: XCTestExpectation) in
              Severity: Minor
              Found in Tests/KituraTests/KituraTestBuilder.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 runGetResponseTest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  private func runGetResponseTest(path: String, expectedResponseText: String? = nil,
                                                  expectedStatusCode: HTTPStatusCode = HTTPStatusCode.OK,
                                                  bodyChecker: BodyChecker? = nil,
                                                  withRouter: Router? = nil) {
                      performServerTest(withRouter ?? router) { expectation in
              Severity: Minor
              Found in Tests/KituraTests/TestStaticFileServer.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 process has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  func process(request: RouterRequest, response: RouterResponse, parameterWalker: RouterParameterWalker, next: @escaping () -> Void) {
                      guard let path = request.parsedURLPath.path else {
                          Log.error("Failed to process request (path is nil)")
                          next()
                          return
              Severity: Minor
              Found in Sources/Kitura/RouterElement.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 getFilePath has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                      func getFilePath(from request: RouterRequest) -> String? {
                          var filePath = servingFilesPath
                          guard let requestPath = request.parsedURLPath.path else {
                              return nil
                          }
              Severity: Minor
              Found in Sources/Kitura/staticFileServer/FileServer.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 performRequest has 10 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  func performRequest(_ method: String, path: String, port: Int? = nil, socketPath: String? = nil, useSSL: Bool? = nil, useUnixSocket: Bool? = nil, followRedirects: Bool = true,
                                      callback: @escaping ClientRequest.Callback, headers: [String: String]? = nil,
                                      requestModifier: ((ClientRequest) -> Void)? = nil) {
              Severity: Major
              Found in Tests/KituraTests/KituraTest.swift - About 1 hr to fix

                Function hightlight has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        return function hightlight(o) {
                            var regex;
                            o = _.mixin({}, defaults, o);
                            if (!o.node || !o.pattern) {
                                return;
                Severity: Minor
                Found in docs/js/typeahead.jquery.js - About 1 hr to fix

                  Function hightlight has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          return function hightlight(o) {
                              var regex;
                              o = _.mixin({}, defaults, o);
                              if (!o.node || !o.pattern) {
                                  return;
                    Severity
                    Category
                    Status
                    Source
                    Language