aequitas/macos-menubar-wireguard

View on GitHub

Showing 51 of 51 total issues

Function parse has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

  internal func parse(line: String) throws -> ContentType? {
    var cache = ""
    var state = State.Variable
    let stack = Stack<State>()

Severity: Minor
Found in WireGuardStatusbar/INIParser.swift - About 7 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 parse has 76 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  internal func parse(line: String) throws -> ContentType? {
    var cache = ""
    var state = State.Variable
    let stack = Stack<State>()

Severity: Major
Found in WireGuardStatusbar/INIParser.swift - About 3 hrs to fix

    Function buildMenu has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    func buildMenu(tunnels: Tunnels,
                   allTunnelDetails: Bool = false,
                   connectedTunnelDetails: Bool = true,
                   showInstallInstructions _: Bool = false) -> [NSMenuItem] {
        guard !tunnels.isEmpty else {
    Severity: Minor
    Found in WireGuardStatusbar/Menu.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 buildMenu has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    func buildMenu(tunnels: Tunnels,
                   allTunnelDetails: Bool = false,
                   connectedTunnelDetails: Bool = true,
                   showInstallInstructions _: Bool = false) -> [NSMenuItem] {
        guard !tunnels.isEmpty else {
    Severity: Minor
    Found in WireGuardStatusbar/Menu.swift - About 1 hr to fix

      Function addPathToQueue has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private func addPathToQueue(_ path: String, notifyingAbout notification: SKQueueNotification) -> SKQueuePath? {
          var pathEntry = watchedPaths[path]
      
          if pathEntry != nil {
            if pathEntry!.notification.contains(notification) {
      Severity: Minor
      Found in WireGuardStatusbarHelper/SKQueue.swift - About 1 hr to fix

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

            func tunnelNames() -> [String] {
                var tunnelNames = [String]()
        
                // get names of all tunnel configurations
                for configPath in configPaths {
        Severity: Minor
        Found in WireGuardStatusbarHelper/WireGuard.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

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

        // TODO: figure out how to get this using package manager (Cocoapods/SwiftPM,Carthage)
        // or get rid of config file parsing altogether?
        
        //
        //  INIParser.swift
        Severity: Major
        Found in WireGuardStatusbar/INIParser.swift and 1 other location - About 1 hr to fix
        WireGuardStatusbar/INIParser.swift on lines 1..181

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

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

            func installOrUpdateHelper(onFailure: @escaping (String?) -> Void, onSuccess: @escaping () -> Void) {
                helperStatus { installed in
                    if !installed {
                        // Invalidate the connection to force a reconnect to the newly installed helper
                        self.xpcHelperConnection?.invalidate()
        Severity: Minor
        Found in WireGuardStatusbar/HelperXPC.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 deeply nested control flow statements.
        Open

                    if var sec = _sections[currentTitle] {
                      sec[variable] = value
                      _sections[currentTitle] = sec
                    } else {
                      var sec: [String: String] = [:]
        Severity: Major
        Found in WireGuardStatusbar/INIParser.swift - About 45 mins to fix

          Function ev_create has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func ev_create(ident: UInt, filter: Int16, flags: UInt16, fflags: UInt32, data: Int, udata: UnsafeMutableRawPointer) -> kevent {
          Severity: Minor
          Found in WireGuardStatusbarHelper/SKQueue.swift - About 45 mins to fix

            Function toStrings has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              public func toStrings() -> [SKQueueNotificationString] {
                var s = [SKQueueNotificationString]()
                if contains(.Rename) { s.append(.Rename) }
                if contains(.Write) { s.append(.Write) }
                if contains(.Delete) { s.append(.Delete) }
            Severity: Minor
            Found in WireGuardStatusbarHelper/SKQueue.swift - About 35 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 addPathToQueue has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              private func addPathToQueue(_ path: String, notifyingAbout notification: SKQueueNotification) -> SKQueuePath? {
                var pathEntry = watchedPaths[path]
            
                if pathEntry != nil {
                  if pathEntry!.notification.contains(notification) {
            Severity: Minor
            Found in WireGuardStatusbarHelper/SKQueue.swift - About 35 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

                    let xpcService = privilegedHelper?.helperConnection()?.remoteObjectProxyWithErrorHandler { error -> Void in
                        NSLog("XPCService error: \(error)")
                        return
                    } as? HelperProtocol
            Severity: Minor
            Found in WireGuardStatusbar/AppDelegate.swift and 1 other location - About 35 mins to fix
            WireGuardStatusbar/AppDelegate.swift on lines 105..108

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

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

                func registerWireGuardStateWatch() {
                    // register watchers to respond to changes in wireguard config/runtime state
                    // will trigger: receivedNotification
                    if queue == nil {
                        queue = SKQueue(delegate: self)!
            Severity: Minor
            Found in WireGuardStatusbarHelper/Helper.swift - About 35 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

                    let xpcService = privilegedHelper?.helperConnection()?.remoteObjectProxyWithErrorHandler { error -> Void in
                        NSLog("XPCService error: \(error)")
                        return
                    } as? HelperProtocol
            Severity: Minor
            Found in WireGuardStatusbar/AppDelegate.swift and 1 other location - About 35 mins to fix
            WireGuardStatusbar/AppDelegate.swift on lines 117..120

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

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

                func listener(_: NSXPCListener, shouldAcceptNewConnection connection: NSXPCConnection) -> Bool {
                    NSLog("Client connected")
                    onConnect()
            
                    // Set the protocol that the calling application conforms to.
            Severity: Minor
            Found in WireGuardStatusbarHelper/AppXPC.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

            Enum case names should be lowerCamelCase
            Open

                case Title, Variable, Value, SingleQuotation, DoubleQuotation
            Severity: Minor
            Found in WireGuardStatusbar/INIParser.swift by tailor

            lower-camel-case

            method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

            Method and selector names

            Preferred

            func someMethod() {
                // method definition goes here
            }

            Not Preferred

            func some-method() {
                // method definition goes here
            }

            Variable names

            Preferred

            var someVariable = someValue

            Not Preferred

            var Some_Var1able = someValue

            Enum case names should be lowerCamelCase
            Open

              case AttributeChange

            lower-camel-case

            method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

            Method and selector names

            Preferred

            func someMethod() {
                // method definition goes here
            }

            Not Preferred

            func some-method() {
                // method definition goes here
            }

            Variable names

            Preferred

            var someVariable = someValue

            Not Preferred

            var Some_Var1able = someValue

            Enum case names should be lowerCamelCase
            Open

              case SizeIncrease

            lower-camel-case

            method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

            Method and selector names

            Preferred

            func someMethod() {
                // method definition goes here
            }

            Not Preferred

            func some-method() {
                // method definition goes here
            }

            Variable names

            Preferred

            var someVariable = someValue

            Not Preferred

            var Some_Var1able = someValue

            Enum case names should be lowerCamelCase
            Open

                case Title, Variable, Value, SingleQuotation, DoubleQuotation
            Severity: Minor
            Found in WireGuardStatusbar/INIParser.swift by tailor

            lower-camel-case

            method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

            Method and selector names

            Preferred

            func someMethod() {
                // method definition goes here
            }

            Not Preferred

            func some-method() {
                // method definition goes here
            }

            Variable names

            Preferred

            var someVariable = someValue

            Not Preferred

            var Some_Var1able = someValue
            Severity
            Category
            Status
            Source
            Language