IBM-Swift/Kitura

View on GitHub
Tests/KituraTests/TestCookies.swift

Summary

Maintainability
F
3 days
Test Coverage

Function cookieFrom has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    func cookieFrom(response: ClientResponse?, named: String) -> (HTTPCookie?, String?) {
        guard let response = response else {
            return (nil, nil)
        }
        var resultCookie: HTTPCookie? = nil
Severity: Minor
Found in Tests/KituraTests/TestCookies.swift - About 3 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 testCookieFromServer has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    func testCookieFromServer() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/1/sendcookie", callback: {response in
                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "/1/sendcookie route did not match single path request")

Severity: Major
Found in Tests/KituraTests/TestCookies.swift - About 2 hrs to fix

    File TestCookies.swift has 280 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import XCTest
    import Foundation
    #if swift(>=4.1)
      #if canImport(FoundationNetworking)
        import FoundationNetworking
    Severity: Minor
    Found in Tests/KituraTests/TestCookies.swift - About 2 hrs to fix

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

          func testCookieFromServer() {
              performServerTest(router, asyncTasks: { expectation in
                  self.performRequest("get", path: "/1/sendcookie", callback: {response in
                      XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "/1/sendcookie route did not match single path request")
      
      
      Severity: Minor
      Found in Tests/KituraTests/TestCookies.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 cookieFrom has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func cookieFrom(response: ClientResponse?, named: String) -> (HTTPCookie?, String?) {
              guard let response = response else {
                  return (nil, nil)
              }
              var resultCookie: HTTPCookie? = nil
      Severity: Minor
      Found in Tests/KituraTests/TestCookies.swift - About 1 hr to fix

        Function testNoCookies has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            func testNoCookies() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path: "/1/cookiedump", callback: {response in
                        XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "cookiedump route did not match single path request")
                        do {
        Severity: Minor
        Found in Tests/KituraTests/TestCookies.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 setupRouter has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static func setupRouter() -> Router {
                let router = Router()
        
                router.get("/1/cookiedump") {request, response, next in
                    var cookies: [String] = []
        Severity: Minor
        Found in Tests/KituraTests/TestCookies.swift - About 1 hr to fix

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

              private func cookieToServer(separator: String, quoteValue: Bool) {
                  performServerTest(router, asyncTasks: { expectation in
                      let cookieMap = [" Plover ": " value with spaces ",
                                     "Zxcv": "(E = mc^2)",
                                     "value with one quote": "\"",
          Severity: Minor
          Found in Tests/KituraTests/TestCookies.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 cookieToServer has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private func cookieToServer(separator: String, quoteValue: Bool) {
                  performServerTest(router, asyncTasks: { expectation in
                      let cookieMap = [" Plover ": " value with spaces ",
                                     "Zxcv": "(E = mc^2)",
                                     "value with one quote": "\"",
          Severity: Minor
          Found in Tests/KituraTests/TestCookies.swift - About 1 hr to fix

            Function testNoCookies has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                func testNoCookies() {
                    performServerTest(router, asyncTasks: { expectation in
                        self.performRequest("get", path: "/1/cookiedump", callback: {response in
                            XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "cookiedump route did not match single path request")
                            do {
            Severity: Minor
            Found in Tests/KituraTests/TestCookies.swift - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      for  part in parts[1..<parts.count] {
                                          let pieces = part.components(separatedBy: "=")
                                          let piece = pieces[0].lowercased()
                                          switch piece {
                                          case "secure", "httponly":
              Severity: Major
              Found in Tests/KituraTests/TestCookies.swift - About 45 mins to fix

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

                /**
                 * Copyright IBM Corporation 2016
                 *
                 * Licensed under the Apache License, Version 2.0 (the "License");
                 * you may not use this file except in compliance with the License.
                Severity: Major
                Found in Tests/KituraTests/TestCookies.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestCookies.swift on lines 1..329

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

                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

                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

                    static var allTests: [(String, (TestCookies) -> () throws -> Void)] {
                        return [
                            ("testCookieToServerWithSemiColonSeparator", testCookieToServerWithSemiColonSeparator),
                            ("testCookieToServerWithSemiColonSpaceSeparator", testCookieToServerWithSemiColonSpaceSeparator),
                            ("testCookieToServerWithSemiColonWhitespacesSeparator", testCookieToServerWithSemiColonWhitespacesSeparator),
                Severity: Major
                Found in Tests/KituraTests/TestCookies.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestSubrouter.swift on lines 32..40

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

                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

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                            self.performRequest("get", path: "/1/sendcookie", callback: {response in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Closure is the function's final argument and may be passed as a trailing closure instead
                Open

                        }, { expectation in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                trailing-closure

                Closures that are the last argument of a function should be passed into the function using trailing closure syntax.

                Preferred

                reversed = names.sort { s1, s2 in return s1 > s2 }

                Not Preferred

                reversed = names.sort({ s1, s2 in return s1 > s2 })

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                        router.get("/2/sendcookie") {request, response, next in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                            self.performRequest("get", path: "/1/cookiedump", callback: {response in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                            self.performRequest("get", path: "/1/cookiedump", callback: {response in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                        router.get("/1/cookiedump") {request, response, next in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                        router.get("/3/sendcookie") {request, response, next in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                            self.performRequest("get", path: "/1/cookiedump", callback: {response in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                Closure is the function's final argument and may be passed as a trailing closure instead
                Open

                        }, { expectation in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                trailing-closure

                Closures that are the last argument of a function should be passed into the function using trailing closure syntax.

                Preferred

                reversed = names.sort { s1, s2 in return s1 > s2 }

                Not Preferred

                reversed = names.sort({ s1, s2 in return s1 > s2 })

                Parameter clause in closure signature should be preceded by exactly one space
                Open

                        router.get("/1/sendcookie") {request, response, next in
                Severity: Minor
                Found in Tests/KituraTests/TestCookies.swift by tailor

                There are no issues that match your filters.

                Category
                Status