Open kingsword opened 1 year ago
@implementation TestLizard + (UIImage *)sgb_imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock { if (!drawBlock) return nil; UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); if (!context) return nil; drawBlock(context); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end
deal with the code above, and get result:
Function name -> `sgb_imageWithSize: drawBlock: CGContextRef.image`, Cyclomatic complexity -> 1 LOC -> 2
but in fact,
function name -> `sgb_imageWithSize: drawBlock:` Cyclomatic complexity -> 3 LOC -> 10
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html
deal with the code above, and get result:
but in fact,
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html