How to find WordPress theme’s stylesheet handle

A few moments ago, I wanted to append an inline style to the theme’s stylesheet from within a plugin. This requires knowing the current theme’s stylesheet handle, so here is a function that finds that string.

private function find_theme_stylesheet_handle() {
	global $wp_styles;

	foreach( $wp_styles->registered as $handle => $style_obj ) {
		if( $style_obj->src === get_template_directory_uri() . '/style.css' ) {
			return $handle;
		}
	}
	return null;
}