IBM-Swift/Kitura

View on GitHub
Sources/Kitura/RouterResponse.swift

Summary

Maintainability
D
3 days
Test Coverage

File RouterResponse.swift has 433 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Function addCookie has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public func addCookie(name: String, value: String, domain: String, path: String, otherAttributes: [AdditionalCookieAttribute]? = nil ) {
            var cookieProperties = [HTTPCookiePropertyKey: Any]()
            cookieProperties[HTTPCookiePropertyKey.name] = name
            cookieProperties[HTTPCookiePropertyKey.value] = value
            cookieProperties[HTTPCookiePropertyKey.domain] = domain
    Severity: Minor
    Found in Sources/Kitura/RouterResponse.swift - About 4 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

      Function addCookie has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public func addCookie(name: String, value: String, domain: String, path: String, otherAttributes: [AdditionalCookieAttribute]? = nil ) {
              var cookieProperties = [HTTPCookiePropertyKey: Any]()
              cookieProperties[HTTPCookiePropertyKey.name] = name
              cookieProperties[HTTPCookiePropertyKey.value] = value
              cookieProperties[HTTPCookiePropertyKey.domain] = domain
      Severity: Minor
      Found in Sources/Kitura/RouterResponse.swift - About 1 hr to fix

        Function send has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public func send<T : Encodable>(jsonp: T, callbackParameter: String = "callback") throws -> RouterResponse {
                guard !state.invokedEnd else {
                    Log.warning("RouterResponse send(jsonp:) invoked after end() for \(self.request.urlURL)")
                    return self
                }
        Severity: Minor
        Found in Sources/Kitura/RouterResponse.swift - About 1 hr to fix

          Function send has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public func send<T : Encodable>(jsonp: T, callbackParameter: String = "callback") throws -> RouterResponse {
                  guard !state.invokedEnd else {
                      Log.warning("RouterResponse send(jsonp:) invoked after end() for \(self.request.urlURL)")
                      return self
                  }
          Severity: Minor
          Found in Sources/Kitura/RouterResponse.swift - About 1 hr 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 selectResponseEncoder has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              private func selectResponseEncoder(_ request: RouterRequest) -> (MediaType, BodyEncoder) {
                  let acceptHeader = request.headers["accept"]
                  if encoders.count == 1 ||
                      acceptHeader == nil ||
                      acceptHeader == "*" ||
          Severity: Minor
          Found in Sources/Kitura/RouterResponse.swift - About 55 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 addCookie has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public func addCookie(name: String, value: String, domain: String, path: String, otherAttributes: [AdditionalCookieAttribute]? = nil ) {
          Severity: Minor
          Found in Sources/Kitura/RouterResponse.swift - About 35 mins to fix

            Avoid too many return statements within this function.
            Open

                    return (bestMediaType, bestEncoder())
            Severity: Major
            Found in Sources/Kitura/RouterResponse.swift - About 30 mins to fix

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

                  public func end() throws {
                      guard !state.invokedEnd else {
                          Log.warning("RouterResponse end() invoked more than once for \(self.request.urlURL)")
                          return
                      }
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.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

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

                  @discardableResult
                  public func send(json: [Any]) -> RouterResponse {
                      guard !state.invokedEnd else {
                          Log.warning("RouterResponse send(json:) invoked after end() for \(self.request.urlURL)")
                          return self
              Severity: Major
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 1 hr to fix
              Sources/Kitura/RouterResponse.swift on lines 635..651

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

              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

                  @discardableResult
                  public func send(json: [String: Any]) -> RouterResponse {
                      guard !state.invokedEnd else {
                          Log.warning("RouterResponse send(json:) invoked after end() for \(self.request.urlURL)")
                          return self
              Severity: Major
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 1 hr to fix
              Sources/Kitura/RouterResponse.swift on lines 611..627

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

              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

                      if encoders.count == 1 ||
                          acceptHeader == nil ||
                          acceptHeader == "*" ||
                          acceptHeader == "*/*" {
                          if let defaultEncoder = encoders[defaultResponseMediaType] {
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 35 mins to fix
              Sources/Kitura/RouterResponse.swift on lines 322..331

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

              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

                      guard let bestAccepts = request.accepts(types: encoderAcceptsTypes),
                          let bestMediaType = MediaType(bestAccepts),
                          let bestEncoder = encoders[bestMediaType]
                          else {
                              if let defaultEncoder = encoders[defaultResponseMediaType] {
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 35 mins to fix
              Sources/Kitura/RouterResponse.swift on lines 311..320

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

              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

                  public func setWrittenDataFilter(_ newWrittenDataFilter: @escaping WrittenDataFilter) -> WrittenDataFilter {
                      let oldWrittenDataFilter = lifecycle.writtenDataFilter
                      lifecycle.writtenDataFilter = newWrittenDataFilter
                      return oldWrittenDataFilter
                  }
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 30 mins to fix
              Sources/Kitura/RouterResponse.swift on lines 455..459

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

              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

                  public func setOnEndInvoked(_ newOnEndInvoked: @escaping LifecycleHandler) -> LifecycleHandler {
                      let oldOnEndInvoked = lifecycle.onEndInvoked
                      lifecycle.onEndInvoked = newOnEndInvoked
                      return oldOnEndInvoked
                  }
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift and 1 other location - About 30 mins to fix
              Sources/Kitura/RouterResponse.swift on lines 465..469

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

              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

              Parentheses content should not end with whitespace
              Open

                  public func addCookie(name: String, value: String, domain: String, path: String, otherAttributes: [AdditionalCookieAttribute]? = nil ) {
              Severity: Minor
              Found in Sources/Kitura/RouterResponse.swift by tailor

              There are no issues that match your filters.

              Category
              Status