Moving $entityManager outside the if clause

Otherwise $entityManager doesn't exists ligne 81.