Refactoring : exception in _getPerson method

This commit is contained in:
Marc Ducobu 2015-03-06 20:46:38 +01:00
parent 5207a8fa12
commit a6bac03242

View File

@ -33,10 +33,6 @@ class AccompanyingPeriodController extends Controller
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(), array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
'person' => $person)); 'person' => $person));
@ -44,10 +40,6 @@ class AccompanyingPeriodController extends Controller
public function createAction($person_id) { public function createAction($person_id) {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime()); $accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$accompanyingPeriod->setDateClosing(new \DateTime()); $accompanyingPeriod->setDateClosing(new \DateTime());
@ -148,10 +140,6 @@ class AccompanyingPeriodController extends Controller
public function closeAction($person_id) { public function closeAction($person_id) {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
if ($person->isOpen() === false) { if ($person->isOpen() === false) {
$this->get('session')->getFlashBag() $this->get('session')->getFlashBag()
->add('danger', $this->get('translator') ->add('danger', $this->get('translator')
@ -245,10 +233,6 @@ class AccompanyingPeriodController extends Controller
public function openAction($person_id) { public function openAction($person_id) {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
$request = $this->getRequest(); $request = $this->getRequest();
//in case the person is already open //in case the person is already open
@ -313,8 +297,13 @@ class AccompanyingPeriodController extends Controller
} }
private function _getPerson($id) { private function _getPerson($id) {
return $this->getDoctrine()->getManager() $person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person') ->getRepository('ChillPersonBundle:Person')->find($id);
->find($id);
if ($person === null) {
throw $this->createNotFoundException('Person not found');
}
return $person;
} }
} }