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

View on GitHub

Showing 113 of 122 total issues

Function calculateCaloricDeficits has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    private func calculateCaloricDeficits(with caloricBudget: Int) {
        guard caloricBudget > 0, consumedCalories.allDataIsLoaded else { return }
        
        let deficitDay1 = consumedCalories.day1Count == 0 ? 0 : caloricBudget - consumedCalories.day1Count
        let deficitDay2 = consumedCalories.day2Count == 0 ? 0 : caloricBudget - consumedCalories.day2Count
Severity: Minor
Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

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

    Function getMostRecentSamples has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        func getMostRecentSamples(for sampleType: HKSampleType, withStart date: Date = Date.distantPast, limit: Int = 1, sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: true), completion: @escaping ([HKQuantitySample]?, Error?) -> Swift.Void) {
    Severity: Minor
    Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 35 mins to fix

      Function getCumulativeSamples has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          func getCumulativeSamples(for quantityType: HKQuantityType, startDate: Date = Date(), endDate: Date = Date(), options: HKStatisticsOptions = [], completion: @escaping (HKStatistics?, Error?) -> Void) {
      Severity: Minor
      Found in Nutrivurv/Nutrivurv/HealthKitController.swift - About 35 mins to fix

        Function point has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            open override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
                var b = super.point(inside: point, with: event)
                if !b {
                    for container in containers {
                        if container.point(inside: CGPoint.init(x: point.x - container.frame.origin.x, y: point.y - container.frame.origin.y), with: event) {
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/TabBar.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

            open var imageView: UIImageView = {
                let imageView = UIImageView.init(frame: CGRect.zero)
                imageView.backgroundColor = .clear
                return imageView
            }()
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/TabBarItemBadgeView.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/TabBarItemContentView.swift on lines 100..104

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

        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

            open var imageView: UIImageView = {
                let imageView = UIImageView.init(frame: CGRect.zero)
                imageView.backgroundColor = .clear
                return imageView
            }()
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/TabBarItemContentView.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/TabBarItemBadgeView.swift on lines 31..35

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

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

            public func systemMore(highlighted isHighlighted: Bool) -> UIImage? {
                let image = UIImage.init()
                let circleDiameter  = isHighlighted ? 5.0 : 4.0
                let scale = UIScreen.main.scale
                
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/TabBarItemMoreContentView.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function getLoginStreak has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            class func getLoginStreak() -> Int {
                var currentLoginStreak = UserDefaults.standard.integer(forKey: Keys.dailyLoginStreak.rawValue)
                
                if let differenceInDays = differenceInDays() {
                    switch differenceInDays {
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/UserDefaults.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function reauthorizeUser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private func reauthorizeUser() {
                let alertController = UIAlertController(title: "Session Expired", message: "Your login session has expired. Please enter your email and password to continue using the app, or sign out if desired.", preferredStyle: .alert)
                
                alertController.addTextField { (email) in
                    email.placeholder = "Email"
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogTableViewController.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function loginButtonTapped has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            @IBAction func loginButtonTapped(_ sender: Any) {
                guard let email = self.emailTextField.text, !email.isEmpty,
                    let password = self.passwordTextField.text, !password.isEmpty else {
                        completeFieldsAlert()
                        return
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/LoginViewController.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function point has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            internal override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
                var b = super.point(inside: point, with: event)
                if !b {
                    for subview in self.subviews {
                        if subview.point(inside: CGPoint.init(x: point.x - subview.frame.origin.x, y: point.y - subview.frame.origin.y), with: event) {
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/TabBarItemContainer.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function getRandomQuote has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            func getRandomQuote(completion: @escaping (Result<Quote, NetworkError>) -> Void) {
                
                var urlComponets = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)
                urlComponets?.queryItems = [
                    URLQueryItem(name: "maxLength", value: "102"),
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/QuoteController.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function getMacrosTuple has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private func getMacrosTuple(for meal: [FoodLogEntry]) -> (CGFloat, CGFloat, CGFloat, CGFloat) {
                var totalCalories: CGFloat = 0.0
                var totalCarbs: CGFloat = 0.0
                var totalProtein: CGFloat = 0.0
                var totalFat: CGFloat = 0.0
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function metadataOutput has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
                
                // Stop capture session to prevent multiple network calls prior to completion
                captureSession.stopRunning()
                
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/BarcodeSearchViewController.swift - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

                        if response.statusCode != 200 {
                            print("Error communicating with server. Response information: \(response), status code: \(response.statusCode)")
                            DispatchQueue.main.async {
                                completion(.failure(.serverError))
                            }
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 340..346

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

        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

                        if response.statusCode != 200 {
                            print("Error communicating with server. Response information: \(response), status code: \(response.statusCode)")
                            DispatchQueue.main.async {
                                completion(.failure(.serverError))
                            }
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 412..418

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

        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

                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 and 3 other locations - About 35 mins to fix
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 240..246
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 308..314
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 380..386

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

        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

                guard let entryID = entry.id else {
                    print("Unable to update entry: no ID associated with entry")
                    DispatchQueue.main.async {
                        completion(.failure(.otherError))
                    }
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 248..254

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

        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

                guard let entryID = entry.id else {
                    print("Unable to update entry: no ID associated with entry")
                    DispatchQueue.main.async {
                        completion(.failure(.otherError))
                    }
        Severity: Minor
        Found in Nutrivurv/Nutrivurv/FoodLogController.swift and 1 other location - About 35 mins to fix
        Nutrivurv/Nutrivurv/FoodLogController.swift on lines 388..394

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

        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

        Severity
        Category
        Status
        Source
        Language