IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

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(T.self, request: request, response: response) { typeSafeMiddleware in
                guard let typeSafeMiddleware = typeSafeMiddleware 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 518..536
Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 666..682

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

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(T.self, request: request, response: response) { typeSafeMiddleware 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 666..682
Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1194..1210

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

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(appendId(path: route)) { request, response, next in
            Log.verbose("Received GET (singular with identifier and middleware) type-safe request")
            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 {
                    return next()
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 1150..1161

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

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

    func testJsonp() {
        performServerTest(router) { expectation in
            self.performRequest("get", path: "/jsonp?callback=testfn", callback: { response in
                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
Severity: Major
Found in Tests/KituraTests/TestResponse.swift - About 2 hrs to fix

    File KituraTestBuilder.swift has 260 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

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

          func testCustomCoder() {
              struct SimpleQuery: QueryParams {
                  let string: String
              }
              let jsonEncoder: () -> BodyEncoder = {
      Severity: Major
      Found in Tests/KituraTests/TestTypeSafeMiddleware.swift - About 2 hrs to fix

        File Router.swift has 260 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import KituraNet
        import LoggerAPI
        import Foundation
        import KituraTemplateEngine
        import KituraContracts
        Severity: Minor
        Found in Sources/Kitura/Router.swift - About 2 hrs to fix

          Identical blocks of code found in 6 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/TestRouteRegex.swift and 5 other locations - About 2 hrs to fix
          Tests/KituraTests/TestRouteRegex.swift on lines 1..1069
          Tests/KituraTests/TestRouteRegex.swift on lines 1..1069
          Tests/KituraTests/TestRouteRegex.swift on lines 1..1069
          Tests/KituraTests/TestRouteRegex.swift on lines 1..1069
          Tests/KituraTests/TestRouteRegex.swift on lines 1..1069

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

          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:"/format", callback: {response in
                          XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                          XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                          XCTAssertEqual(response?.headers["Content-Type"]?.first, "text/html")
          Severity: Major
          Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
          Tests/KituraTests/TestResponse.swift on lines 809..822

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

          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:"/format", callback: {response in
                          XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                          XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                          XCTAssertEqual(response?.headers["Content-Type"]?.first, "text/plain")
          Severity: Major
          Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
          Tests/KituraTests/TestResponse.swift on lines 794..807

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

          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 parse has 53 lines of code (exceeds 25 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: Major
          Found in Sources/Kitura/staticFileServer/RangeHeader.swift - About 2 hrs to fix

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

                func testPostRequest() {
                    performServerTest(router) { expectation in
                        self.performRequest("post", path: "/bodytest", callback: {response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            //XCTAssertEqual(response?.method, "POST", "The request wasn't recognized as a post")
            Severity: Major
            Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
            Tests/KituraTests/TestResponse.swift on lines 294..312

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

            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

                    performServerTest(router) { expectation in
                        self.performRequest("get", path: "/jsonp_cb?cb=testfn", callback: { response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                            do {
            Severity: Major
            Found in Tests/KituraTests/TestResponse.swift and 2 other locations - About 2 hrs to fix
            Tests/KituraTests/TestResponse.swift on lines 868..883
            Tests/KituraTests/TestResponse.swift on lines 918..933

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

            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

                    performServerTest(router) { expectation in
                        self.performRequest("get", path: "/jsonp?callback=testfn", callback: { response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                            do {
            Severity: Major
            Found in Tests/KituraTests/TestResponse.swift and 2 other locations - About 2 hrs to fix
            Tests/KituraTests/TestResponse.swift on lines 901..916
            Tests/KituraTests/TestResponse.swift on lines 918..933

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

            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

                    performServerTest(router) { expectation in
                        self.performRequest("get", path: "/jsonp_encoded?callback=testfn", callback: { response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                            do {
            Severity: Major
            Found in Tests/KituraTests/TestResponse.swift and 2 other locations - About 2 hrs to fix
            Tests/KituraTests/TestResponse.swift on lines 868..883
            Tests/KituraTests/TestResponse.swift on lines 901..916

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

            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 testPostRequestWithDoubleBodyParser() {
                    performServerTest(router) { expectation in
                        self.performRequest("post", path: "/doublebodytest", callback: {response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            //XCTAssertEqual(response?.method, "POST", "The request wasn't recognized as a post")
            Severity: Major
            Found in Tests/KituraTests/TestResponse.swift and 1 other location - About 2 hrs to fix
            Tests/KituraTests/TestResponse.swift on lines 220..238

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

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

                public static func constructIdentOutResultHandler<IdType: Identifier, OutputType: Codable>(successStatus: HTTPStatusCode = .OK, response: RouterResponse, completion: @escaping () -> Void) -> IdentifierCodableResultClosure<IdType, OutputType> {
                    return { id, codableOutput, error in
                        var status = successStatus
                        if let error = error {
                            status = httpStatusCode(from: error)
            Severity: Minor
            Found in Sources/Kitura/CodableRouter.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 initialize has 52 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        initialize: function initialize(o, datasets) {
                            var www;
                            datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
                            o = o || {};
                            www = WWW(o.classNames);

              Function initialize has 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                          initialize: function initialize(o, datasets) {
                              var www;
                              datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
                              o = o || {};
                              www = WWW(o.classNames);
              Severity: Major
              Found in docs/js/typeahead.jquery.js - 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 Query Parameters")
                            Log.verbose("Query Parameters: \(request.queryParameters)")
                            do {
                                var query: Q? = nil
                Severity: Major
                Found in Sources/Kitura/CodableRouter.swift and 2 other locations - About 2 hrs to fix
                Sources/Kitura/CodableRouter.swift on lines 515..531
                Sources/Kitura/CodableRouter.swift on lines 597..612

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

                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