IBM-Swift/Kitura

View on GitHub
Tests/KituraTests/TestSubrouter.swift

Summary

Maintainability
D
2 days
Test Coverage

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

          func testExternSub() {
              router.all("/extern", middleware: ExternSubrouter.getRouter())
      
              performServerTest(router, asyncTasks: { expectation in
                  self.performRequest("get", path:"/extern", callback: {response in
      Severity: Minor
      Found in Tests/KituraTests/TestSubrouter.swift - About 1 hr to fix

        Function testMergeParams has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            func testMergeParams() {
                let simpleHandler = { (req: RouterRequest, res: RouterResponse, next: () -> Void) throws in
                    next()
                }
        
        
        Severity: Minor
        Found in Tests/KituraTests/TestSubrouter.swift - About 55 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 testSubSubs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            func testSubSubs() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/sub/sub2", 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: Minor
        Found in Tests/KituraTests/TestSubrouter.swift - 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

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

            func testSimpleSub() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/sub", 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: Minor
        Found in Tests/KituraTests/TestSubrouter.swift - 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

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

            func testExternSub() {
                router.all("/extern", middleware: ExternSubrouter.getRouter())
        
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/extern", callback: {response in
        Severity: Minor
        Found in Tests/KituraTests/TestSubrouter.swift - 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

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

            func testSimpleSub() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/sub", 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/TestSubrouter.swift and 1 other location - About 3 hrs to fix
        Tests/KituraTests/TestSubrouter.swift on lines 107..134

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

        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

            func testSubSubs() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/sub/sub2", 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/TestSubrouter.swift and 1 other location - About 3 hrs to fix
        Tests/KituraTests/TestSubrouter.swift on lines 47..74

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

        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

                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path: "/root1/123/sub1/456/subsub1/789", callback: { response in
                        XCTAssertEqual(response?.statusCode, .OK)
        
                        var data = Data()
        Severity: Major
        Found in Tests/KituraTests/TestSubrouter.swift and 1 other location - About 2 hrs to fix
        Tests/KituraTests/TestSubrouter.swift on lines 193..212

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

        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

                }, { expectation in
                    self.performRequest("get", path: "/root1/123/sub1/456/subsub2/passthrough", callback: { response in
                        XCTAssertEqual(response?.statusCode, .OK)
        
                        var data = Data()
        Severity: Major
        Found in Tests/KituraTests/TestSubrouter.swift and 1 other location - About 2 hrs to fix
        Tests/KituraTests/TestSubrouter.swift on lines 174..193

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

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

            func testMultipleMiddleware() {
                performServerTest(router) { expectation in
                    self.performRequest("get", path:"/middle/sub1", 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/TestSubrouter.swift and 2 other locations - About 2 hrs to fix
        Tests/KituraTests/TestBridgingHTTPStatusCode.swift on lines 43..59
        Tests/KituraTests/TestResponse.swift on lines 89..105

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

        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, (TestSubrouter) -> () throws -> Void)] {
                return [
                    ("testSimpleSub", testSimpleSub),
                    ("testExternSub", testExternSub),
                    ("testSubSubs", testSubSubs),
        Severity: Major
        Found in Tests/KituraTests/TestSubrouter.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCookies.swift on lines 44..52

        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:"/sub/sub2", callback: {response in

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

                    self.performRequest("get", path:"/middle/sub1", callback: {response in

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

                    self.performRequest("get", path:"/extern/sub1", callback: {response in

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

                    self.performRequest("get", path:"/sub/sub2/sub1", callback: {response in

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

                    self.performRequest("get", path:"/sub/sub1", callback: {response in

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

                    self.performRequest("get", path:"/sub", callback: {response in

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

                }, { expectation in

        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 })

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

                }, { expectation in

        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

                    self.performRequest("get", path:"/extern", callback: {response in

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

                }, { expectation in

        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 })

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

                }, { expectation in

        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 })

        There are no issues that match your filters.

        Category
        Status