Here you could refactor by doing everything in the private method you did like: 

```php
private function getAnnouncement($id, $em)
{
    if ($announcementId = $this->get('session')->get('announcement_id')) {
        $announcement = $em->getRepository('SensioLabsJobBoardBundle:Announcement')->findOneById($id);

        if (!$announcement) {
            throw new NotFoundHttpException(sprintf('Unable to find announcement with id %s', $id));
        }

        return $announcement;
    }

    return new Announcement();
}
```