PDF-Archiver/PDF-Archiver

View on GitHub

Showing 484 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

Similar blocks of code found in 2 locations. 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)

ArchiveCore/Tests/ArchiveBackendTests/PDFProcessingTests.swift on lines 104..139

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 369.

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

Further Reading

Similar blocks of code found in 2 locations. 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)

ArchiveCore/Tests/ArchiveBackendTests/PDFProcessingTests.swift on lines 67..102

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 369.

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

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

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        func testDocumentDateParsingFormat2() throws {
    
            // setup
            let path = URL(fileURLWithPath: "~/Downloads/2010_05_12 example filename.pdf")
    
    
    Severity: Major
    Found in ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift and 2 other locations - About 2 hrs to fix
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 283..298
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 317..332

    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 135.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        func testDocumentDateParsingFormat1() throws {
    
            // setup
            let path = URL(fileURLWithPath: "~/Downloads/2010-05-12 example filename.pdf")
    
    
    Severity: Major
    Found in ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift and 2 other locations - About 2 hrs to fix
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 300..315
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 317..332

    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 135.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        func testDocumentDateParsingFormat3() throws {
    
            // setup
            let path = URL(fileURLWithPath: "~/Downloads/20100512 example filename.pdf")
    
    
    Severity: Major
    Found in ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift and 2 other locations - About 2 hrs to fix
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 283..298
    ArchiveCore/Tests/ArchiveBackendTests/DocumentTests.swift on lines 300..315

    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 135.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        func criticalAndAssert(_ message: @autoclosure () -> Logger.Message,
                               metadata: @autoclosure () -> Logger.Metadata? = nil,
                               source: @autoclosure () -> String? = nil,
                               file: StaticString = #file,
                               function: StaticString = #function,
    ArchiveCore/Sources/ArchiveSharedConstants/Logging/Log.swift on lines 24..32

    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 117.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        func errorAndAssert(_ message: @autoclosure () -> Logger.Message,
                            metadata: @autoclosure () -> Logger.Metadata? = nil,
                            source: @autoclosure () -> String? = nil,
                            file: StaticString = #file,
                            function: StaticString = #function,
    ArchiveCore/Sources/ArchiveSharedConstants/Logging/Log.swift on lines 34..42

    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 117.

    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

    Further Reading

    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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              func testSearchCPUCoreCount2() {
          
                  // prepare
                  let elements = stride(from: 0, to: ProcessInfo.processInfo.activeProcessorCount - 2, by: 1)
                      .map { "2018 05 \($0) kitchen table bill ikea" }
          Severity: Major
          Found in ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift and 1 other location - About 1 hr to fix
          ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift on lines 104..116

          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 98.

          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

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              func testSearchCPUCoreCount1() {
          
                  // prepare
                  let elements = stride(from: 0, to: ProcessInfo.processInfo.activeProcessorCount + 4, by: 1)
                      .map { "2018 05 \($0) kitchen table bill ikea" }
          Severity: Major
          Found in ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift and 1 other location - About 1 hr to fix
          ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift on lines 118..130

          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 98.

          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

          Further Reading

          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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                func testFilterPerformance1() {
            
                    // create the search base
                    let elements = stride(from: 0, to: 100, by: 1)
                        .map { idx in
            Severity: Major
            Found in ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift and 1 other location - About 1 hr to fix
            ArchiveCore/Tests/ArchiveBackendTests/SearchTests.swift on lines 163..178

            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 94.

            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

            Further Reading

            Severity
            Category
            Status
            Source
            Language