MailController::getMailService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace AppBundle\Controller\Mail;
3
4
use AppBundle\Form\Type\SendMailFormType;
5
use AppBundle\Service\MailService;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class MailController extends Controller
12
{
13
    /**
14
     * @return MailService
15
     */
16
    private function getMailService()
17
    {
18
        return $this->get('app.mail');
19
    }
20
21
    /**
22
     * @Route("/", name="mail.index")
23
     * @Method({"GET"})
24
     */
25
    public function indexAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        $mails = $this->getMailService()->getConversationList();
28
29
        return $this->render('mail/index.html.twig', [
30
            'mails' => $mails,
31
        ]);
32
    }
33
34
    /**
35
     * @Route("/{userId}", name="mail.view", requirements={"userId": "\d+"})
36
     * @Method({"GET", "POST"})
37
     */
38
    public function viewAction(Request $request, $userId)
39
    {
40
        $mails = $this->getMailService()->getMessagesByRecipientUserId($userId);
41
42
        $form = $this->createForm(SendMailFormType::class, null, []);
43
44
        $form->handleRequest($request);
45
        if ($form->isSubmitted()) {
46
            $this->getMailService()->sendMessage($userId, $form->get('text')->getData());
47
48
            return $this->redirectToRoute('mail.view', ['userId' => $userId]);
49
        }
50
        else {
51
            $this->getMailService()->markConversationAsRead($userId);
52
        }
53
54
        return $this->render('mail/view.html.twig', [
55
            'mails' => $mails,
56
            'form' => $form->createView(),
57
        ]);
58
    }
59
}
60