Very nice! But for readability i think it would be better to rewrite the conditions to sth. like:
// Check, if user is allowed to remove second factor first
if ($isAdministrator || ($isOwner && $this->secondFactorService->canOneSecondFactorBeDeletedForAccount($account))) {
// User is admin ore more than one second factor exists.
// Remove second factor and show flash message.
return;
}
// Next, check if the user is the owner of the second factor
if ($isOwner) {
// As it is the owner, the second factor to be remove must be the last one, so we can't remove it.
// Show error flash message.
return;
}
// All others (neither administrator nor owner) are redirected to index
$this->redirect('index');
Very nice! But for readability i think it would be better to rewrite the conditions to sth. like: