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
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")
- Read upRead up
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)
- Read upRead up
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 {
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
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 {
- Read upRead up
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")
- Read upRead up
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)
- Read upRead up
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)
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)
File BarcodeSearchViewController.swift
has 270 lines of code (exceeds 250 allowed). Consider refactoring. Open
import AVFoundation
import UIKit
import SwiftUI
class BarcodeSearchViewController: UIViewController, AVCapturePhotoCaptureDelegate {
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")
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)
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
}
- Read upRead up
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")
- Read upRead up
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))
- Read upRead up
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
}
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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()
- Read upRead up
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"