IBM-Swift/Kitura

View on GitHub
Tests/KituraTests/TestCustomCoders.swift

Summary

Maintainability
D
2 days
Test Coverage

Function testCustomQueryEncoder has 80 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    func testCustomQueryEncoder() {
        // Set up router for this test
        let customRouter = Router()
        customRouter.encoders[.urlEncoded] =  { return QueryEncoder() }
        
Severity: Major
Found in Tests/KituraTests/TestCustomCoders.swift - About 3 hrs to fix

    Function testCustomQueryEncoder has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        func testCustomQueryEncoder() {
            // Set up router for this test
            let customRouter = Router()
            customRouter.encoders[.urlEncoded] =  { return QueryEncoder() }
            
    Severity: Minor
    Found in Tests/KituraTests/TestCustomCoders.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 testRawCustomCoder has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func testRawCustomCoder() {
            // Set up router for this test
            let customRouter = Router()
            let jsonDecoder: () -> BodyDecoder = {
                let decoder = JSONDecoder()
    Severity: Minor
    Found in Tests/KituraTests/TestCustomCoders.swift - About 1 hr to fix

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

          func testCustomCoder() {
              let jsonEncoder: () -> BodyEncoder = {
                  let encoder = JSONEncoder()
                  encoder.dateEncodingStrategy = .secondsSince1970
                  return encoder
      Severity: Minor
      Found in Tests/KituraTests/TestCustomCoders.swift - About 1 hr to fix

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

        /**
         * Copyright IBM Corporation 2018
         *
         * 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/TestCustomCoders.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 1..244

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

        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(customRouter) { expectation in
                    self.performRequest("get", path: "/rawget", callback: { response in
                        if let response = response,
                           let responseJson = try? CodableDateAsTimeInterval(response: response) {
                            XCTAssertEqual(responseJson.date, 1519206456)
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 232..242

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

        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(customRouter) { expectation in
                    self.performRequest("get", path: "/sendjson", callback: { response in
                        if let response = response,
                           let responseJson = try? CodableDateAsTimeInterval(response: response) {
                            XCTAssertEqual(responseJson.date, 1519206456)
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 130..140

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

        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

            struct CodableDate: Codable, Equatable {
                let date: Date
                init(date: Date) {
                    self.date = date
                }
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 2 other locations - About 1 hr to fix
        Tests/KituraTests/TestCodableRouter.swift on lines 61..71
        Tests/KituraTests/TestTypeSafeMiddleware.swift on lines 86..95

        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

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

                performServerTest(customRouter) { expectation in
                    self.performRequest("get", path: "/sendjson", callback: { response in
                        if let response = response, let responseString = try? response.readString() {
                            XCTAssertEqual(responseString, "{\"date\":540899256}")
                        } else {
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 185..194

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

        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(customRouter) { expectation in
                    self.performRequest("get", path: "/rawget", callback: { response in
                        if let response = response, let responseString = try? response.readString() {
                            XCTAssertEqual(responseString, "{\"date\":540899256}")
                        } else {
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 214..223

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

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

            static var allTests: [(String, (TestCustomCoders) -> () throws -> Void)] {
                return [
                    ("testCustomCoder", testCustomCoder),
                    ("testRawCustomCoder", testRawCustomCoder),
                    ("testCustomQueryEncoder", testCustomQueryEncoder),
        Severity: Major
        Found in Tests/KituraTests/TestCustomCoders.swift and 3 other locations - About 50 mins to fix
        Tests/KituraTests/TestContentType.swift on lines 24..30
        Tests/KituraTests/TestErrors.swift on lines 32..38
        Tests/KituraTests/TestRangeHeaderDataExtensions.swift on lines 24..30

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

        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

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

                customRouter.get("/rawget") { _, response, next in
                    let date = Date(timeIntervalSince1970: 1519206456)
                    let codableDate = CodableDate(date: date)
                    response.send(codableDate)
                    next()
        Severity: Minor
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 45 mins to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 155..160

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

        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

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

                customRouter.get("/rawget") { _, response, next in
                    let date = Date(timeIntervalSince1970: 1519206456)
                    let codableDate = CodableDate(date: date)
                    response.send(codableDate)
                    next()
        Severity: Minor
        Found in Tests/KituraTests/TestCustomCoders.swift and 1 other location - About 45 mins to fix
        Tests/KituraTests/TestCustomCoders.swift on lines 117..122

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

        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

        There are no issues that match your filters.

        Category
        Status