zhuhaow/NEKit

View on GitHub
src/Utils/IPMask.swift

Summary

Maintainability
B
5 hrs
Test Coverage

Function mask has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    func mask(baseIP: IPAddress) -> (IPAddress, IPAddress)? {
        switch (self, baseIP.address) {
        case (.IPv4(var m), .IPv4(let addr)):
            guard m <= 32 else {
                return nil
Severity: Minor
Found in src/Utils/IPMask.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 mask has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    func mask(baseIP: IPAddress) -> (IPAddress, IPAddress)? {
        switch (self, baseIP.address) {
        case (.IPv4(var m), .IPv4(let addr)):
            guard m <= 32 else {
                return nil
Severity: Minor
Found in src/Utils/IPMask.swift - About 1 hr to fix

    Avoid too many return statements within this function.
    Open

                return (b, e)
    Severity: Major
    Found in src/Utils/IPMask.swift - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return nil
      Severity: Major
      Found in src/Utils/IPMask.swift - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return (baseIP, baseIP)
        Severity: Major
        Found in src/Utils/IPMask.swift - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return (IPAddress(ipv6InNetworkOrder: 0), IPAddress(ipv6InNetworkOrder: UInt128.max))
          Severity: Major
          Found in src/Utils/IPMask.swift - About 30 mins to fix

            Function should have at least one blank line after it
            Open

                }
            Severity: Minor
            Found in src/Utils/IPMask.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
            }

            There are no issues that match your filters.

            Category
            Status