SubjectAdderListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace DoS\UserBundle\Confirmation\Form\EventListener;
4
5
use DoS\UserBundle\Confirmation\ConfirmationInterface;
6
use DoS\UserBundle\Confirmation\Model\ResendInterface;
7
use DoS\UserBundle\Confirmation\Model\VerificationInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\Form\FormEvent;
10
use Symfony\Component\Form\FormEvents;
11
12
class SubjectAdderListener implements EventSubscriberInterface
13
{
14
    /**
15
     * @var ConfirmationInterface
16
     */
17
    protected $confirmation;
18
19
    public function __construct(ConfirmationInterface $confirmation)
20
    {
21
        $this->confirmation = $confirmation;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public static function getSubscribedEvents()
28
    {
29
        return array(
30
            FormEvents::SUBMIT => 'addSubject'
31
        );
32
    }
33
34
    public function addSubject(FormEvent $event)
35
    {
36
        $data = $event->getData();
37
        $subject = null;
38
39
        if ($data instanceof ResendInterface) {
40
            $subject = $this->confirmation->findSubject($data->getSubjectValue());
41
        }
42
43
        if ($data instanceof VerificationInterface) {
44
            $subject = $this->confirmation->findSubjectWithToken($data->getToken());
45
        }
46
47
        $data->setSubject($subject);
48
    }
49
}
50