SysFont - arnthor89/pygame GitHub Wiki
SysFont
Description
The function searches the system fonts with parameter name as a comma-separated list of font names and returns the first font it finds in the list. The function uses a small set of common font aliases, in the case a specific font is not available an alternative may be used.
Complexity
The reason for the high complexity of the function is that the system has to account for different system resources, create aliases and handle if a user does not have a specific font in his resources. It also handles both italic and bold style fonts for different styles.
Refactoring strategy
The simplest way to decrease the cyclomatic complexity of the function would be to split the function up into three functions, that is creat two new functions.
Create a new function with existing code from line 326-354. This function would be called get_font_name(name, bold=False, italic=False) and would return font name, bold, italic. Essentially it does the same thing as the original code but it decreases the cyclomatic complexity and makes testing the function easier.
Create a new function which would be called by the newly generated get_font_name function. It uses existing code form line 330-352. This function would be called get_styles(name, bold=False, italic=False) and would return font name, bold, italic. This would decrease the cyclomatic complexity further and would make testing easier.