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

View on GitHub

Showing 92 of 122 total issues

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

          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

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

                override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                    guard let foodLog = foodLog else { return 0 }
                    
                    switch section {
                    case 0:
            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 getFoodImage has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                func getFoodImage(urlString: String, completion: @escaping (Data?) -> Void) {
                    guard let url = URL(string: urlString) else {
                        print("Error getting image url from string")
                        DispatchQueue.main.async {
                            completion(nil)
            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 createFoodLogEntry has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                func createFoodLogEntry(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 checkPermissions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                private func checkPermissions() {
                    let mediaType = AVMediaType.video
                    let status = AVCaptureDevice.authorizationStatus(for: mediaType)
                    
                    switch status {
            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 tableView has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                    let cell = tableView.dequeueReusableCell(withIdentifier: "foodLogCell", for: indexPath)
                    
                    guard let foodLog = foodLog else { return cell }
                    
            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

            Severity
            Category
            Status
            Source
            Language