This will fail if there is no user, you removed `if (null === $user) {` so this is not longer checked.