| Conditions | 7 |
| Paths | 4 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 7 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 10 | public function setDefault(GetResponseForControllerResultEvent $event) |
|
| 29 | { |
||
| 30 | 10 | $language = $event->getControllerResult(); |
|
| 31 | 10 | $method = $event->getRequest()->getMethod(); |
|
| 32 | |||
| 33 | 10 | if (!$language instanceof Language) { |
|
| 34 | 7 | return; |
|
| 35 | } |
||
| 36 | |||
| 37 | 3 | if ($language->isDefault()) { |
|
| 38 | 3 | if (Request::METHOD_POST === $method || Request::METHOD_PUT === $method) { |
|
| 39 | 2 | $languages = $this->em->getRepository('Webcook\Cms\I18nBundle\Entity\Language')->findBy(array( |
|
| 40 | 'default' => true |
||
| 41 | 2 | )); |
|
| 42 | |||
| 43 | 2 | foreach ($languages as $l) { |
|
| 44 | 2 | if ($l !== $language) { |
|
| 45 | 2 | $l->setDefault(false); |
|
| 46 | } |
||
| 47 | } |
||
| 48 | } else { |
||
| 49 | 1 | $language = $this->em->getRepository('Webcook\Cms\I18nBundle\Entity\Language')->findAll()[0]; |
|
| 50 | |||
| 51 | 1 | $language->setDefault(true); |
|
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | 3 | $this->em->flush(); |
|
| 56 | } |
||
| 57 | } |