Passed
Push — master ( a137f9...d5d520 )
by Stepan
04:26
created

TrashController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A shareContactsAction() 0 18 2
1
<?php
2
3
namespace Application\Bundle\DefaultBundle\Controller;
4
5
use Application\Bundle\UserBundle\Entity\User;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
11
/**
12
 * Class DefaultController.
13
 */
14
class TrashController extends Controller
15
{
16
    /**
17
     * @Route("/share-contacts/{reply}", name="share_contacts")
18
     *
19
     * @param string $reply
20
     *
21
     * @Security("has_role('ROLE_USER')")
22
     *
23
     * @return RedirectResponse
24
     */
25
    public function shareContactsAction($reply = 'no')
26
    {
27
        /** @var User */
28
        $user = $this->getUser();
29
30
        if ('yes' === $reply) {
31
            $user->setAllowShareContacts(true);
32
        } else {
33
            $user->setAllowShareContacts(false);
34
        }
35
36
        $em = $this->getDoctrine()->getManager();
37
        $em->persist($user);
38
        $em->flush();
39
40
        $url = $this->get('request_stack')->getCurrentRequest()->headers->get('referer');
41
42
        return new RedirectResponse($url);
43
    }
44
}
45