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

View on GitHub

Showing 113 of 122 total issues

File HealthKitController.swift has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Foundation
import Combine
import SwiftUI
import HealthKit

Severity: Minor
Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 5 hrs to fix

    Function getBodyCompStatsForLast30Days has a Cognitive Complexity of 28 (exceeds 5 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: Minor
    Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 4 hrs 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 parseFoodLogEntries has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        func parseFoodLogEntries() {
            guard let foodLog = foodLog else { return }
            
            var totalMacros: (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)
            
    Severity: Minor
    Found in Nutrivurv/Nutrivurv/FoodLogController.swift - About 4 hrs 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

    File TabBar.swift has 317 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import UIKit
    
    
    public enum TabBarItemPositioning : Int {
        
    Severity: Minor
    Found in Nutrivurv/Nutrivurv/TabBar.swift - About 3 hrs to fix

      File TabBarItemContentView.swift has 305 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import UIKit
      
      public enum TabBarItemContentMode : Int {
          
          case alwaysOriginal // Always set the original image size
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift - About 3 hrs to fix

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

            override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
                guard let foodLog = foodLog else { return }
                var entry: FoodLogEntry?
                
                if editingStyle == .delete {
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogTableViewController.swift - About 3 hrs 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 registerUser has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            func registerUser(user: UserProfile, completion: @escaping (Result<Bool, NetworkError>) -> Void) {
                let registerURL = baseURL.appendingPathComponent("ios/register")
                var request = URLRequest(url: registerURL)
                
                request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/UserController.swift - About 2 hrs 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 getCalorieStatsCollectionForWeek has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            private func getCalorieStatsCollectionForWeek(using quantityType: HKQuantityType) {
                getCumulativeStatsCollectionUsingOneDayInterval(for: quantityType) { (statsCollection, error) in
                    if let error = error {
                        print(error)
                        self.stopLoadingFor(quantityType: quantityType)
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 2 hrs 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 updateLayout has 93 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

            open func updateLayout() {
                let w = self.bounds.size.width
                let h = self.bounds.size.height
                
                imageView.isHidden = (imageView.image == nil)
        Severity: Major
        Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift - About 2 hrs to fix

          Function getCalorieStatsCollectionForWeek has 88 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

              private func getCalorieStatsCollectionForWeek(using quantityType: HKQuantityType) {
                  getCumulativeStatsCollectionUsingOneDayInterval(for: quantityType) { (statsCollection, error) in
                      if let error = error {
                          print(error)
                          self.stopLoadingFor(quantityType: quantityType)
          Severity: Major
          Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 2 hrs to fix

            File BarcodeSearchViewController.swift has 270 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import AVFoundation
            import UIKit
            import SwiftUI
            
            class BarcodeSearchViewController: UIViewController, AVCapturePhotoCaptureDelegate {
            Severity: Minor
            Found in Nutrivurv/Nutrivurv/BarcodeSearchViewController.swift - About 2 hrs to fix

              Function registerUser has 85 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

                  func registerUser(user: UserProfile, completion: @escaping (Result<Bool, NetworkError>) -> Void) {
                      let registerURL = baseURL.appendingPathComponent("ios/register")
                      var request = URLRequest(url: registerURL)
                      
                      request.addValue("application/json", forHTTPHeaderField: "Content-Type")
              Severity: Major
              Found in Nutrivurv/Nutrivurv/UserController.swift - About 2 hrs to fix

                Function parseFoodLogEntries has 82 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                    func parseFoodLogEntries() {
                        guard let foodLog = foodLog else { return }
                        
                        var totalMacros: (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)
                        
                Severity: Major
                Found in Nutrivurv/Nutrivurv/FoodLogController.swift - About 2 hrs to fix

                  Function updateAccessibilityLabels has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                      func updateAccessibilityLabels() {
                          guard let tabBarItems = self.items, tabBarItems.count == self.containers.count else {
                              return
                          }
                          
                  Severity: Minor
                  Found in Nutrivurv/Nutrivurv/TabBar.swift - About 2 hrs 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 loginUser has a Cognitive Complexity of 16 (exceeds 5 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: Minor
                  Found in Nutrivurv/Nutrivurv/UserController.swift - About 2 hrs 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 getFoodLogEntriesForDate has a Cognitive Complexity of 15 (exceeds 5 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: 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 updateLayout has 71 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                      func updateLayout() {
                          guard let tabBarItems = self.items else {
                              TabBarController.printError("empty items")
                              return
                          }
                  Severity: Major
                  Found in Nutrivurv/Nutrivurv/TabBar.swift - About 1 hr to fix

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

                        func textFieldDidBeginEditing(_ textField: UITextField) {
                            textField.layer.borderWidth = 2.0
                            textField.layer.borderColor = UIColor(red: 0, green: 0.259, blue: 0.424, alpha: 1).cgColor
                            textField.layer.cornerRadius = 4
                            textField.layer.shadowColor = UIColor(red: 0, green: 0.455, blue: 0.722, alpha: 0.5).cgColor
                    Severity: Major
                    Found in Nutrivurv/Nutrivurv/LoginViewController.swift and 1 other location - About 1 hr to fix
                    Nutrivurv/Nutrivurv/RegisterViewController.swift on lines 142..150

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

                    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 2 locations. Consider refactoring.
                    Open

                        func textFieldDidBeginEditing(_ textField: UITextField) {
                            textField.layer.borderWidth = 2.0
                            textField.layer.borderColor = UIColor(red: 0, green: 0.259, blue: 0.424, alpha: 1).cgColor
                            textField.layer.cornerRadius = 4
                            textField.layer.shadowColor = UIColor(red: 0, green: 0.455, blue: 0.722, alpha: 0.5).cgColor
                    Severity: Major
                    Found in Nutrivurv/Nutrivurv/RegisterViewController.swift and 1 other location - About 1 hr to fix
                    Nutrivurv/Nutrivurv/LoginViewController.swift on lines 125..133

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

                    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 searchForFoodByUPC has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                    Open

                        func searchForFoodByUPC(_ upc: String) {
                            self.searchController?.searchForFoodItemWithUPC(searchTerm: upc) { (error) in
                                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                                    self.hideLoadingIndicators()
                                    
                    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

                    Severity
                    Category
                    Status
                    Source
                    Language