Lambda-School-Labs/nutrition-tracker-ios-pt7

View on GitHub

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 {
Severity: Minor
Found in Nutrivurv/Nutrivurv/FoodLogTableViewController.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 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)
Severity: Major
Found in Nutrivurv/Nutrivurv/FoodSearchController.swift - About 1 hr to fix

    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)
    Severity: Major
    Found in Nutrivurv/Nutrivurv/FoodSearchController.swift - About 1 hr to fix

      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
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/SceneDelegate.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 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
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodSearchTableViewController.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 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))
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodLogController.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 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
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/CalculateBMIViewController.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 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 {
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodSearchTableViewController.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 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
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 45 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 navVC.viewControllers.count > 1 {
                                  navVC.popToRootViewController(animated: animated)
                              }
      Severity: Major
      Found in Nutrivurv/Nutrivurv/TabBar.swift - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if navVC.viewControllers.count > 1 && navVC.viewControllers.last != tabBarController {
                                    navVC.popToViewController(tabBarController, animated: true);
                                }
        Severity: Major
        Found in Nutrivurv/Nutrivurv/TabBar.swift - About 45 mins to fix

          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) {
          Severity: Minor
          Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 35 mins to fix

            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) {
            Severity: Minor
            Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 35 mins to fix

              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 {
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/UserDefaults.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 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) {
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/TabBar.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 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
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/LoginViewController.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 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"),
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/QuoteController.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 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"
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/FoodLogTableViewController.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 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()
                      
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/BarcodeSearchViewController.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 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
                      
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/TabBarItemMoreContentView.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

              Severity
              Category
              Status
              Source
              Language