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")
- Read upRead up
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
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")
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()
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:
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
- Read upRead up
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:
- Read upRead up
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))
- Read upRead up
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())
Avoid too many return
statements within this function. Open
return(false, "")
Avoid too many return
statements within this function. Open
return (true, dayNightCheck(sunrise: dateSunrise, sunset: dateSunset))
Avoid too many return
statements within this function. Open
return(false, "")
Avoid too many return
statements within this function. Open
return (solar?.astronomicalSunrise, solar?.astronomicalSunset)
Avoid too many return
statements within this function. Open
return(nil, nil)
Avoid too many return
statements within this function. Open
return (false, "")
Avoid too many return
statements within this function. Open
return (true, dayNightCheck(sunrise: sunrise!, sunset: sunset!))
Avoid too many return
statements within this function. Open
return (false, "")
Avoid too many return
statements within this function. Open
return (false, "")
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()
- Read upRead up
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
}*/
- Read upRead up
- Exclude checks
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
}*/
- Read upRead up
- Exclude checks
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 */