PDF-Archiver/PDF-Archiver

View on GitHub

Showing 38 of 599 total issues

Function createPdf has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    private func createPdf(of documentId: UUID) throws -> URL {
        // check if the parent folder exists
        try FileManager.default.createFolderIfNotExists(tempImagePath)

        // STEP I: get all image urls
Severity: Minor
Found in Shared/Other/DocumentProcessing/PDFProcessing.swift - About 6 hrs 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 performDrop has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    func performDrop(info: DropInfo) -> Bool {
        documentProcessingState = .processing
        
        let types: [UTType] = [.pdf, .image, .fileURL]
        guard info.hasItemsConforming(to: types) else { return false }
Severity: Minor
Found in Shared/Import/PDFDropHandler.swift - About 2 hrs 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 createPdf has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private func createPdf(of documentId: UUID) throws -> URL {
        // check if the parent folder exists
        try FileManager.default.createFolderIfNotExists(tempImagePath)

        // STEP I: get all image urls
Severity: Major
Found in Shared/Other/DocumentProcessing/PDFProcessing.swift - About 2 hrs to fix

    Function renderPdf has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static func renderPdf(from observations: [TextObservation]) -> PDFDocument {
    
            var pages = [PDFPage]()
            for observation in observations {
    
    
    Severity: Minor
    Found in Shared/Other/DocumentProcessing/PDFProcessing.swift - About 1 hr to fix

      Function testParsingValidDate has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func testParsingValidDate() throws {
      
              // setup the raw string
              let hiddenDate = "20050201"
              let longText = """
      Severity: Minor
      Found in Tests macOS/ArchiveBackendTests/DateParserTests.swift - About 1 hr to fix

        Function performDrop has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func performDrop(info: DropInfo) -> Bool {
                documentProcessingState = .processing
                
                let types: [UTType] = [.pdf, .image, .fileURL]
                guard info.hasItemsConforming(to: types) else { return false }
        Severity: Minor
        Found in Shared/Import/PDFDropHandler.swift - About 1 hr to fix

          Function snapshot has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              open class func snapshot(_ name: String, timeWaitingForIdle timeout: TimeInterval = 20) {
                  if timeout > 0 {
                      waitForLoadingIndicatorToDisappear(within: timeout)
                  }
          
          
          Severity: Minor
          Found in UITests iOS/SnapshotHelper.swift - About 1 hr to fix

            Function setArchiveUrl has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public func setArchiveUrl(with type: ArchivePathType) throws {
                    if type == .iCloudDrive {
                        guard fileManager.iCloudDriveURL != nil else { throw PathError.iCloudDriveNotFound }
                    }
            
            
            Severity: Minor
            Found in Shared/Other/FolderAccess/PathManager/PathManager.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 assertEqualPDFDocuments has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                func assertEqualPDFDocuments(left: PDFDocument, right: PDFDocument) {
                    guard left.pageCount == right.pageCount else {
                        XCTFail("Documents have different page count")
                        return
                    }
            Severity: Minor
            Found in Tests macOS/ArchiveBackendTests/helper/XCTestCase.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 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
            Severity: Minor
            Found in Shared/Other/FolderAccess/iCloud/ICloudFolderProvider.swift - About 1 hr to fix

              Function setArchiveUrl has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public func setArchiveUrl(with type: ArchivePathType) throws {
                      if type == .iCloudDrive {
                          guard fileManager.iCloudDriveURL != nil else { throw PathError.iCloudDriveNotFound }
                      }
              
              
              Severity: Minor
              Found in Shared/Other/FolderAccess/PathManager/PathManager.swift - About 1 hr to fix

                Function syncLoadItem has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    func syncLoadItem(forTypeIdentifier uti: UTType) throws -> Data? {
                        var data: Data?
                        var error: Error?
                        let semaphore = DispatchSemaphore(value: 0)
                        self.loadItem(forTypeIdentifier: uti.identifier, options: nil) { rawData, rawError in
                Severity: Minor
                Found in ShareExtension/NSItemProvider.swift - About 1 hr to fix

                  Function main has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      override public func main() {
                  
                          do {
                              if isCancelled {
                                  return
                  Severity: Minor
                  Found in Shared/Other/DocumentProcessing/PDFProcessing.swift - About 1 hr to fix

                    Function testJPGInput has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        func testJPGInput() throws {
                            let uuid = UUID()
                            let exampleUrl = Self.tempFolder.appendingPathComponent(uuid.uuidString).appendingPathExtension("jpg")
                            try FileManager.default.copyItem(at: Bundle.billJPGGUrl, to: exampleUrl)
                    
                    
                    Severity: Minor
                    Found in Tests macOS/ArchiveBackendTests/PDFProcessingTests.swift - About 1 hr to fix

                      Function testJPGMultiplePages has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          func testJPGMultiplePages() throws {
                              let uuid = UUID()
                              try FileManager.default.copyItem(at: Bundle.billJPGGUrl, to: Self.tempFolder.appendingPathComponent(uuid.uuidString + "-1").appendingPathExtension("jpg"))
                              try FileManager.default.copyItem(at: Bundle.billJPGGUrl, to: Self.tempFolder.appendingPathComponent(uuid.uuidString + "-2").appendingPathExtension("jpg"))
                              try FileManager.default.copyItem(at: Bundle.billJPGGUrl, to: Self.tempFolder.appendingPathComponent(uuid.uuidString + "-3").appendingPathExtension("jpg"))
                      Severity: Minor
                      Found in Tests macOS/ArchiveBackendTests/PDFProcessingTests.swift - About 1 hr to fix

                        Function testPNGInput has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            func testPNGInput() throws {
                                let uuid = UUID()
                                let exampleUrl = Self.tempFolder.appendingPathComponent(uuid.uuidString).appendingPathExtension("png")
                                try FileManager.default.copyItem(at: Bundle.billPNGUrl, to: exampleUrl)
                        
                        
                        Severity: Minor
                        Found in Tests macOS/ArchiveBackendTests/PDFProcessingTests.swift - About 1 hr to fix

                          Function syncLoadItem has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                              func syncLoadItem(forTypeIdentifier uti: UTType) throws -> Data? {
                                  var data: Data?
                                  var error: Error?
                                  let semaphore = DispatchSemaphore(value: 0)
                                  self.loadItem(forTypeIdentifier: uti.identifier, options: nil) { rawData, rawError in
                          Severity: Minor
                          Found in ShareExtension/NSItemProvider.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 saveData has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                              func saveData(at url: URL, with validUTIs: [UTType]) throws -> Bool {
                                  var error: Error?
                                  var data: Data?
                          
                                  for uti in validUTIs where hasItemConformingToTypeIdentifier(uti.identifier) {
                          Severity: Minor
                          Found in ShareExtension/NSItemProvider.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 createAndPost has 7 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public func createAndPost(title: LocalizedStringKey, message: LocalizedStringKey, primaryButton: Alert.Button, secondaryButton: Alert.Button, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
                          Severity: Major
                          Found in Shared/Other/Constants/ErrorHandling/NotificationCenter+Error.swift - About 50 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                        for observation in (request.results as? [VNRecognizedTextObservation] ?? []) {
                                                            guard let candidate = observation.topCandidates(1).first,
                                                                !candidate.string.isEmpty else { continue }
                                                            thisObservation.append(candidate.string)
                                                        }
                            Severity: Major
                            Found in Shared/Other/DocumentProcessing/PDFProcessing.swift - About 45 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language