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

View on GitHub

Showing 113 of 122 total issues

Function select has 64 lines of code (exceeds 50 allowed). Consider refactoring.
Open

    @objc func select(itemAtIndex idx: Int, animated: Bool) {
        let newIndex = max(0, idx)
        let currentIndex = (selectedItem != nil) ? (items?.firstIndex(of: selectedItem!) ?? -1) : -1
        guard newIndex < items?.count ?? 0, let item = self.items?[newIndex], item.isEnabled == true else {
            return
Severity: Major
Found in Nutrivurv/Nutrivurv/TabBar.swift - About 1 hr to fix

    Function loginUser has 62 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

        func loginUser(user: UserAuth, completion: @escaping (Result<Bool, NetworkError>) -> Void) {
            let loginURL = baseURL.appendingPathComponent("login")
            var request = URLRequest(url: loginURL)
            
            request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    Severity: Major
    Found in Nutrivurv/Nutrivurv/UserController.swift - About 1 hr to fix

      Function tableView has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
              guard let foodLog = foodLog, !foodLogIsEmpty() else { return }
              
              var foodEntry: FoodLogEntry?
              
      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 searchForFoodItemWithUPC has a Cognitive Complexity of 12 (exceeds 5 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: Minor
      Found in Nutrivurv/Nutrivurv/FoodSearchController.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 updateAllValues has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          func updateAllValues() {
              
              if let weightSampleType = HKSampleType.quantityType(forIdentifier: .bodyMass) {
                  if !weightIsLoading {
                      getBodyCompStatsForLast30Days(using: weightSampleType)
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/HealthKitController.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 a Cognitive Complexity of 12 (exceeds 5 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: Minor
      Found in Nutrivurv/Nutrivurv/FoodSearchController.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 searchForNutrients has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          func searchForNutrients(qty: Double, measureURI: String, foodId: String, completion: @escaping (Nutrients?) -> Void) {
              let json: [String: Any] = ["ingredients": [["quantity": qty, "measureURI": measureURI, "foodId": foodId]]]
              let jsonData = try? JSONSerialization.data(withJSONObject: json)
              
              var urlComponents = URLComponents(url: nutritionURL, resolvingAgainstBaseURL: true)
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodSearchController.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 getBodyCompStatsForLast30Days has 59 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

          private func getBodyCompStatsForLast30Days(using sampleType: HKSampleType) {
              let endDate = Date()
              
              guard let startDate = Calendar.current.date(byAdding: .day, value: -29, to: endDate) else {
                  print("error getting start date for statistics collection")
      Severity: Major
      Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 1 hr to fix

        Function getFoodLogEntriesForDate has 58 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

            func getFoodLogEntriesForDate(date: String, completion: @escaping (Result<FoodLog?, NetworkError>) -> Void) {
                guard let token = getUserToken() else {
                    print("No token found for user")
                    DispatchQueue.main.async {
                        completion(.failure(.noAuth))
        Severity: Major
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift - About 1 hr to fix

          Function editFoodLogEntry has 57 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

              func editFoodLogEntry(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: Major
          Found in Nutrivurv/Nutrivurv/FoodLogController.swift - About 1 hr to fix

            Function setUpCameraLiveView has 57 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

                private func setUpCameraLiveView() {
                    // Ensure we have appropriate permissions before a capture session is established
                    guard permissionGranted != false else {
                        return
                    }
            Severity: Major
            Found in Nutrivurv/Nutrivurv/BarcodeSearchViewController.swift - About 1 hr to fix

              Function tableView has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
                      guard let foodLog = foodLog else { return nil }
                      
                      let label = MealTypeHeaderLabel()
                      var macrosByMealModel: DailyMacros?
              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 setUpCameraLiveView has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  private func setUpCameraLiveView() {
                      // Ensure we have appropriate permissions before a capture session is established
                      guard permissionGranted != false else {
                          return
                      }
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/BarcodeSearchViewController.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 prepare has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                      if segue.identifier == "ToActivityLevel" {
                          guard let profileController = profileController,
                              let apVC = segue.destination as? ActivityLevelViewController else { return }
                          
              Severity: Minor
              Found in Nutrivurv/Nutrivurv/GettingPersonalViewController.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 editFoodLogEntry has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

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

                  @objc private func updateFoodLog() {
                      guard let date = selectedDateAsString else { return }
                      
                      FoodLogController.shared.getFoodLogEntriesForDate(date: date) { (result) in
                          switch result {
              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

              Identical blocks of code found in 4 locations. Consider refactoring.
              Open

                  private func createAndDisplayAlertController(title: String, message: String) {
                      let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
                      let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
                      alertController.addAction(alertAction)
                      self.present(alertController, animated: true, completion: nil)
              Severity: Major
              Found in Nutrivurv/Nutrivurv/GettingPersonalViewController.swift and 3 other locations - About 1 hr to fix
              Nutrivurv/Nutrivurv/CalculateBMIViewController.swift on lines 78..83
              Nutrivurv/Nutrivurv/LoginViewController.swift on lines 94..99
              Nutrivurv/Nutrivurv/RegisterViewController.swift on lines 104..109

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

              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

              Identical blocks of code found in 4 locations. Consider refactoring.
              Open

                  private func createAndDisplayAlertController(title: String, message: String) {
                      let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
                      let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
                      alertController.addAction(alertAction)
                      self.present(alertController, animated: true, completion: nil)
              Severity: Major
              Found in Nutrivurv/Nutrivurv/CalculateBMIViewController.swift and 3 other locations - About 1 hr to fix
              Nutrivurv/Nutrivurv/GettingPersonalViewController.swift on lines 80..85
              Nutrivurv/Nutrivurv/LoginViewController.swift on lines 94..99
              Nutrivurv/Nutrivurv/RegisterViewController.swift on lines 104..109

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

              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

              Identical blocks of code found in 4 locations. Consider refactoring.
              Open

                  private func createAndDisplayAlertController(title: String, message: String) {
                      let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
                      let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
                      alertController.addAction(alertAction)
                      self.present(alertController, animated: true, completion: nil)
              Severity: Major
              Found in Nutrivurv/Nutrivurv/LoginViewController.swift and 3 other locations - About 1 hr to fix
              Nutrivurv/Nutrivurv/CalculateBMIViewController.swift on lines 78..83
              Nutrivurv/Nutrivurv/GettingPersonalViewController.swift on lines 80..85
              Nutrivurv/Nutrivurv/RegisterViewController.swift on lines 104..109

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

              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 searchForNutrients has 54 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

                  func searchForNutrients(qty: Double, measureURI: String, foodId: String, completion: @escaping (Nutrients?) -> Void) {
                      let json: [String: Any] = ["ingredients": [["quantity": qty, "measureURI": measureURI, "foodId": foodId]]]
                      let jsonData = try? JSONSerialization.data(withJSONObject: json)
                      
                      var urlComponents = URLComponents(url: nutritionURL, resolvingAgainstBaseURL: true)
              Severity: Major
              Found in Nutrivurv/Nutrivurv/FoodSearchController.swift - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language