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
- 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 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
- 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 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 = """
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 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 }
- 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 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 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
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.")
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 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 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 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 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])
- 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"