ArchiveCore/Sources/ArchiveBackend/FolderAccess/iCloud/ICloudFolderProvider.swift
Function createDetails
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static func createDetails(from item: NSMetadataItem) -> FileChange.Details? {
// get the document path
guard let documentPath = item.value(forAttribute: NSMetadataItemURLKey) as? URL else {
log.errorAndAssert("Could not parse Metadata URL.")
return nil
Function createDetails
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
static func createDetails(from item: NSMetadataItem) -> FileChange.Details? {
// get the document path
guard let documentPath = item.value(forAttribute: NSMetadataItemURLKey) as? URL else {
log.errorAndAssert("Could not parse Metadata URL.")
return nil
- 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
Avoid too many return
statements within this function. Open
Open
return FileChange.Details(url: documentPath, filename: filename, size: Int(size), downloadStatus: documentStatus)
Line should be 120 characters or less: currently 124 characters Open
Open
let removedMetadataItems = (notification.userInfo?[NSMetadataQueryUpdateRemovedItemsKey] as? [NSMetadataItem]) ?? []
- Exclude checks
Line should be 120 characters or less: currently 124 characters Open
Open
let changedMetadataItems = (notification.userInfo?[NSMetadataQueryUpdateChangedItemsKey] as? [NSMetadataItem]) ?? []
- Exclude checks
Line should be 120 characters or less: currently 163 characters Open
Open
NotificationCenter.default.addObserver(self, selector: #selector(Self.queryUpdated(notification:)), name: .NSMetadataQueryDidUpdate, object: metadataQuery)
- Exclude checks
Line should be 120 characters or less: currently 121 characters Open
Open
return FileChange.Details(url: documentPath, filename: filename, size: Int(size), downloadStatus: documentStatus)
- Exclude checks
Line should be 120 characters or less: currently 126 characters Open
Open
guard let downloadingStatus = item.value(forAttribute: NSMetadataUbiquitousItemDownloadingStatusKey) as? String else {
- Exclude checks
Line should be 120 characters or less: currently 218 characters Open
Open
private let notContainsTempPath = NSPredicate(format: "(NOT (%K CONTAINS[c] %@)) AND (NOT (%K CONTAINS[c] %@))", NSMetadataItemPathKey, "/\(ICloudFolderProvider.tempFolderName)/", NSMetadataItemPathKey, "/.Trash/")
- Exclude checks
Line should be 120 characters or less: currently 163 characters Open
Open
// let predicate = NSPredicate(format: "(%K LIKE[c] '\(year)-*.pdf') OR (%K LIKE[c] '\(year - 1)-*.pdf')", NSMetadataItemFSNameKey, NSMetadataItemFSNameKey)
- Exclude checks
Line should be 120 characters or less: currently 149 characters Open
Open
let percentDownloaded = Float(truncating: (item.value(forAttribute: NSMetadataUbiquitousItemPercentDownloadedKey) as? NSNumber) ?? 0)
- Exclude checks
Line should be 120 characters or less: currently 129 characters Open
Open
// Check if it is a local document. These two values are possible for the "NSMetadataUbiquitousItemDownloadingStatusKey":
- Exclude checks
Line should be 120 characters or less: currently 175 characters Open
Open
NotificationCenter.default.addObserver(self, selector: #selector(Self.finishGathering(notification:)), name: .NSMetadataQueryDidFinishGathering, object: metadataQuery)
- Exclude checks