Showing 92 of 122 total issues
Function tableView
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard let foodLog = foodLog else { return 0 }
var headerSize: CGFloat = 0
switch section {
- 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 searchForFoodItemWithKeyword
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
func searchForFoodItemWithKeyword(searchTerm: String, completion: @escaping (Error?) -> Void) {
var urlComponents = URLComponents(url: baseURL, resolvingAgainstBaseURL: true)
let appIdQueryItem = URLQueryItem(name: "app_id", value: appId)
let appKeyQueryItem = URLQueryItem(name: "app_key", value: appKey)
let searchTermQueryItem = URLQueryItem(name: "ingr", value: searchTerm)
Function searchForFoodItemWithUPC
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
func searchForFoodItemWithUPC(searchTerm: String, completion: @escaping (Error?) -> Void) {
var urlComponents = URLComponents(url: baseURL, resolvingAgainstBaseURL: true)
let appIdQueryItem = URLQueryItem(name: "app_id", value: appId)
let appKeyQueryItem = URLQueryItem(name: "app_key", value: appKey)
let searchTermQueryItem = URLQueryItem(name: "upc", value: searchTerm)
Function scene
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
QuoteController.shared.getRandomQuote { (_) in }
HealthKitController.shared.updateAllValues()
// This code runs upon app load to determine which view to present to user based on logged in state
- 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 searchBarSearchButtonClicked
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
guard let searchTerm = self.foodSearchBar.text else { return }
foodSearchBar.endEditing(true)
foodSearchBar.showsCancelButton = false
- 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 deleteFoodLogEntry
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
func deleteFoodLogEntry(entry: FoodLogEntry, completion: @escaping (Result<Bool, NetworkError>) -> Void) {
guard let token = getUserToken() else {
print("No token found for user")
DispatchQueue.main.async {
completion(.failure(.noAuth))
- 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 prepare
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ToGettingPersonal" {
guard let gpVC = segue.destination as? GettingPersonalViewController else { return }
gpVC.profileController = self.profileController
gpVC.modalPresentationStyle = .fullScreen
- 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 delayedSearch
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
@objc func delayedSearch() {
guard let searchText = searchDelayTimer.userInfo as? String, !searchText.isEmpty else { return }
searchDelayTimer.invalidate()
if foodSearchKeyword == searchText {
- 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 calculateCaloricDeficits
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private func calculateCaloricDeficits(with caloricBudget: Int) {
guard caloricBudget > 0, consumedCalories.allDataIsLoaded else { return }
let deficitDay1 = consumedCalories.day1Count == 0 ? 0 : caloricBudget - consumedCalories.day1Count
let deficitDay2 = consumedCalories.day2Count == 0 ? 0 : caloricBudget - consumedCalories.day2Count
- 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 deeply nested control flow statements. Open
if navVC.viewControllers.count > 1 {
navVC.popToRootViewController(animated: animated)
}
Avoid deeply nested control flow statements. Open
if navVC.viewControllers.count > 1 && navVC.viewControllers.last != tabBarController {
navVC.popToViewController(tabBarController, animated: true);
}
Function getCumulativeSamples
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func getCumulativeSamples(for quantityType: HKQuantityType, startDate: Date = Date(), endDate: Date = Date(), options: HKStatisticsOptions = [], completion: @escaping (HKStatistics?, Error?) -> Void) {
Function getMostRecentSamples
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func getMostRecentSamples(for sampleType: HKSampleType, withStart date: Date = Date.distantPast, limit: Int = 1, sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: true), completion: @escaping ([HKQuantitySample]?, Error?) -> Swift.Void) {
Function getLoginStreak
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
class func getLoginStreak() -> Int {
var currentLoginStreak = UserDefaults.standard.integer(forKey: Keys.dailyLoginStreak.rawValue)
if let differenceInDays = differenceInDays() {
switch differenceInDays {
- 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 point
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
open override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
var b = super.point(inside: point, with: event)
if !b {
for container in containers {
if container.point(inside: CGPoint.init(x: point.x - container.frame.origin.x, y: point.y - container.frame.origin.y), with: event) {
- 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 loginButtonTapped
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
@IBAction func loginButtonTapped(_ sender: Any) {
guard let email = self.emailTextField.text, !email.isEmpty,
let password = self.passwordTextField.text, !password.isEmpty else {
completeFieldsAlert()
return
- 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 getRandomQuote
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
func getRandomQuote(completion: @escaping (Result<Quote, NetworkError>) -> Void) {
var urlComponets = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)
urlComponets?.queryItems = [
URLQueryItem(name: "maxLength", value: "102"),
- 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 reauthorizeUser
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private func reauthorizeUser() {
let alertController = UIAlertController(title: "Session Expired", message: "Your login session has expired. Please enter your email and password to continue using the app, or sign out if desired.", preferredStyle: .alert)
alertController.addTextField { (email) in
email.placeholder = "Email"
- 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 metadataOutput
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
// Stop capture session to prevent multiple network calls prior to completion
captureSession.stopRunning()
- 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 systemMore
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public func systemMore(highlighted isHighlighted: Bool) -> UIImage? {
let image = UIImage.init()
let circleDiameter = isHighlighted ? 5.0 : 4.0
let scale = UIScreen.main.scale
- 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"