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
- Read upRead up
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 }
- Read upRead up
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
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 {
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 = """
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 }
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)
}
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 }
}
- Read upRead up
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
}
- Read upRead up
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
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 }
}
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
Function main
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
override public func main() {
do {
if isCancelled {
return
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)
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"))
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)
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
- Read upRead up
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) {
- Read upRead up
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) {
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)
}