From a6bac03242b8558619c5f523e1a003ce4f197e5d Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 6 Mar 2015 20:46:38 +0100 Subject: [PATCH] Refactoring : exception in _getPerson method --- Controller/AccompanyingPeriodController.php | 27 ++++++--------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Controller/AccompanyingPeriodController.php b/Controller/AccompanyingPeriodController.php index 08843c667..edc469718 100644 --- a/Controller/AccompanyingPeriodController.php +++ b/Controller/AccompanyingPeriodController.php @@ -33,10 +33,6 @@ class AccompanyingPeriodController extends Controller $person = $this->_getPerson($person_id); - if ($person === null) { - return $this->createNotFoundException('Person not found'); - } - return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(), 'person' => $person)); @@ -44,10 +40,6 @@ class AccompanyingPeriodController extends Controller public function createAction($person_id) { $person = $this->_getPerson($person_id); - - if ($person === null) { - return $this->createNotFoundException('Person not found'); - } $accompanyingPeriod = new AccompanyingPeriod(new \DateTime()); $accompanyingPeriod->setDateClosing(new \DateTime()); @@ -148,10 +140,6 @@ class AccompanyingPeriodController extends Controller public function closeAction($person_id) { $person = $this->_getPerson($person_id); - if ($person === null) { - return $this->createNotFoundException('Person not found'); - } - if ($person->isOpen() === false) { $this->get('session')->getFlashBag() ->add('danger', $this->get('translator') @@ -245,10 +233,6 @@ class AccompanyingPeriodController extends Controller public function openAction($person_id) { $person = $this->_getPerson($person_id); - if ($person === null) { - return $this->createNotFoundException('Person not found'); - } - $request = $this->getRequest(); //in case the person is already open @@ -313,8 +297,13 @@ class AccompanyingPeriodController extends Controller } private function _getPerson($id) { - return $this->getDoctrine()->getManager() - ->getRepository('ChillPersonBundle:Person') - ->find($id); + $person = $this->getDoctrine()->getManager() + ->getRepository('ChillPersonBundle:Person')->find($id); + + if ($person === null) { + throw $this->createNotFoundException('Person not found'); + } + + return $person; } }