JohnCoates/Aerial

View on GitHub
Aerial/Source/Models/Time/TimeManagement.swift

Summary

Maintainability
D
2 days
Test Coverage

Function shouldRestrictPlaybackToDayNightVideo has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    func shouldRestrictPlaybackToDayNightVideo() -> (Bool, String) {
        debugLog("PrefsTime : \(PrefsTime.timeMode)")
        // We override everything on dark mode if we need to
        if PrefsTime.darkModeNightOverride && DarkMode.isEnabled() {
            debugLog("Dark Mode override")
Severity: Minor
Found in Aerial/Source/Models/Time/TimeManagement.swift - About 3 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

File TimeManagement.swift has 252 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Foundation
import Cocoa
import CoreLocation
import IOKit.ps

Severity: Minor
Found in Aerial/Source/Models/Time/TimeManagement.swift - About 2 hrs to fix

    Function shouldRestrictPlaybackToDayNightVideo has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func shouldRestrictPlaybackToDayNightVideo() -> (Bool, String) {
            debugLog("PrefsTime : \(PrefsTime.timeMode)")
            // We override everything on dark mode if we need to
            if PrefsTime.darkModeNightOverride && DarkMode.isEnabled() {
                debugLog("Dark Mode override")
    Severity: Major
    Found in Aerial/Source/Models/Time/TimeManagement.swift - About 2 hrs to fix

      Function getCurrentSleepTime has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func getCurrentSleepTime() -> Int {
              // pmset -g | grep "^[ ]*sleep" | awk '{ print $2 }'
      
              let pipe1 = Pipe()
              let pmset = Process()
      Severity: Minor
      Found in Aerial/Source/Models/Time/TimeManagement.swift - About 1 hr to fix

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

            public func getSunriseSunset() -> (Date?, Date?) {
                switch PrefsTime.timeMode {
                case .disabled:
                    return (nil, nil)
                case .nightShift:
        Severity: Minor
        Found in Aerial/Source/Models/Time/TimeManagement.swift - About 1 hr to fix

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

              private func dayNightCheck(sunrise: Date, sunset: Date) -> String {
                  var nsunrise = sunrise
                  var nsunset = sunset
                  let now = Date()
                  // When used with manual mode, sunrise and sunset will always be set to 2000-01-01
          Severity: Minor
          Found in Aerial/Source/Models/Time/TimeManagement.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 getSunriseSunset has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public func getSunriseSunset() -> (Date?, Date?) {
                  switch PrefsTime.timeMode {
                  case .disabled:
                      return (nil, nil)
                  case .nightShift:
          Severity: Minor
          Found in Aerial/Source/Models/Time/TimeManagement.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 calculateFrom has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              private func calculateFrom(latitude: Double, longitude: Double) -> (Bool, String) {
                  solar = Solar.init(coordinate: CLLocationCoordinate2D(
                      latitude: latitude,
                      longitude: longitude))
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Time/TimeManagement.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

          Avoid too many return statements within this function.
          Open

                          return (true, solar!.getTimeSlice())
          Severity: Major
          Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return(false, "")
            Severity: Major
            Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return (true, dayNightCheck(sunrise: dateSunrise, sunset: dateSunset))
              Severity: Major
              Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return(false, "")
                Severity: Major
                Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return (solar?.astronomicalSunrise, solar?.astronomicalSunset)
                  Severity: Major
                  Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return(nil, nil)
                    Severity: Major
                    Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return (false, "")
                      Severity: Major
                      Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return (true, dayNightCheck(sunrise: sunrise!, sunset: sunset!))
                        Severity: Major
                        Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return (false, "")
                          Severity: Major
                          Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return (false, "")
                            Severity: Major
                            Found in Aerial/Source/Models/Time/TimeManagement.swift - About 30 mins to fix

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

                                  func getCurrentSleepTime() -> Int {
                                      // pmset -g | grep "^[ ]*sleep" | awk '{ print $2 }'
                              
                                      let pipe1 = Pipe()
                                      let pmset = Process()
                              Severity: Minor
                              Found in Aerial/Source/Models/Time/TimeManagement.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

                              Multiline comment should end with whitespace
                              Open

                              }*/

                              comment-whitespace

                              Prefer at least one whitespace character after a comment opening symbol (//, ///, /*, or /**) and at least one whitespace character before a comment closing symbol (*/).

                              Preferred

                              // This is a comment
                              
                              /// This is a documentation comment
                              
                              /* This is a
                              multi-line comment */
                              
                              /* This is a
                              multi-line comment
                              */
                              
                              /** This is a
                              documentation multi-line
                              comment
                              */

                              Not Preferred

                              //This is a comment
                              
                              ///This is a documentation comment
                              
                              /*This is a
                              multi-line comment*/
                              
                              /**This is a multi-line
                              documentation comment */

                              Multiline comment should end with whitespace
                              Open

                                  }*/

                              comment-whitespace

                              Prefer at least one whitespace character after a comment opening symbol (//, ///, /*, or /**) and at least one whitespace character before a comment closing symbol (*/).

                              Preferred

                              // This is a comment
                              
                              /// This is a documentation comment
                              
                              /* This is a
                              multi-line comment */
                              
                              /* This is a
                              multi-line comment
                              */
                              
                              /** This is a
                              documentation multi-line
                              comment
                              */

                              Not Preferred

                              //This is a comment
                              
                              ///This is a documentation comment
                              
                              /*This is a
                              multi-line comment*/
                              
                              /**This is a multi-line
                              documentation comment */

                              There are no issues that match your filters.

                              Category
                              Status