IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

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

        get(route) { request, response, next in
            Log.verbose("Received GET (plural) type-safe request")
            handler(CodableHelpers.constructOutResultHandler(response: response, completion: next))
        }
Severity: Major
Found in Sources/Kitura/CodableRouter.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/CodableRouter.swift on lines 426..429
Sources/Kitura/CodableRouter.swift on lines 450..453
Sources/Kitura/CodableRouter.swift on lines 555..558

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

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

        get(route) { request, response, next in
            Log.verbose("Received GET (plural with identifier) type-safe request")
            handler(CodableHelpers.constructTupleArrayOutResultHandler(response: response, completion: next))
        }
Severity: Major
Found in Sources/Kitura/CodableRouter.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/CodableRouter.swift on lines 426..429
Sources/Kitura/CodableRouter.swift on lines 438..441
Sources/Kitura/CodableRouter.swift on lines 555..558

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

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

    public static func expires(_ value: Date?) -> AdditionalCookieAttribute {
        return AdditionalCookieAttribute(_CookieAttribute.expires(value))
    }
Severity: Major
Found in Sources/Kitura/AdditionalCookieAttribute.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/AdditionalCookieAttribute.swift on lines 35..37
Sources/Kitura/AdditionalCookieAttribute.swift on lines 40..42
Sources/Kitura/AdditionalCookieAttribute.swift on lines 65..67

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

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

    public static func originURL(_ value: URL?) -> AdditionalCookieAttribute {
        return AdditionalCookieAttribute(_CookieAttribute.originURL(value))
    }
Severity: Major
Found in Sources/Kitura/AdditionalCookieAttribute.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/AdditionalCookieAttribute.swift on lines 35..37
Sources/Kitura/AdditionalCookieAttribute.swift on lines 40..42
Sources/Kitura/AdditionalCookieAttribute.swift on lines 50..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 40.

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

        delete(route) { request, response, next in
            Log.verbose("Received DELETE (plural) type-safe request")
            handler(CodableHelpers.constructResultHandler(response: response, completion: next))
        }
Severity: Major
Found in Sources/Kitura/CodableRouter.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/CodableRouter.swift on lines 426..429
Sources/Kitura/CodableRouter.swift on lines 438..441
Sources/Kitura/CodableRouter.swift on lines 450..453

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

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

    public static func comment(_ value: String?) -> AdditionalCookieAttribute {
        return AdditionalCookieAttribute(_CookieAttribute.comment(value))
    }
Severity: Major
Found in Sources/Kitura/AdditionalCookieAttribute.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/AdditionalCookieAttribute.swift on lines 40..42
Sources/Kitura/AdditionalCookieAttribute.swift on lines 50..52
Sources/Kitura/AdditionalCookieAttribute.swift on lines 65..67

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

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

    public static func commentURL(_ value: String?) -> AdditionalCookieAttribute {
        return AdditionalCookieAttribute(_CookieAttribute.commentURL(value))
    }
Severity: Major
Found in Sources/Kitura/AdditionalCookieAttribute.swift and 3 other locations - About 30 mins to fix
Sources/Kitura/AdditionalCookieAttribute.swift on lines 35..37
Sources/Kitura/AdditionalCookieAttribute.swift on lines 50..52
Sources/Kitura/AdditionalCookieAttribute.swift on lines 65..67

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

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

    @discardableResult
    public func error(_ handler: [RouterHandler]) -> Router {
        return routingHelper(.error, pattern: nil, handler: handler)
    }
Severity: Minor
Found in Sources/Kitura/RouterHTTPVerbs+Error.swift and 1 other location - About 30 mins to fix
Sources/Kitura/RouterHTTPVerbs+Error.swift on lines 57..60

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

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

    @discardableResult
    public func error(_ middleware: [RouterMiddleware]) -> Router {
        return routingHelper(.error, pattern: nil, middleware: middleware)
    }
Severity: Minor
Found in Sources/Kitura/RouterHTTPVerbs+Error.swift and 1 other location - About 30 mins to fix
Sources/Kitura/RouterHTTPVerbs+Error.swift on lines 37..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 40.

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

    func testRouteFunc() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/route", 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/TestResponse.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 testSimpleCustomMatches has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func testSimpleCustomMatches() {
        var router = Router()

        router.all("/:id(\\d+)", handler: handler)

Severity: Minor
Found in Tests/KituraTests/TestRouteRegex.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 testRouteWithPercentEncoding has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func testRouteWithPercentEncoding() {
        let router = Router()
        router.get("/say hello", handler: makeHandler(helloworld + " with whitespace"))
        router.get("/say%20hello", handler: makeHandler(helloworld + " with %20"))
        router.get("/say+hello", handler: makeHandler(helloworld + " with +"))
Severity: Minor
Found in Tests/KituraTests/TestRouteRegex.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 testRawDataPost has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func testRawDataPost() {
        performServerTest(router) { expectation in
            self.performRequest("post",
                                path: "/bodytest",
                                callback: { response in
Severity: Minor
Found in Tests/KituraTests/TestResponse.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

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

    func testStaticFileServerRedirectPreservingQueryParams() {
        performServerTest(router) { expectation in
            self.performRequest("get", path: "/queryparams?a=b&c=d", followRedirects: false, callback: { response in
                defer {
                    expectation.fulfill()
Severity: Minor
Found in Tests/KituraTests/TestStaticFileServer.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 runTestParameters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private func runTestParameters(pathParameter: String, queryParameter: String,
                                   expectedReturnedPathParameter: String? = nil,
                                   expectedReturnedQueryParameter: String? = nil) {
        let expectedReturnedPathParameter = expectedReturnedPathParameter ?? pathParameter
        let expectedReturnedQueryParameter = expectedReturnedQueryParameter ?? queryParameter
Severity: Minor
Found in Tests/KituraTests/TestResponse.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 hasData has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func hasData<T: Decodable & Equatable>(_ expected: [[String : T]], customDecoder: @escaping () -> BodyDecoder) -> Self {
        return has { response in
            guard let (_, data) = self.readDataOrFail(from: response) else { return }
            do {
                let actual = try customDecoder().decode([[String : T]].self, from: data)
Severity: Minor
Found in Tests/KituraTests/KituraTestBuilder.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 testConnectionRejection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func testConnectionRejection() {
        let numClients = 5  // Number of clients to connect
        let maxClients = 2  // Maximum number of concurrent clients

        // Create client status objects and expectations
Severity: Minor
Found in Tests/KituraTests/TestServerOptions.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 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

Severity
Category
Status
Source
Language