Extending the NavWalker

I have a custom post_type “degree” that uses a “content-single-degree” template.

I then have a menu item that lists all the degrees, kind of like a “parent” page, which I want to have an “active” class, how can this be achieved via the SageNavWalker when viewing a single degree?

What I’m currently doing is extending the $element->is_active call by using get_post_type() and the menu_id, but I feel like there should be a better way of doing it?

if ( $element->is_active || ( get_post_type() == 'degree' && $element->ID == 214 ) ) {
  $element->classes[] = 'active';