IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

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

        performServerTest(router) { expectation in
            self.performRequest("get", path: "/subdomains", callback: { response in
                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                let hostHeader = response?.headers["Host"]?.first
Severity: Major
Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
Tests/KituraTests/TestResponse.swift on lines 952..965

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

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) { expectation in
            self.performRequest("get", path: "/subdomains", callback: { response in
                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                let hostHeader = response?.headers["Host"]?.first
Severity: Major
Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
Tests/KituraTests/TestResponse.swift on lines 967..980

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

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

    func testQueryParameters() {
        // Set up router for this test
        let router = Router()

        struct Params: QueryParams {
Severity: Minor
Found in Tests/KituraTests/TestRequests.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

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

/**
 * Copyright IBM Corporation 2016,2017
 *
 * 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/TestStaticFileServer.swift and 1 other location - About 2 hrs to fix
Tests/KituraTests/TestStaticFileServer.swift on lines 1..710

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

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

    func testFourthTypeVerbsAdded() {
            let router = Router()
            var verbsArray: [String] = []
            let bodyParser = BodyParser()
            verbsArray.append("ALL")
Severity: Major
Found in Tests/KituraTests/TestRouterHTTPVerbs_generated.swift - About 2 hrs to fix

    Function testThirdTypeVerbsAdded has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func testThirdTypeVerbsAdded() {
                let router = Router()
                var verbsArray: [String] = []
                let bodyParser = BodyParser()
                verbsArray.append("ALL")
    Severity: Major
    Found in Tests/KituraTests/TestRouterHTTPVerbs_generated.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

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

                get(route) { request, response, next in
                    Log.verbose("Received GET (plural) type-safe request with middleware and Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    self.handleMiddleware(T.self, request: request, response: response) { typeSafeMiddleware in
                        guard let typeSafeMiddleware = typeSafeMiddleware else {
        Severity: Major
        Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 1 other location - About 2 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1248..1268

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

        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

                delete(route) { request, response, next in
                    Log.verbose("Received DELETE type-safe request with middleware and Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    self.handleMiddleware(T.self, request: request, response: response) { typeSafeMiddleware in
                        guard let typeSafeMiddleware = typeSafeMiddleware else {
        Severity: Major
        Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 1 other location - About 2 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 719..739

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

        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

                get(route) { request, response, next in
                    Log.verbose("Received GET (singular) type-safe request with middleware and Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    // Define result handler
                    self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
        Severity: Major
        Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 867..883
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1393..1409

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

        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

                get(route) { request, response, next in
                    Log.verbose("Received GET (plural) type-safe request with middleware and Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                        guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
        Severity: Major
        Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 614..631
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1393..1409

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

        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

                delete(route) { request, response, next in
                    Log.verbose("Received DELETE type-safe request with middleware and Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                        guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
        Severity: Major
        Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 614..631
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 867..883

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

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

            func testFirstTypeVerbsAdded() {
                    let router = Router()
                    var verbsArray: [String] = []
                    verbsArray.append("ALL")
                    router.all("/bodytest", handler: self.bodyTestHandler)
        Severity: Major
        Found in Tests/KituraTests/TestRouterHTTPVerbs_generated.swift - About 2 hrs to fix

          Function testSecondTypeVerbsAdded has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              func testSecondTypeVerbsAdded() {
                      let router = Router()
                      var verbsArray: [String] = []
                      verbsArray.append("ALL")
                      router.all("/bodytest", handler: [self.bodyTestHandler, self.bodyTestHandler])
          Severity: Major
          Found in Tests/KituraTests/TestRouterHTTPVerbs_generated.swift - About 2 hrs to fix

            ServerTestBuilder has 24 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class ServerTestBuilder: RequestTestBuilder, AssertionTestBuilder {
                // An object to keep track of a request and store up a list of
                // assertions to be applied when the request is complete
                private class Request {
                    let test: KituraTest
            Severity: Minor
            Found in Tests/KituraTests/KituraTestBuilder.swift - About 2 hrs to fix

              Function parse has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  static func parse(size: UInt64, headerValue: String, shouldCombine: Bool = true) throws -> RangeHeader {
              
                      guard let index = headerValue.range(of: "=")?.lowerBound else {
                          // malformed
                          throw RangeHeader.Error.malformed
              Severity: Minor
              Found in Sources/Kitura/staticFileServer/RangeHeader.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 serveNonDirectoryFile has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                      private func serveNonDirectoryFile(_ filePath: String, response: RouterResponse) {
                          if  !isValidFilePath(filePath) {
                              return
                          }
              
              
              Severity: Minor
              Found in Sources/Kitura/staticFileServer/FileServer.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

              RouterResponse has 23 methods (exceeds 20 allowed). Consider refactoring.
              Open

              public class RouterResponse {
              
                  // MARK: Properties
                  
                  struct State {
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift - About 2 hrs to fix

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

                        get(route) { request, response, next in
                            Log.verbose("Received GET (plural) type-safe request with middleware and Query Parameters")
                            Log.verbose("Query Parameters: \(request.queryParameters)")
                            self.handleMiddleware(T1.self, T2.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2 in
                                guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2 else {
                Severity: Major
                Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
                Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 566..584
                Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1296..1312

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

                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

                        get(route) { request, response, next in
                            Log.verbose("Received GET (singular) type-safe request with middleware and Query Parameters")
                            Log.verbose("Query Parameters: \(request.queryParameters)")
                            // Define result handler
                            self.handleMiddleware(T1.self, T2.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2 in
                Severity: Major
                Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
                Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 769..785
                Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1296..1312

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

                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

                Severity
                Category
                Status
                Source
                Language