This won't work if `$identity->getRoles()` returns (for example) an `ArrayCollection`. The identity interface should explicitly always return an array or you should use `iterator_to_array`