How about:

```php
$identity = $this->authenticationService->getIdentity();

if (!$identity instanceof IdentityInterface) {
    return $this->guestRole;
}
```