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

View on GitHub

Showing 113 of 122 total issues

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

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

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

                      titleLabel.frame = CGRect.init(x: (w - titleLabel.bounds.size.width) / 2.0,
                                                     y: h - titleLabel.bounds.size.height - 1.0,
                                                     width: titleLabel.bounds.size.width,
                                                     height: titleLabel.bounds.size.height)
      Severity: Major
      Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift and 1 other location - About 1 hr to fix
      Nutrivurv/Nutrivurv/TabBarItemContentView.swift on lines 223..226

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

      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

                          titleLabel.frame = CGRect.init(x: (w - titleLabel.bounds.size.width) / 2.0,
                                                         y: h - titleLabel.bounds.size.height - 1.0,
                                                         width: titleLabel.bounds.size.width,
                                                         height: titleLabel.bounds.size.height)
      Severity: Major
      Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift and 1 other location - About 1 hr to fix
      Nutrivurv/Nutrivurv/TabBarItemContentView.swift on lines 260..263

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

      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

              do {
                  let data = try encoder.encode(entry)
                  request.httpBody = data
              } catch {
                  print("Error encoding food item for upload to database: \(error)")
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 55 mins to fix
      Nutrivurv/Nutrivurv/FoodLogController.swift on lines 265..274

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

      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

              do {
                  let data = try encoder.encode(entry)
                  request.httpBody = data
              } catch {
                  print("Error encoding food item for upload to database: \(error)")
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 55 mins to fix
      Nutrivurv/Nutrivurv/FoodLogController.swift on lines 197..206

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

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

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

                      badgeView.frame = CGRect.init(origin: CGPoint.init(x: w / 2.0 + badgeOffset.horizontal, y: h / 2.0 + badgeOffset.vertical), size: size)
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift and 1 other location - About 50 mins to fix
      Nutrivurv/Nutrivurv/TabBarItemContentView.swift on lines 251..251

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

      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

                          badgeView.frame = CGRect.init(origin: CGPoint.init(x: w / 2.0 + badgeOffset.horizontal, y: h / 2.0 + badgeOffset.vertical), size: size)
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift and 1 other location - About 50 mins to fix
      Nutrivurv/Nutrivurv/TabBarItemContentView.swift on lines 278..278

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

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

      Severity
      Category
      Status
      Source
      Language