PDF-Archiver/PDF-Archiver

View on GitHub

Showing 39 of 484 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 ArchiveCore/Sources/ArchiveBackend/PDFRendering/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 fuzzyMatch3 has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    private func fuzzyMatch3(_ needle: [Element]) -> (score: Int, matrix: Matrix<Int?>)? {
        guard needle.count <= count else { return nil }
        var matrix = Matrix<Int?>(width: self.count, height: needle.count, initialValue: nil)
        if needle.isEmpty { return (score: 0, matrix: matrix) }
        var prevMatchIdx: Int = -1
Severity: Minor
Found in ArchiveCore/Sources/ArchiveBackend/Search/Array+FuzzyMatch.swift - About 3 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 ArchiveCore/Sources/ArchiveBackend/PDFRendering/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 ArchiveCore/Sources/ArchiveBackend/PDFRendering/PDFProcessing.swift - About 1 hr to fix

      Function syncLoadItem has 38 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

        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 ArchiveCore/Tests/ArchiveBackendTests/DateParserTests.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 updateButtonNames has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                private func updateButtonNames(with products: Set<SKProduct>) {
                    for product in products {
                        switch product.productIdentifier {
                        case "SUBSCRIPTION_MONTHLY_IOS":
                            guard let localizedPrice = product.localizedPrice else { continue }
            Severity: Minor
            Found in ArchiveCore/Sources/ArchiveViews/IAPViewModel.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 ArchiveCore/Tests/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 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 ArchiveCore/Sources/ArchiveBackend/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 fuzzyMatch3 has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private func fuzzyMatch3(_ needle: [Element]) -> (score: Int, matrix: Matrix<Int?>)? {
                    guard needle.count <= count else { return nil }
                    var matrix = Matrix<Int?>(width: self.count, height: needle.count, initialValue: nil)
                    if needle.isEmpty { return (score: 0, matrix: matrix) }
                    var prevMatchIdx: Int = -1
            Severity: Minor
            Found in ArchiveCore/Sources/ArchiveBackend/Search/Array+FuzzyMatch.swift - About 1 hr to fix

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

                    func tapped(button: IAPButton, presentationMode: Binding<PresentationMode>) {
                
                        switch button {
                        case .level1:
                            log.info("IAPView - buy: Monthly subscription.")
                Severity: Minor
                Found in ArchiveCore/Sources/ArchiveViews/IAPViewModel.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 ArchiveCore/Sources/ArchiveBackend/PathManager/PathManager.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 ArchiveCore/Sources/ArchiveBackend/PDFRendering/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 ArchiveCore/Tests/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 ArchiveCore/Tests/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 ArchiveCore/Tests/ArchiveBackendTests/PDFProcessingTests.swift - About 1 hr to fix

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

                                public static func parse(_ text: String) -> Set<String> {
                                    var documentTags = Set<String>()
                            
                                    if #available(iOS 12.0, OSX 10.14, *) {
                                        let tagger = NLTagger(tagSchemes: [.nameType])
                            Severity: Minor
                            Found in ArchiveCore/Sources/ArchiveBackend/Helpers/TagParser.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) {

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language