PDF-Archiver/PDF-Archiver

View on GitHub
ArchiveCore/Sources/ArchiveBackend/FolderAccess/iCloud/ICloudFolderProvider.swift

Summary

Maintainability
A
2 hrs
Test Coverage

Function createDetails has 33 lines of code (exceeds 25 allowed). Consider refactoring.
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

        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

    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

            return FileChange.Details(url: documentPath, filename: filename, size: Int(size), downloadStatus: documentStatus)

      Line should be 120 characters or less: currently 124 characters
      Open

              let removedMetadataItems = (notification.userInfo?[NSMetadataQueryUpdateRemovedItemsKey] as? [NSMetadataItem]) ?? []

      Line should be 120 characters or less: currently 124 characters
      Open

              let changedMetadataItems = (notification.userInfo?[NSMetadataQueryUpdateChangedItemsKey] as? [NSMetadataItem]) ?? []

      Line should be 120 characters or less: currently 163 characters
      Open

              NotificationCenter.default.addObserver(self, selector: #selector(Self.queryUpdated(notification:)), name: .NSMetadataQueryDidUpdate, object: metadataQuery)

      Line should be 120 characters or less: currently 121 characters
      Open

              return FileChange.Details(url: documentPath, filename: filename, size: Int(size), downloadStatus: documentStatus)

      Line should be 120 characters or less: currently 126 characters
      Open

              guard let downloadingStatus = item.value(forAttribute: NSMetadataUbiquitousItemDownloadingStatusKey) as? String else {

      Line should be 120 characters or less: currently 218 characters
      Open

          private let notContainsTempPath = NSPredicate(format: "(NOT (%K CONTAINS[c] %@)) AND (NOT (%K CONTAINS[c] %@))", NSMetadataItemPathKey, "/\(ICloudFolderProvider.tempFolderName)/", NSMetadataItemPathKey, "/.Trash/")

      Line should be 120 characters or less: currently 163 characters
      Open

      //        let predicate = NSPredicate(format: "(%K LIKE[c] '\(year)-*.pdf') OR (%K LIKE[c] '\(year - 1)-*.pdf')", NSMetadataItemFSNameKey, NSMetadataItemFSNameKey)

      Line should be 120 characters or less: currently 149 characters
      Open

                      let percentDownloaded = Float(truncating: (item.value(forAttribute: NSMetadataUbiquitousItemPercentDownloadedKey) as? NSNumber) ?? 0)

      Line should be 120 characters or less: currently 129 characters
      Open

              // Check if it is a local document. These two values are possible for the "NSMetadataUbiquitousItemDownloadingStatusKey":

      Line should be 120 characters or less: currently 175 characters
      Open

              NotificationCenter.default.addObserver(self, selector: #selector(Self.finishGathering(notification:)), name: .NSMetadataQueryDidFinishGathering, object: metadataQuery)

      There are no issues that match your filters.

      Category