PDF-Archiver/PDF-Archiver

View on GitHub

Showing 39 of 484 total issues

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

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) {

    Function handleAttachments has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        private func handleAttachments() {
            do {
                let url = PathConstants.extensionTempPdfURL
                let inputItems = (extensionContext?.inputItems as? [NSExtensionItem]) ?? []
                var success = false
    Severity: Minor
    Found in ShareExtension/ShareViewController.swift - About 45 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 log has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {

      Function createAndPost has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public func createAndPost(title: LocalizedStringKey, message: LocalizedStringKey, primaryButtonTitle: LocalizedStringKey, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {

        Function sort has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        public func sort<Type: CustomComparable>(_ items: [Type], by sortDescriptors: [NSSortDescriptor]) throws -> [Type] {
            return try items.sorted { (lhs, rhs) -> Bool in
                for sortDescriptor in sortDescriptors {
                    if try lhs.isBefore(rhs, sortDescriptor) { return true }
                    if try rhs.isBefore(lhs, sortDescriptor) { return false }
        Severity: Minor
        Found in ArchiveCore/Sources/ArchiveBackend/Helpers/SortDescriptors.swift - About 45 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 criticalAndAssert has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            func criticalAndAssert(_ message: @autoclosure () -> Logger.Message,
                                   metadata: @autoclosure () -> Logger.Metadata? = nil,
                                   source: @autoclosure () -> String? = nil,
                                   file: StaticString = #file,
                                   function: StaticString = #function,
        Severity: Minor
        Found in ArchiveCore/Sources/ArchiveSharedConstants/Logging/Log.swift - About 45 mins to fix

          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

          Function errorAndAssert has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              func errorAndAssert(_ message: @autoclosure () -> Logger.Message,
                                  metadata: @autoclosure () -> Logger.Metadata? = nil,
                                  source: @autoclosure () -> String? = nil,
                                  file: StaticString = #file,
                                  function: StaticString = #function,
          Severity: Minor
          Found in ArchiveCore/Sources/ArchiveSharedConstants/Logging/Log.swift - About 45 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 ArchiveCore/Sources/ArchiveBackend/PDFRendering/PDFProcessing.swift - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      guard let item = matrix[prevColumn, row - 1] else { continue }
              Severity: Major
              Found in ArchiveCore/Sources/ArchiveBackend/Search/Array+FuzzyMatch.swift - About 45 mins to fix

                Function tapped has a Cognitive Complexity of 7 (exceeds 5 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 35 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 snapshot has a Cognitive Complexity of 7 (exceeds 5 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 35 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

                Avoid too many return statements within this function.
                Open

                        return (score, matrix)
                Severity: Major
                Found in ArchiveCore/Sources/ArchiveBackend/Search/Array+FuzzyMatch.swift - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return UIImage(cgImage: cgImage).png
                  Severity: Major
                  Found in ArchiveCore/Tests/ArchiveBackendTests/helper/XCTestCase.swift - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

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

                      Function renderPdf has a Cognitive Complexity of 6 (exceeds 5 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 25 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 startWatching has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private func startWatching(contentsOf url: URL) throws {
                              let enumerator = FileManager.default.enumerator(at: url,
                                                                              includingPropertiesForKeys: [.creationDateKey, .isDirectoryKey],
                                                                              options: [.skipsHiddenFiles]) { (url, error) -> Bool in
                                  // if a folder was deleted during enumeration, there occurs a "no such file" error - we assume that there will be another change triggered

                      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 moveContents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public func moveContents(of sourceFolder: URL, to destinationFolder: URL) throws {
                              guard directoryExists(at: sourceFolder),
                                    directoryExists(at: destinationFolder) else {
                                  preconditionFailure("Source/Destionation is no folder - this should not happen.")
                              }
                      Severity: Minor
                      Found in ArchiveCore/Sources/ArchiveSharedConstants/Extensions/FileManager.swift - About 25 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

                      Severity
                      Category
                      Status
                      Source
                      Language