I also thought it isn't beautiful, the other way is:

                if ($field->vars['group']) {
                    $group = $field->vars['group'];
                } elseif ($field->parent && $field->getParent()->vars['group']) {
                    $group = $field->getParent()->vars['group'];
                } else {
                    $group = $defaultGroup;
                }