zhuhaow/NEKit

View on GitHub
src/Config/AdapterFactoryParser.swift

Summary

Maintainability
C
1 day
Test Coverage

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

    static func parseShadowsocksAdapterFactory(_ config: Yaml) throws -> ShadowsocksAdapterFactory {
        guard let host = config["host"].string else {
            throw ConfigurationParserError.adapterParsingError(errorInfo: "Host (host) is required.")
        }

Severity: Minor
Found in src/Config/AdapterFactoryParser.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 parseShadowsocksAdapterFactory has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static func parseShadowsocksAdapterFactory(_ config: Yaml) throws -> ShadowsocksAdapterFactory {
        guard let host = config["host"].string else {
            throw ConfigurationParserError.adapterParsingError(errorInfo: "Host (host) is required.")
        }

Severity: Major
Found in src/Config/AdapterFactoryParser.swift - About 2 hrs to fix

    Function parseServerAdapterFactory has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        static func parseServerAdapterFactory(_ config: Yaml, type: HTTPAuthenticationAdapterFactory.Type) throws -> ServerAdapterFactory {
            guard let host = config["host"].string else {
                throw ConfigurationParserError.adapterParsingError(errorInfo: "Host (host) is required.")
            }
    
    
    Severity: Minor
    Found in src/Config/AdapterFactoryParser.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 parseAdapterFactoryManager has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static func parseAdapterFactoryManager(_ config: Yaml) throws -> AdapterFactoryManager {
            var factoryDict: [String: AdapterFactory] = [:]
            factoryDict["direct"] = DirectAdapterFactory()
            guard let adapterConfigs = config.array else {
                throw ConfigurationParserError.noAdapterDefined
    Severity: Minor
    Found in src/Config/AdapterFactoryParser.swift - About 1 hr to fix

      Function parseSpeedAdapterFactory has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          static func parseSpeedAdapterFactory(_ config: Yaml, factoryDict: [String:AdapterFactory]) throws -> SpeedAdapterFactory {
              var factories: [(AdapterFactory, Int)] = []
              guard let adapters = config["adapters"].array else {
                  throw ConfigurationParserError.adapterParsingError(errorInfo: "Speed Adatper should specify a set of adapters (adapters).")
              }
      Severity: Minor
      Found in src/Config/AdapterFactoryParser.swift - About 45 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 parseAdapterFactoryManager has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          static func parseAdapterFactoryManager(_ config: Yaml) throws -> AdapterFactoryManager {
              var factoryDict: [String: AdapterFactory] = [:]
              factoryDict["direct"] = DirectAdapterFactory()
              guard let adapterConfigs = config.array else {
                  throw ConfigurationParserError.noAdapterDefined
      Severity: Minor
      Found in src/Config/AdapterFactoryParser.swift - About 25 mins to fix

      Cognitive Complexity

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

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

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

      Further reading

      Function should have at least one blank line before it
      Open

          static func parseAdapterFactoryManager(_ config: Yaml) throws -> AdapterFactoryManager {

      function-whitespace

      Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

      Preferred

      func function1() {
        var text = 1
        var text = 2
      }
      
      function1()
      
      // a comment
      func function2() {
        // something goes here
      }
      
      struct SomeStruct {
      
        func function3() {
          // something goes here
        }
      
        func function4() {
          // something else goes here
        };
      
      }
      
      func function5() {
        // something goes here
      }

      Not Preferred

      func function1() {
        var text = 1
        var text = 2
      }
      function1()
      // a comment
      func function2() {
        // something goes here
      }
      
      struct SomeStruct {
        func function3() {
          // something goes here
        }
      
        func function4() {
          // something else goes here
        };
      }
      func function5() {
        // something goes here
      }

      Colon at column 78 should have exactly one space after it
      Open

          static func parseSpeedAdapterFactory(_ config: Yaml, factoryDict: [String:AdapterFactory]) throws -> SpeedAdapterFactory {

      colon-whitespace

      There should be no whitespace preceding the colon, exactly one whitespace after the colon for: * var, class, struct, protocol, extension, func, and tuple declarations * dict literals and types * case statements

      However, for conditional expressions there should be a single whitespace before and after the colon.

      Variable declarations

      Preferred

      var x: Int = 2

      Not Preferred

      var x : Int
      var y:   String

      Dictionary literals and types

      Preferred

      var x = [ 'key1': 1, 'key2': 2 ]
      var y: [ Int: String ]

      Not Preferred

      var x = [ 'key1' : 1, 'key2':  3]
      var y: [ Int :    String ]

      Case statements

      Preferred

      switch character {
      case "a": doSomething(a);
      default: alert();
      }

      Not Preferred

      switch character {
      case "a" : doSomething(a);
      default:     alert();
      }

      Class, Struct, Protocol, and Extension declarations

      Preferred

      class ClassName: BaseClass {
      }
      
      struct StructName: BaseStruct {
      }
      
      protocol ProtocolName: AnotherProtocol {
      }
      
      extension TypeName: ProtocolName {
      }

      Not Preferred

      class ClassName : BaseClass {
      }
      
      struct StructName:  BaseStruct {
      }
      
      protocol ProtocolName:AnotherProtocol {
      }
      
      extension TypeName : ProtocolName {
      }

      Tuple declarations

      Preferred

      var y = (key: 1, value: 2)

      Not Preferred

      var y = (key:1, value : 2)

      Function declarations

      Preferred

      func someFunction<t: someclass u: someprotocol>(someT: T, someU: U) {
      }</t:>

      Not Preferred

      func someFunction<t : someclass u:someprotocol>(someT: T, someU: U) {
      }</t>

      Conditional expressions

      Preferred

      var x = condition ? a : b

      Not Preferred

      var x = condition ? a: b
      var x = condition ? a   : b

      Function should have at least one blank line after it
      Open

          }

      function-whitespace

      Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

      Preferred

      func function1() {
        var text = 1
        var text = 2
      }
      
      function1()
      
      // a comment
      func function2() {
        // something goes here
      }
      
      struct SomeStruct {
      
        func function3() {
          // something goes here
        }
      
        func function4() {
          // something else goes here
        };
      
      }
      
      func function5() {
        // something goes here
      }

      Not Preferred

      func function1() {
        var text = 1
        var text = 2
      }
      function1()
      // a comment
      func function2() {
        // something goes here
      }
      
      struct SomeStruct {
        func function3() {
          // something goes here
        }
      
        func function4() {
          // something else goes here
        };
      }
      func function5() {
        // something goes here
      }

      There are no issues that match your filters.

      Category
      Status