zhuhaow/NEKit

View on GitHub
src/IPStack/UDPDirectStack.swift

Summary

Maintainability
A
1 hr
Test Coverage

Function findSocket has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    fileprivate func findSocket(connectInfo: ConnectInfo?, socket: NWUDPSocket?) -> (ConnectInfo, NWUDPSocket)? {
        var result: (ConnectInfo, NWUDPSocket)?

        queue.sync {
            if connectInfo != nil {
Severity: Minor
Found in src/IPStack/UDPDirectStack.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

Avoid too many return statements within this function.
Open

                return socket === sock
Severity: Major
Found in src/IPStack/UDPDirectStack.swift - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return result
    Severity: Major
    Found in src/IPStack/UDPDirectStack.swift - About 30 mins to fix

      Force casts should be avoided
      Open

              let payload = (packet.protocolParser as! UDPProtocolParser).payload
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      forced-type-cast

      Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

      Preferred

      if let movie = item as? Movie {
          print("Movie: '\(movie.name)', dir. \(movie.director)")
      }

      Not Preferred

      let movie = item as! Movie
      print("Movie: '\(movie.name)', dir. \(movie.director)")

      Force casts should be avoided
      Open

              let udpParser = packet.protocolParser as! UDPProtocolParser
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      forced-type-cast

      Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

      Preferred

      if let movie = item as? Movie {
          print("Movie: '\(movie.name)', dir. \(movie.director)")
      }

      Not Preferred

      let movie = item as! Movie
      print("Movie: '\(movie.name)', dir. \(movie.director)")

      Line should not have any trailing whitespace
      Open

          
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      trailing-whitespace

      Flag whitespace after the last non-whitespace character on each line until the newline.

      Preferred

      let number = 42¬

      Not Preferred

      let number = 42••¬

      Line should not have any trailing whitespace
      Open

              
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      trailing-whitespace

      Flag whitespace after the last non-whitespace character on each line until the newline.

      Preferred

      let number = 42¬

      Not Preferred

      let number = 42••¬

      Line should not have any trailing whitespace
      Open

          
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      trailing-whitespace

      Flag whitespace after the last non-whitespace character on each line until the newline.

      Preferred

      let number = 42¬

      Not Preferred

      let number = 42••¬

      Function should have at least one blank line after it
      Open

          }
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      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
      }

      Line should not have any trailing whitespace
      Open

          
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      trailing-whitespace

      Flag whitespace after the last non-whitespace character on each line until the newline.

      Preferred

      let number = 42¬

      Not Preferred

      let number = 42••¬

      Line should not have any trailing whitespace
      Open

              
      Severity: Minor
      Found in src/IPStack/UDPDirectStack.swift by tailor

      trailing-whitespace

      Flag whitespace after the last non-whitespace character on each line until the newline.

      Preferred

      let number = 42¬

      Not Preferred

      let number = 42••¬

      There are no issues that match your filters.

      Category
      Status