IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

File TestRouterHTTPVerbs_generated.swift has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import XCTest
import Foundation

@testable import Kitura
@testable import KituraNet
Severity: Minor
Found in Tests/KituraTests/TestRouterHTTPVerbs_generated.swift - About 3 hrs to fix

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

    function openCurrentItemIfClosed() {
      if (window.jazzy.docset) {
        return;
      }
      var $link = $(`a[name="${location.hash.substring(1)}"]`).nextAll('.token');
    Severity: Major
    Found in docs/js/jazzy.js and 1 other location - About 3 hrs to fix
    docs/docsets/Kitura.docset/Contents/Resources/Documents/js/jazzy.js on lines 22..31

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

    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

    function openCurrentItemIfClosed() {
      if (window.jazzy.docset) {
        return;
      }
      var $link = $(`a[name="${location.hash.substring(1)}"]`).nextAll('.token');
    docs/js/jazzy.js on lines 22..31

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

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

      File KituraTest.swift has 299 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import XCTest
      import Kitura
      
      @testable import KituraNet
      
      
      Severity: Minor
      Found in Tests/KituraTests/KituraTest.swift - About 3 hrs to fix

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

            func testSingleMiddlewarePatch() {
                let user = User(id: 1, name: "NewUser")
        
                router.patch("/userMiddleware") { (middleware: UserMiddleware, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
                    print("PATCH on /userMiddleware for user \(user) - received header \(middleware.header)")
        Severity: Major
        Found in Tests/KituraTests/TestTypeSafeMiddleware.swift and 1 other location - About 3 hrs to fix
        Tests/KituraTests/TestTypeSafeMiddleware.swift on lines 891..911

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

        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

                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 1 other location - About 3 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1442..1462

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

        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

            fileprivate func patchSafely<Id: Identifier, I: Codable, O: Codable>(_ route: String, handler: @escaping IdentifierCodableClosure<Id, I, O>) {
                if !pathSyntaxIsValid(route, identifierExpected: true) {
                    return
                }
                registerPatchRoute(route: route, id: Id.self, inputType: I.self, outputType: O.self)
        Severity: Major
        Found in Sources/Kitura/CodableRouter.swift and 1 other location - About 3 hrs to fix
        Sources/Kitura/CodableRouter.swift on lines 385..400

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

        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 testSingleMiddlewarePut() {
                let user = User(id: 1, name: "NewUser")
        
                router.put("/userMiddleware") { (middleware: UserMiddleware, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
                    print("PUT on /userMiddleware for user \(user) - received header \(middleware.header)")
        Severity: Major
        Found in Tests/KituraTests/TestTypeSafeMiddleware.swift and 1 other location - About 3 hrs to fix
        Tests/KituraTests/TestTypeSafeMiddleware.swift on lines 946..966

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

        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

            fileprivate func putSafely<Id: Identifier, I: Codable, O: Codable>(_ route: String, handler: @escaping IdentifierCodableClosure<Id, I, O>) {
                if !pathSyntaxIsValid(route, identifierExpected: true) {
                    return
                }
                registerPutRoute(route: route, id: Id.self, inputType: I.self, outputType: O.self)
        Severity: Major
        Found in Sources/Kitura/CodableRouter.swift and 1 other location - About 3 hrs to fix
        Sources/Kitura/CodableRouter.swift on lines 403..418

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

        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(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 1 other location - About 3 hrs to fix
        Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 915..935

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

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

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

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function testSimpleMatches has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func testSimpleMatches() {
                var router = Router()
        
                router.all("/test", handler: handler)
        
        
        Severity: Major
        Found in Tests/KituraTests/TestRouteRegex.swift - About 3 hrs to fix

          TestTemplateEngine has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          final class TestTemplateEngine: KituraTest, KituraTestSuite {
          
              static var allTests: [(String, (TestTemplateEngine) -> () throws -> Void)] {
                  return [
                      ("testEmptyTemplateName", testEmptyTemplateName),
          Severity: Minor
          Found in Tests/KituraTests/TestTemplateEngine.swift - About 3 hrs to fix

            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(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 1 other location - About 2 hrs to fix
            Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 817..837

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

            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

                    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 1 other location - About 2 hrs to fix
            Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1345..1365

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

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

                func testQueryParameters() {
                    // Set up router for this test
                    let router = Router()
            
                    struct Params: QueryParams {
            Severity: Major
            Found in Tests/KituraTests/TestRequests.swift - About 2 hrs to fix

              Function testSend has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
              Open

                  func testSend() {
                      performServerTest(router) { expectation in
                          self.performRequest("get", path: "/data", 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 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 testCookieFromServer has 69 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

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

                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

                Severity
                Category
                Status
                Source
                Language